uploadVTask.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <van-col span="6">
  3. <!-- <van-uploader :after-read="afterRead" upload-text="照片上传"/>-->
  4. <div class="uploaderImage">
  5. <p class="coverImg" @click="uploadImg">
  6. <van-icon class="photo ico" name="photograph" size="16px" color="#969696"> </van-icon>
  7. <span>{{ imgText }}</span>
  8. </p>
  9. </div>
  10. <div id="allmap"></div>
  11. </van-col>
  12. </template>
  13. <script>
  14. import { ImagePreview } from 'vant';
  15. import { addPhotov } from '@/api/index';
  16. import axios from 'axios';
  17. export default {
  18. name: 'uploadImg',
  19. props: {
  20. uploadid: {
  21. type: String,
  22. default: '',
  23. },
  24. imgText: {
  25. type: String,
  26. default: '',
  27. },
  28. indexImg: {
  29. type: Number,
  30. default: 0,
  31. },
  32. visitsId: {
  33. type: String,
  34. default: '',
  35. },
  36. customId: {
  37. type: String | Number,
  38. default: '',
  39. },
  40. summaryId: {
  41. type: String | Number,
  42. default: '',
  43. },
  44. type: {
  45. type: Number,
  46. default: 1,
  47. },
  48. imgArr: {
  49. type: String,
  50. default: '',
  51. },
  52. // 是否补填
  53. allowWriteAgain: {
  54. type: Boolean,
  55. default: false,
  56. },
  57. item: {
  58. type: Object,
  59. default: {},
  60. },
  61. },
  62. data() {
  63. return {
  64. shows: false,
  65. url: '',
  66. addressesRemark: '',
  67. localIdsArr: [],
  68. };
  69. },
  70. methods: {
  71. deleteImgs(val) {
  72. ImagePreview([val]);
  73. },
  74. uploadImg() {
  75. let url = window.location.href;
  76. let that = this;
  77. let wx = this.wx;
  78. let qiyeData;
  79. this.addressesRemark = '';
  80. var map = new TMap.Map('allmap', {
  81. zoom: 14,
  82. center: new TMap.LatLng(39.986785, 116.301012),
  83. });
  84. var geocoder = new TMap.service.Geocoder(); // 新建一个正逆地址解析类
  85. var markers = new TMap.MultiMarker({
  86. map: map,
  87. geometries: [],
  88. });
  89. markers.setGeometries([]);
  90. const instance = axios.create();
  91. instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
  92. instance
  93. .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
  94. params: {
  95. url: url,
  96. },
  97. })
  98. .then((response) => {
  99. if (response.status == 200) {
  100. qiyeData = response.data.data;
  101. wx.config({
  102. beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
  103. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  104. appId: qiyeData.appId, // 必填,企业微信的corpID
  105. timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
  106. nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
  107. signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
  108. jsApiList: ['ready', 'chooseImage', 'uploadImage', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
  109. });
  110. wx.ready(function () {
  111. wx.getLocation({
  112. type: 'gcj02',
  113. success: function (res) {
  114. var location = new TMap.LatLng(res.latitude, res.longitude);
  115. map.setCenter(location);
  116. markers.updateGeometries([
  117. {
  118. id: 'main', // 点标注数据数组
  119. position: location,
  120. },
  121. ]);
  122. geocoder.getAddress({ location: location }).then(
  123. function (result) {
  124. var addresses = result.result.formatted_addresses;
  125. that.addressesRemark = addresses.recommend;
  126. },
  127. function (err) {
  128. that.addressesRemark = '';
  129. }
  130. );
  131. },
  132. fail: function () {
  133. that.$dialog.alert({
  134. message: 'GPS未开启',
  135. });
  136. },
  137. });
  138. wx.chooseImage({
  139. count: 5,
  140. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  141. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  142. defaultCameraMode: 'normal', //表示进入拍照界面的默认模式,目前有normal与batch两种选择,normal表示普通单拍模式,batch表示连拍模式,不传该参数则为normal模式。从3.0.26版本开始支持front和batch_front两种值,其中front表示默认为前置摄像头单拍模式,batch_front表示默认为前置摄像头连拍模式。(注:用户进入拍照界面仍然可自由切换两种模式)
  143. isSaveToAlbum: 0,
  144. success: function (res) {
  145. let localIds = res.localIds;
  146. // andriod中localId可以作为img标签的src属性显示图片;
  147. // iOS应当使用 getLocalImgData 获取图片base64数据,从而用于img标签的显示(在img标签内使用 wx.chooseImage 的 localid 显示可能会不成功)
  148. that.localIdsArr = [];
  149. that.syncUpload(localIds);
  150. // wx.uploadImage({
  151. // localId: localIds, // 需要上传的图片的本地ID,由chooseImage接口获得
  152. // isShowProgressTips: 1, // 默认为1,显示进度提示
  153. // success: function (res) {
  154. // that.uploadImagev(res.serverId, addressesRemark);
  155. // },
  156. // });
  157. },
  158. });
  159. });
  160. }
  161. });
  162. },
  163. syncUpload(localIds) {
  164. if (!localIds.length) {
  165. this.uploadImagev(this.localIdsArr);
  166. } else {
  167. var localId = localIds.pop();
  168. wx.uploadImage({
  169. localId: localId,
  170. isShowProgressTips: 1, // 默认为1,显示进度提示
  171. success: (res) => {
  172. this.localIdsArr.push(res.serverId);
  173. this.syncUpload(localIds);
  174. },
  175. });
  176. }
  177. },
  178. uploadImagev(meidaIds) {
  179. var that = this;
  180. var form = {
  181. mediaIds: meidaIds,
  182. customId: that.customId,
  183. summaryId: that.summaryId,
  184. locationRemark: that.addressesRemark,
  185. };
  186. var loind1 = that.$toast.loading({
  187. duration: 0,
  188. message: '上传中...',
  189. forbidClick: true,
  190. });
  191. // 允许补填 添加上补填标识
  192. if (this.allowWriteAgain) {
  193. form.writeAgain = '1';
  194. }
  195. addPhotov(form).then((res) => {
  196. if (res.code == 200) {
  197. // that.imgArr = res.data.url;
  198. loind1.clear();
  199. that.$toast('上传成功!');
  200. let urlArr = [];
  201. let idArr = [];
  202. res.data.forEach((val) => {
  203. urlArr.push({
  204. fileUrl: val.url,
  205. id: val.fileId,
  206. fileType: val.fileType,
  207. fileName: val.fileName,
  208. type: that.type,
  209. index: that.indexImg,
  210. });
  211. idArr.push(val.id);
  212. });
  213. if (this.item.fileInfoList == null || this.item.fileInfoList == undefined) {
  214. this.item.fileInfoList = [];
  215. this.item.fileIdList = [];
  216. }
  217. this.item.fileInfoList.concat(urlArr);
  218. this.item.fileIdList.concat(idArr);
  219. // that.$emit('newimgarr', {
  220. // fileUrl: res.data.url,
  221. // id: res.data.fileId,
  222. // fileType: res.fileType,
  223. // fileName: res.fileName,
  224. // type: that.type,
  225. // index: that.indexImg,
  226. // });
  227. } else {
  228. that.$toast('上传失败!');
  229. }
  230. });
  231. },
  232. },
  233. };
  234. </script>
  235. <style scoped>
  236. .uploaderImage {
  237. position: relative;
  238. height: 80px;
  239. width: 80px;
  240. border: 1px solid #ccc;
  241. border-radius: 5px;
  242. }
  243. .uploaderImage img {
  244. position: absolute;
  245. width: 100%;
  246. display: block;
  247. height: 40px;
  248. top: 0;
  249. }
  250. .imgPre {
  251. height: 164px;
  252. width: 100%;
  253. background-color: white;
  254. border-radius: 6px;
  255. overflow: hidden;
  256. }
  257. .photos1 {
  258. margin: 70px auto;
  259. left: 50%;
  260. margin-left: -14px;
  261. }
  262. .photobrowsing {
  263. position: absolute;
  264. padding: 4px;
  265. right: 0;
  266. top: 0;
  267. z-index: 99;
  268. background-color: rgba(255, 255, 255, 0.8);
  269. border-bottom-left-radius: 3px;
  270. border-top-left-radius: 3px;
  271. }
  272. .uploaderImage .coverImg {
  273. text-align: center;
  274. position: absolute;
  275. top: 0;
  276. left: 0;
  277. height: 80px;
  278. margin: 0;
  279. width: 100%;
  280. }
  281. .uploaderImage .coverImg span {
  282. padding-top: 24px;
  283. display: block;
  284. text-align: center;
  285. }
  286. .uploaderImage .coverImg .ico {
  287. top: 30%;
  288. }
  289. #allmap {
  290. width: 10px;
  291. height: 10px;
  292. left: -1000px;
  293. position: relative;
  294. }
  295. </style>