upload.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view class="index-page">
  3. <view class="top">
  4. 微信聊天文件上传
  5. </view>
  6. <view class="min">
  7. 支持PDF文件格式,文件大小不超过20M
  8. </view>
  9. <view class="left">
  10. 将文件发送至微信(文件传输助手、自己或好友),在本页面点击上传按钮,选择刚才发送文件的聊天对象,选择文件,点击确定即可上传
  11. </view>
  12. <view class="back1 " v-if="flielist.length">
  13. <view class="u-flex u-row-between" v-for="(item,index) in flielist" :key="index">
  14. <view class="u-flex" @click="yulan">
  15. <image src="../static/images/pdf.png" style="width: 60rpx;height: 60rpx;" mode=""></image>
  16. <text>{{name}}</text>
  17. <text style="margin-left: 20rpx;">点击预览</text>
  18. </view>
  19. <u-icon @click.stop="trash(index)" name="trash" size='30'></u-icon>
  20. </view>
  21. </view>
  22. <view v-else class="back u-flex u-row-center" @click="upload1()">
  23. <u-icon name="plus" size="60"></u-icon>
  24. </view>
  25. <view class="button" @click.once="touserinfo" v-if="flielist.length">
  26. 立即上传
  27. </view>
  28. <u-popup :show="show" mode="center" round="20" customStyle="width:80vw;padding:20rpx">
  29. <view class="font">提示</view>
  30. <view class="u-flex" style="margin-top: 40rpx;">
  31. <u-icon name="error" color="#E6A23C" size="24"></u-icon>
  32. <text>删除后不可恢复,确定删除吗?</text>
  33. </view>
  34. <view class="u-flex u-row-between" style="margin-top: 60rpx;">
  35. <view class="btn1" @click="cancel">取消</view>
  36. <view class="btn2" @click="end">确定</view>
  37. </view>
  38. </u-popup>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. upload,
  44. ocr
  45. } from "@/units/inquire.js"
  46. export default {
  47. data() {
  48. return {
  49. show: false,
  50. name: "",
  51. path: "",
  52. flielist: [],
  53. index: "",
  54. fill: ""
  55. }
  56. },
  57. onLoad(options) {
  58. },
  59. methods: {
  60. touserinfo() {
  61. uni.showLoading({
  62. mask: true,
  63. title: "解析中请稍后"
  64. })
  65. ocr({
  66. path: this.flielist[0]
  67. }).then(res => {
  68. // uni.showLoading({
  69. // title: '解析中请稍后',
  70. // mask: true
  71. // })
  72. this.$u.toast(res.data.msg, "请重新上传或手动填写简历")
  73. if (res.data.msg == "解析失败") {
  74. } else {
  75. uni.setStorageSync("education_experience3", res.data.data.education_experience)
  76. uni.setStorageSync("job_experience3", res.data.data.job_experience)
  77. uni.setStorageSync("project_experience3", res.data.data.project_experience)
  78. uni.setStorageSync("from1", res.data.data.resume)
  79. setTimeout(function() {
  80. uni.navigateTo({
  81. url: "/pagesA/jianli"
  82. })
  83. }, 1000)
  84. }
  85. })
  86. },
  87. yulan() {
  88. console.log(111, this.path);
  89. uni.openDocument({
  90. filePath: this.path,
  91. showMenu: true,
  92. success: function(res) {
  93. console.log('打开文档成功');
  94. }
  95. });
  96. },
  97. upload1() {
  98. let that = this;
  99. wx.chooseMessageFile({
  100. count: 1, //限制选择的文件数量
  101. type: 'file', //非图片和视频的文件,不选默认为all
  102. extension: [".pdf", 'pdf'], //此处限制文件类型
  103. success(res) {
  104. var tempFilePaths = res.tempFiles
  105. console.log('临时路径', tempFilePaths)
  106. that.name = tempFilePaths[0].name
  107. // that.path = tempFilePaths[0].path
  108. that.upload(tempFilePaths[0].path)
  109. }
  110. })
  111. },
  112. upload(file) {
  113. uni.uploadFile({
  114. url: 'https://hire.hdlkeji.com/api/common/upload', //仅为示例,非真实的接口地址
  115. filePath: file,
  116. name: 'file',
  117. formData: {
  118. 'user': 'test'
  119. },
  120. success: (res) => {
  121. console.log('uploadImage success, res is:', res)
  122. uni.hideLoading();
  123. uni.showToast({
  124. title: '上传成功',
  125. icon: 'success',
  126. duration: 1000
  127. })
  128. var obj = JSON.parse(res.data)
  129. this.path = obj.data.fullurl
  130. this.flielist.push(obj.data.fullurl)
  131. },
  132. fail: (err) => {
  133. console.log('uploadImage fail', err);
  134. uni.hideLoading();
  135. uni.showModal({
  136. content: err.errMsg,
  137. showCancel: false
  138. });
  139. },
  140. });
  141. },
  142. // 取消
  143. cancel() {
  144. this.show = false
  145. },
  146. end() {
  147. this.flielist.splice(this.index, 1)
  148. this.show = false
  149. },
  150. trash(index) {
  151. this.show = true
  152. this.index = index
  153. }
  154. // uni.navigateTo({
  155. // url: "/pagesA/userinfo"
  156. // })
  157. },
  158. }
  159. </script>
  160. <style lang="scss" scoped>
  161. .font {
  162. font-size: 38rpx;
  163. font-family: PingFangSC-Regular, PingFang SC;
  164. font-weight: 400;
  165. }
  166. .btn1 {
  167. height: 88rpx;
  168. line-height: 88rpx;
  169. text-align: center;
  170. color: #000;
  171. width: 30vw;
  172. border-radius: 12rpx;
  173. font-size: 34rpx;
  174. font-family: PingFangSC-Regular, PingFang SC;
  175. font-weight: 400;
  176. background-color: #e4e4e4;
  177. }
  178. .btn2 {
  179. height: 88rpx;
  180. line-height: 88rpx;
  181. text-align: center;
  182. background-color: #0C66C2;
  183. color: #fff;
  184. width: 30vw;
  185. border-radius: 12rpx;
  186. font-size: 34rpx;
  187. font-family: PingFangSC-Regular, PingFang SC;
  188. font-weight: 400;
  189. }
  190. .back1 {
  191. padding: 10rpx 20rpx;
  192. border: 2rpx dashed #555555;
  193. margin-top: 28rpx;
  194. }
  195. .index-page {
  196. overflow: hidden;
  197. padding: 32rpx;
  198. }
  199. .back {
  200. background-color: rgba(85, 85, 85, 0.5);
  201. width: 100%;
  202. height: 628rpx;
  203. margin-top: 28rpx;
  204. }
  205. .left {
  206. font-size: 28rpx;
  207. font-family: PingFangSC-Regular, PingFang SC;
  208. font-weight: 400;
  209. color: #555555;
  210. margin-top: 60rpx;
  211. }
  212. .min {
  213. font-size: 24rpx;
  214. font-family: PingFangSC-Regular, PingFang SC;
  215. font-weight: 400;
  216. color: #777777;
  217. margin-top: 20rpx;
  218. }
  219. .top {
  220. font-size: 48rpx;
  221. font-family: PingFangSC-Medium, PingFang SC;
  222. font-weight: 500;
  223. color: #222222;
  224. margin-top: 58rpx;
  225. }
  226. .button {
  227. height: 88rpx;
  228. background: #0C66C2;
  229. border-radius: 12rpx;
  230. font-size: 34rpx;
  231. font-family: PingFangSC-Regular, PingFang SC;
  232. font-weight: 400;
  233. color: #FFFFFF;
  234. line-height: 88rpx;
  235. text-align: center;
  236. margin-top: 36rpx;
  237. }
  238. </style>