uploadImgVStore.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <div>
  3. <div class="cameraDiv1">
  4. <div class="imgPre" v-if="imgArr && imgArr.length">
  5. <van-icon
  6. class="photobrowsing"
  7. name="expand-o"
  8. size="22px"
  9. color="#1989fa"
  10. @click="deleteImgs" />
  11. <img :src="imgUrlArr[0]" alt="" />
  12. </div>
  13. <p class="coverImg" @click="uploadImg">
  14. <van-icon class="photo ico" name="photograph" size="16px" color="#969696">{{
  15. imgText
  16. }}</van-icon>
  17. </p>
  18. </div>
  19. <p style="text-align: center">{{ imgText }}</p>
  20. <div class="mask" v-if="progressFlag">
  21. <el-progress
  22. type="circle"
  23. :percentage="percentage"
  24. :show-text="true"
  25. :format="format"></el-progress>
  26. <div class="progressClose" @click="progressClose">取消</div>
  27. </div>
  28. <imageAIVerifyErr
  29. v-if="true"
  30. :imageAIVerifyFlag="true"
  31. :imageAIVerifyData="imageAIVerifyData"
  32. @confirmUpload="confirmUpload"
  33. @uploadImgFun="uploadImg"
  34. :source="'newCreated'"
  35. @normalFlow="normalFlow"
  36. @close="close"></imageAIVerifyErr>
  37. </div>
  38. </template>
  39. <script>
  40. import { ImagePreview } from 'vant';
  41. import axios from 'axios';
  42. import { uploadImagev } from '@/api/index';
  43. import imageAIVerifyErr from './imageAIVerifyErr';
  44. export default {
  45. name: 'uploadImg',
  46. components: { imageAIVerifyErr },
  47. props: {
  48. uploadid: {
  49. type: String,
  50. default: '',
  51. },
  52. imgText: {
  53. type: String,
  54. default: '',
  55. },
  56. visitsId: {
  57. type: String,
  58. default: '',
  59. },
  60. taskId: {
  61. type: String,
  62. default: '',
  63. },
  64. collectionId: {
  65. type: String,
  66. default: '',
  67. },
  68. type: {
  69. type: Number,
  70. default: 1,
  71. },
  72. imgArr: {
  73. type: [String, Array],
  74. default: '',
  75. },
  76. count: {
  77. type: Number,
  78. default: 1,
  79. },
  80. photoIdentifyType: {
  81. // 图匠识别目的(1:店招内容识别,2:门店代码识别,3:调色机识别,4:更换店招)
  82. type: String,
  83. default: '',
  84. },
  85. disabled: {
  86. // 是否可以添加或修改 true:不可以
  87. type: Boolean,
  88. default: false,
  89. },
  90. },
  91. data() {
  92. return {
  93. shows: false,
  94. url: '',
  95. localIds: [],
  96. num: 0,
  97. serverIdArr: [],
  98. imgUrlArr: [],
  99. progressFlag: false,
  100. percentage: 0,
  101. timeFlag: null,
  102. imageAIVerifyFlag: false,
  103. imageAIVerifyData: [
  104. {
  105. npkpiData: {
  106. storeCode: null,
  107. recognizeType: 1,
  108. imageUrl:
  109. 'http://imagedt-nipponpaint.oss-cn-shenzhen.aliyuncs.com/77/772550faf0627de382d2336fb6c6ccfd.jpg',
  110. shopSignInfo: {
  111. name: null,
  112. npStoreCode: null,
  113. phone: '',
  114. address: null,
  115. contact: '',
  116. businessScope: null,
  117. mainBrand: null,
  118. },
  119. shopSignChange: 0,
  120. checkInfo: {
  121. cheatState: 0,
  122. cheatType: null,
  123. qualifiedState: 0,
  124. unqualifiedReason: '纯色、非店招',
  125. },
  126. shopSignMatchList: [],
  127. },
  128. size: '82',
  129. businessId: '8959656c-bd29-467a-b72a-6dc32a7e95f7',
  130. url: 'https://cdn-svs-test.nipponpaint.com.cn/17401005962152025-02-21%E8%B0%88.jpg?Expires=2055633396&OSSAccessKeyId=LTAI5tG1DTJFA16BHkzHVxjz&Signature=8hlflptRBXlOfGIayDRZHRniKto%3D',
  131. },
  132. ], //图匠校验返回的数据
  133. controller: null, //取消请求状态
  134. };
  135. },
  136. watch: {
  137. imgArr: {
  138. handler(val) {
  139. if (val) this.imgUrlArr = val.split(',');
  140. },
  141. immediate: true,
  142. },
  143. },
  144. methods: {
  145. deleteImgs() {
  146. ImagePreview(this.imgUrlArr);
  147. },
  148. uploadImg() {
  149. if (this.disabled) return;
  150. if (localStorage.getItem('chainName') == null) {
  151. this.$toast('请输入名称!');
  152. return;
  153. }
  154. this.wx.ready(() => {
  155. this.wx.chooseImage({
  156. count: this.count,
  157. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  158. sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
  159. defaultCameraMode: 'normal', //表示进入拍照界面的默认模式,目前有normal与batch两种选择,normal表示普通单拍模式,batch表示连拍模式,不传该参数则为normal模式。从3.0.26版本开始支持front和batch_front两种值,其中front表示默认为前置摄像头单拍模式,batch_front表示默认为前置摄像头连拍模式。(注:用户进入拍照界面仍然可自由切换两种模式)
  160. isSaveToAlbum: 0,
  161. success: (chooseRes) => {
  162. this.localIds = chooseRes.localIds;
  163. console.log('count=' + this.count);
  164. console.log('chooseRes=' + chooseRes);
  165. console.log('localIds=' + this.localIds);
  166. // if (chooseRes.localIds != undefined) {
  167. // localIds = chooseRes.localIds[0];
  168. // } else {
  169. // localIds = chooseRes.localId;
  170. // }
  171. this.num = 0;
  172. this.serverIdArr = [];
  173. this.forUploadImage();
  174. },
  175. });
  176. });
  177. },
  178. forUploadImage() {
  179. this.wx.uploadImage({
  180. localId: this.localIds[this.num],
  181. isShowProgressTips: 1,
  182. success: (uploadRes) => {
  183. this.serverIdArr.push(uploadRes.serverId);
  184. console.log('serverId=' + uploadRes.serverId);
  185. this.num++;
  186. if (this.num == this.localIds.length) {
  187. this.uploadImagev(this.serverIdArr.join(','));
  188. } else {
  189. this.forUploadImage();
  190. }
  191. },
  192. });
  193. },
  194. uploadImagev(meidaId) {
  195. // 初始化重置 图匠校验
  196. this.resetProgress();
  197. this.close();
  198. var that = this;
  199. var form = {
  200. mediaId: meidaId,
  201. storeName: localStorage.getItem('chainName'),
  202. locationRemark: localStorage.getItem('locationRemark'),
  203. deptName: localStorage.getItem('deptName'),
  204. };
  205. this.controller = null;
  206. // 需要图匠校验的添加参数和loading
  207. if (this.photoIdentifyType) {
  208. form.photoIdentifyType = this.photoIdentifyType;
  209. this.progress();
  210. this.controller = new AbortController(); //取消请求
  211. } else {
  212. this.toastLoading(0, '上传中...', true);
  213. }
  214. uploadImagev(form, this.controller ? this.controller.signal : null)
  215. .then((res) => {
  216. this.toastLoading().clear();
  217. if (res.code == -1) {
  218. // 图匠图片校验接口超时
  219. this.requestTimeOut(res);
  220. } else if (res.code == 200) {
  221. // 图匠校验结果返回
  222. if (this.photoIdentifyType) {
  223. // 重置loaidng状态
  224. this.resetProgress();
  225. this.imageAIVerifyFlag = true;
  226. console.log('res.data=' + JSON.stringify(res.data));
  227. this.imageAIVerifyData = res.data;
  228. } else {
  229. // 正常流程
  230. this.normalFlow(res);
  231. }
  232. } else {
  233. this.resetProgress();
  234. that.$toast('上传失败!');
  235. }
  236. })
  237. .catch((error) => {
  238. if (error.message === 'canceled') {
  239. this.$toast('取消上传');
  240. console.log('请求被取消:', error.message);
  241. }
  242. this.resetProgress();
  243. });
  244. },
  245. progress() {
  246. // 后端接口20000ms后失效,每1000m progress加10,到90停止;
  247. this.progressFlag = true;
  248. this.percentage = 10;
  249. this.timeFlag = setInterval(() => {
  250. this.percentage = this.percentage + 10;
  251. if (this.percentage == 90) clearInterval(this.timeFlag);
  252. }, 1000);
  253. },
  254. format(percentage) {
  255. return `${percentage} %\n图像识别中`;
  256. },
  257. requestTimeOut(res) {
  258. this.resetProgress();
  259. this.close();
  260. this.$dialog
  261. .confirm({
  262. title: '系统提示',
  263. message: res.msg,
  264. showCancelButton: false,
  265. })
  266. .then(() => {
  267. this.normalFlow(res);
  268. });
  269. },
  270. // 正常流程
  271. normalFlow(res) {
  272. let imgArr = [];
  273. let businessId = [];
  274. res.data.forEach((item) => {
  275. imgArr.push(item.url);
  276. if (item.businessId) businessId.push(item.businessId);
  277. });
  278. this.$toast('上传成功!');
  279. this.$emit('newimgarr', {
  280. fileUrl: imgArr.join(','),
  281. type: this.type,
  282. businessId: businessId.join(','),
  283. });
  284. },
  285. // 重置loaidng状态
  286. resetProgress() {
  287. this.percentage = 100;
  288. clearInterval(this.timeFlag);
  289. this.progressFlag = false;
  290. this.percentage = 0;
  291. },
  292. // 取消图片上传
  293. progressClose() {
  294. this.controller.abort();
  295. },
  296. confirmUpload(res) {
  297. this.normalFlow(res);
  298. },
  299. close() {
  300. this.imageAIVerifyFlag = false;
  301. },
  302. },
  303. };
  304. </script>
  305. <style scoped>
  306. .cameraDiv1 {
  307. position: relative;
  308. height: 164px;
  309. width: 100%;
  310. background-color: white;
  311. }
  312. .cameraDiv1 img {
  313. position: absolute;
  314. width: 100%;
  315. display: block;
  316. height: 164px;
  317. top: 0;
  318. }
  319. .imgPre {
  320. height: 164px;
  321. width: 100%;
  322. background-color: white;
  323. border-radius: 6px;
  324. overflow: hidden;
  325. }
  326. .photos1 {
  327. margin: 70px auto;
  328. left: 50%;
  329. margin-left: -14px;
  330. }
  331. .photobrowsing {
  332. position: absolute;
  333. padding: 4px;
  334. right: 0;
  335. top: 0;
  336. z-index: 99;
  337. background-color: rgba(255, 255, 255, 0.8);
  338. border-bottom-left-radius: 3px;
  339. border-top-left-radius: 3px;
  340. }
  341. .coverImg {
  342. text-align: center;
  343. position: absolute;
  344. top: 0;
  345. left: 0;
  346. height: 164px;
  347. width: 100%;
  348. }
  349. .coverImg .ico {
  350. top: 42%;
  351. }
  352. .mask {
  353. position: fixed;
  354. top: 0;
  355. left: 0;
  356. right: 0;
  357. bottom: 0;
  358. width: 100%;
  359. height: 100%;
  360. background: rgba(255, 255, 255, 0.8);
  361. display: flex;
  362. justify-content: center;
  363. align-items: center;
  364. z-index: 99999999;
  365. display: flex;
  366. flex-direction: column;
  367. .progressClose {
  368. width: 70px;
  369. text-align: center;
  370. background: #67c23a;
  371. color: #fff;
  372. height: 30px;
  373. line-height: 30px;
  374. border-radius: 5px;
  375. margin-top: 5px;
  376. font-size: 12px;
  377. }
  378. }
  379. </style>
  380. <style lang="scss">
  381. .mask {
  382. .el-progress__text {
  383. white-space: pre-wrap;
  384. }
  385. }
  386. </style>