uploadVNormalTaskPhoto.vue 19 KB

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