uploadVNormal.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <template>
  2. <div class="questionNamep">
  3. <div class="cameraDiv" @click="uploadImg">
  4. <van-icon class="photo photos" name="photograph" size="22px" color="#969696" />
  5. </div>
  6. <div id="allmap"></div>
  7. <div class="mask" v-if="progressFlag">
  8. <el-progress
  9. type="circle"
  10. :percentage="percentage"
  11. :show-text="true"
  12. :width="110"
  13. :format="format"></el-progress>
  14. <div class="progressClose" @click="progressClose">取消</div>
  15. </div>
  16. <imageAIVerifyErr
  17. v-if="imageAIVerifyFlag"
  18. :imageAIVerifyFlag="imageAIVerifyFlag"
  19. :imageAIVerifyData="imageAIVerifyData"
  20. @confirmUpload="confirmUpload"
  21. @uploadImgFun="uploadImg"
  22. :source="'visit'"
  23. @normalFlow="normalFlow"
  24. @close="close"></imageAIVerifyErr>
  25. </div>
  26. </template>
  27. <script>
  28. import { addstorePhoto, addVisitsPosition, addPhotoToDB } from '@/api/index';
  29. import imageAIVerifyErr from './imageAIVerifyErr';
  30. import axios from 'axios';
  31. export default {
  32. name: 'uploadImg',
  33. components: { imageAIVerifyErr },
  34. props: {
  35. uploadid: {
  36. type: String,
  37. default: '',
  38. },
  39. storeGroupId: {
  40. type: String,
  41. default: '',
  42. },
  43. parentCollectionId: {
  44. type: String,
  45. default: '',
  46. },
  47. secondCollectionId: {
  48. type: String,
  49. default: '',
  50. },
  51. firstCollectionId: {
  52. type: String,
  53. default: '',
  54. },
  55. fourthCollectionId: {
  56. type: String,
  57. default: '',
  58. },
  59. thirdCollectionId: {
  60. type: String,
  61. default: '',
  62. },
  63. visitsId: {
  64. type: String,
  65. default: '',
  66. },
  67. taskId: {
  68. type: String,
  69. default: '',
  70. },
  71. collectionId: {
  72. type: String,
  73. default: '',
  74. },
  75. objectType: {
  76. type: String,
  77. default: '',
  78. },
  79. type: {
  80. type: Number,
  81. default: 1,
  82. },
  83. imgArr: {
  84. type: Array,
  85. default() {
  86. return [];
  87. },
  88. },
  89. visitModel: {
  90. type: String,
  91. default: '1',
  92. },
  93. deviceCode: {
  94. type: String,
  95. default: '',
  96. },
  97. putInCode: {
  98. type: String,
  99. default: '',
  100. },
  101. photoIdentifyType: {
  102. // 图匠识别目的(1:店招内容识别,2:门店代码识别,3:调色机识别,4:更换店招)
  103. type: String,
  104. default: '',
  105. },
  106. },
  107. data() {
  108. return {
  109. shows: false,
  110. url: '',
  111. progressFlag: false,
  112. percentage: 0,
  113. timeFlag: null,
  114. imageAIVerifyFlag: false,
  115. imageAIVerifyData: null, //图匠校验返回的数据
  116. meidaId: '', //当前上传图片id
  117. addressesRemark: '', //当前位置信息
  118. controller: null, //取消请求状态
  119. };
  120. },
  121. methods: {
  122. uploadImg() {
  123. var map = new TMap.Map('allmap', {
  124. zoom: 14,
  125. center: new TMap.LatLng(39.986785, 116.301012),
  126. });
  127. var geocoder = new TMap.service.Geocoder(); // 新建一个正逆地址解析类
  128. var markers = new TMap.MultiMarker({
  129. map: map,
  130. geometries: [],
  131. });
  132. markers.setGeometries([]);
  133. if (this.objectType == '' || this.objectType == null) {
  134. this.$toast('请选择类型!');
  135. return;
  136. }
  137. let url = window.location.href;
  138. let that = this;
  139. let wx = this.wx;
  140. let qiyeData;
  141. let addressesRemark = '';
  142. const instance = axios.create();
  143. instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
  144. instance
  145. .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
  146. params: {
  147. url: url,
  148. },
  149. })
  150. .then((response) => {
  151. if (response.status == 200) {
  152. qiyeData = response.data.data;
  153. wx.config({
  154. beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
  155. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  156. appId: qiyeData.appId, // 必填,企业微信的corpID
  157. timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
  158. nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
  159. signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
  160. jsApiList: ['ready', 'chooseImage', 'uploadImage', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
  161. });
  162. wx.ready(function () {
  163. wx.getLocation({
  164. type: 'gcj02',
  165. success: function (res) {
  166. var location = new TMap.LatLng(res.latitude, res.longitude);
  167. map.setCenter(location);
  168. markers.updateGeometries([
  169. {
  170. id: 'main', // 点标注数据数组
  171. position: location,
  172. },
  173. ]);
  174. geocoder.getAddress({ location: location }).then(
  175. function (result) {
  176. var addresses = result.result.formatted_addresses;
  177. addressesRemark = addresses.recommend;
  178. },
  179. function (err) {
  180. addressesRemark = '';
  181. }
  182. );
  183. },
  184. fail: function () {
  185. that.$dialog.alert({
  186. message: 'GPS未开启',
  187. });
  188. },
  189. });
  190. wx.chooseImage({
  191. count: 1,
  192. sizeType: ['original'], // 可以指定是原图还是压缩图,默认二者都有
  193. sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
  194. defaultCameraMode: 'normal', //表示进入拍照界面的默认模式,目前有normal与batch两种选择,normal表示普通单拍模式,batch表示连拍模式,不传该参数则为normal模式。从3.0.26版本开始支持front和batch_front两种值,其中front表示默认为前置摄像头单拍模式,batch_front表示默认为前置摄像头连拍模式。(注:用户进入拍照界面仍然可自由切换两种模式)
  195. isSaveToAlbum: 0, //整型值,0表示拍照时不保存到系统相册,1表示自动保存,默认值是1
  196. success: function (res) {
  197. var localIds = '';
  198. if (res.localIds != undefined) {
  199. localIds = res.localIds[0];
  200. } else {
  201. localIds = res.localId;
  202. }
  203. wx.uploadImage({
  204. localId: localIds, // 需要上传的图片的本地ID,由chooseImage接口获得
  205. isShowProgressTips: 1, // 默认为1,显示进度提示
  206. success: function (res) {
  207. that.uploadImagev(res.serverId, addressesRemark);
  208. },
  209. });
  210. },
  211. });
  212. });
  213. }
  214. });
  215. },
  216. uploadImagev(meidaId, addressesRemark) {
  217. // 初始化重置 图匠校验
  218. this.resetProgress();
  219. this.close();
  220. var that = this;
  221. var parentCollectionId = null;
  222. if (that.parentCollectionId != null && that.parentCollectionId != 'null') {
  223. parentCollectionId = that.parentCollectionId;
  224. }
  225. var secondCollectionId = null;
  226. if (that.secondCollectionId != null && that.secondCollectionId != 'null') {
  227. secondCollectionId = that.secondCollectionId;
  228. }
  229. var firstCollectionId = null;
  230. if (that.firstCollectionId != null && that.firstCollectionId != 'null') {
  231. firstCollectionId = that.firstCollectionId;
  232. }
  233. var fourthCollectionId = null;
  234. if (that.fourthCollectionId != null && that.fourthCollectionId != 'null') {
  235. fourthCollectionId = that.fourthCollectionId;
  236. }
  237. var thirdCollectionId = null;
  238. if (that.thirdCollectionId != null && that.thirdCollectionId != 'null') {
  239. thirdCollectionId = that.thirdCollectionId;
  240. }
  241. this.meidaId = meidaId;
  242. this.addressesRemark = addressesRemark;
  243. var form = {
  244. mediaId: meidaId,
  245. collectionItemId: that.collectionId,
  246. objectType: that.objectType,
  247. storeGroupId: that.storeGroupId,
  248. taskId: that.taskId,
  249. visitsId: localStorage.getItem('visitId'),
  250. visitModel: that.visitModel,
  251. visitSource: '1',
  252. locationRemark: addressesRemark,
  253. parentCollectionId: parentCollectionId,
  254. secondCollectionId: secondCollectionId,
  255. firstCollectionId: firstCollectionId,
  256. fourthCollectionId: fourthCollectionId,
  257. thirdCollectionId: thirdCollectionId,
  258. deviceCode: that.deviceCode, //设备编号
  259. putInCode: that.putInCode, //投放编号
  260. };
  261. this.controller = null;
  262. // 需要图匠校验的添加参数和loading
  263. if (this.photoIdentifyType) {
  264. form.photoIdentifyType = this.photoIdentifyType;
  265. this.progress();
  266. this.controller = new AbortController(); //取消请求
  267. } else {
  268. this.toastLoading(0, '上传中...', true);
  269. }
  270. addstorePhoto(form, this.controller ? this.controller.signal : null)
  271. .then((res) => {
  272. this.toastLoading().clear();
  273. if (res.code == -1) {
  274. // 图匠图片校验接口超时
  275. this.requestTimeOut(res);
  276. } else if (res.code == 200) {
  277. // 图匠校验结果返回
  278. if (this.photoIdentifyType) {
  279. // 重置loaidng状态
  280. this.resetProgress();
  281. this.imageAIVerifyFlag = true;
  282. this.imageAIVerifyData = res.data;
  283. } else {
  284. // 正常流程
  285. this.normalFlow(res);
  286. }
  287. } else {
  288. this.resetProgress();
  289. that.$toast('上传失败!');
  290. }
  291. })
  292. .catch((error) => {
  293. if (error.message === 'canceled') {
  294. this.$toast('取消上传');
  295. console.log('请求被取消:', error.message);
  296. }
  297. this.resetProgress();
  298. });
  299. },
  300. // 正常流程
  301. normalFlow(res) {
  302. this.$toast('上传成功!');
  303. this.$emit('newimgarr', {
  304. fileUrl: res.data.url,
  305. id: res.data.fileId,
  306. type: 2,
  307. photoIdentifyType: this.photoIdentifyType,
  308. });
  309. },
  310. progress() {
  311. // 后端接口20000ms后失效,每1000m progress加10,到90停止;
  312. this.progressFlag = true;
  313. this.percentage = 10;
  314. this.timeFlag = setInterval(() => {
  315. this.percentage = this.percentage + 10;
  316. if (this.percentage == 90) clearInterval(this.timeFlag);
  317. }, 1000);
  318. },
  319. format(percentage) {
  320. return `${percentage} %\n图像识别中`;
  321. },
  322. // 重置loaidng状态
  323. resetProgress() {
  324. this.percentage = 100;
  325. clearInterval(this.timeFlag);
  326. this.progressFlag = false;
  327. this.percentage = 0;
  328. },
  329. // 照片是否入库,1.照片识别三次不通过仍要上传,2.照片识别通过
  330. // isUpdate:是否更新店招照片,只有门店店招需要更新
  331. confirmUpload(res) {
  332. if (this.photoIdentifyType) {
  333. var form = {
  334. mediaId: this.meidaId, // string 图片素材id
  335. visitSource: '1', // Long 拜访模式
  336. storeGroupId: this.storeGroupId, // string 门店任务组,多个用逗号隔开
  337. visitsId: localStorage.getItem('visitId'), // string 拜访id
  338. taskId: this.taskId, // string 任务id
  339. objectType: this.objectType, // string 照片类型,取任务上的照片类型,如果没有则取手动选择的照片类型
  340. locationRemark: this.addressesRemark, // String 当前地址信息
  341. firstCollectionId: this.firstCollectionId, // Long 第一级采集项id,取当前采集项的字段就行
  342. secondCollectionId: this.secondCollectionId, // Long 第二级采集项id,取当前采集项的字段就行
  343. putInCode: this.putInCode, // String 当前任务对应的投放编号
  344. deviceCode: this.deviceCode, // String 当前任务对应的设备编号
  345. collectionItemId: this.collectionId,
  346. url: res.data.url, // String 当前拍摄图片的url
  347. businessId: res.data.businessId, // 当前拍摄图片id
  348. };
  349. if (res.isUpdate) form.isUpdate = 'true';
  350. addPhotoToDB(form).then((resData) => {
  351. if (resData.code == 200) {
  352. console.log(resData);
  353. res.data.fileId = resData.data.fileId;
  354. this.normalFlow(res);
  355. }
  356. });
  357. }
  358. },
  359. close() {
  360. this.imageAIVerifyFlag = false;
  361. },
  362. requestTimeOut(res) {
  363. this.resetProgress();
  364. this.close();
  365. this.$dialog
  366. .confirm({
  367. title: '系统提示',
  368. message: res.msg,
  369. showCancelButton: false,
  370. })
  371. .then(() => {
  372. this.confirmUpload(res);
  373. });
  374. },
  375. // 取消图片上传
  376. progressClose() {
  377. this.controller.abort();
  378. },
  379. },
  380. };
  381. </script>
  382. <style lang="scss" scoped>
  383. .questionNamep {
  384. font-size: 16px;
  385. color: #484848;
  386. line-height: 40px;
  387. padding: 0 15px;
  388. box-sizing: border-box;
  389. position: relative;
  390. .cameraDivp {
  391. flex: 1;
  392. display: flex;
  393. align-items: center;
  394. justify-content: center;
  395. .photo {
  396. /*margin-top: 9px;*/
  397. float: right;
  398. }
  399. .camera {
  400. width: 60px;
  401. height: 100%;
  402. position: absolute;
  403. right: 0;
  404. top: 0;
  405. opacity: 0;
  406. z-index: 89;
  407. }
  408. }
  409. .mask {
  410. position: fixed;
  411. top: 0;
  412. left: 0;
  413. right: 0;
  414. bottom: 0;
  415. width: 100%;
  416. height: 100%;
  417. background: rgba(255, 255, 255, 1);
  418. display: flex;
  419. justify-content: center;
  420. align-items: center;
  421. z-index: 99999999;
  422. display: flex;
  423. flex-direction: column;
  424. .progressClose {
  425. width: 70px;
  426. text-align: center;
  427. background: #67c23a;
  428. color: #fff;
  429. height: 30px;
  430. line-height: 30px;
  431. border-radius: 5px;
  432. margin-top: 5px;
  433. font-size: 12px;
  434. }
  435. }
  436. }
  437. #allmap {
  438. width: 10px;
  439. height: 10px;
  440. left: -1000px;
  441. position: relative;
  442. }
  443. </style>
  444. <style lang="scss">
  445. .mask {
  446. .el-progress__text {
  447. white-space: pre-wrap;
  448. }
  449. }
  450. </style>