uploadVTask.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 form = {
  180. mediaIds: meidaIds,
  181. customId: this.customId,
  182. summaryId: this.summaryId,
  183. locationRemark: this.addressesRemark,
  184. };
  185. var loind1 = this.$toast.loading({
  186. duration: 0,
  187. message: '上传中...',
  188. forbidClick: true,
  189. });
  190. // 允许补填 添加上补填标识
  191. if (this.allowWriteAgain) {
  192. form.writeAgain = '1';
  193. }
  194. addPhotov(form).then((res) => {
  195. if (res.code == 200) {
  196. // that.imgArr = res.data.url;
  197. loind1.clear();
  198. this.$toast('上传成功!');
  199. let urlArr = [];
  200. let idArr = [];
  201. res.data.forEach((val) => {
  202. urlArr.push({
  203. fileUrl: val.url,
  204. id: val.fileId,
  205. // fileType: val.fileType,
  206. // fileName: val.fileName,
  207. type: this.type,
  208. index: this.indexImg,
  209. });
  210. idArr.push(val.fileId);
  211. });
  212. if (this.item.fileInfoList == null || this.item.fileInfoList == undefined) {
  213. this.item.fileInfoList = [];
  214. this.item.fileIdList = [];
  215. }
  216. this.item.fileInfoList = this.item.fileInfoList.concat(urlArr);
  217. this.item.fileIdList = this.item.fileIdList.concat(idArr);
  218. this.$emit('newimgarr');
  219. } else {
  220. this.$toast('上传失败!');
  221. }
  222. });
  223. },
  224. },
  225. };
  226. </script>
  227. <style scoped>
  228. .uploaderImage {
  229. position: relative;
  230. height: 80px;
  231. width: 80px;
  232. border: 1px solid #ccc;
  233. border-radius: 5px;
  234. }
  235. .uploaderImage img {
  236. position: absolute;
  237. width: 100%;
  238. display: block;
  239. height: 40px;
  240. top: 0;
  241. }
  242. .imgPre {
  243. height: 164px;
  244. width: 100%;
  245. background-color: white;
  246. border-radius: 6px;
  247. overflow: hidden;
  248. }
  249. .photos1 {
  250. margin: 70px auto;
  251. left: 50%;
  252. margin-left: -14px;
  253. }
  254. .photobrowsing {
  255. position: absolute;
  256. padding: 4px;
  257. right: 0;
  258. top: 0;
  259. z-index: 99;
  260. background-color: rgba(255, 255, 255, 0.8);
  261. border-bottom-left-radius: 3px;
  262. border-top-left-radius: 3px;
  263. }
  264. .uploaderImage .coverImg {
  265. text-align: center;
  266. position: absolute;
  267. top: 0;
  268. left: 0;
  269. height: 80px;
  270. margin: 0;
  271. width: 100%;
  272. }
  273. .uploaderImage .coverImg span {
  274. padding-top: 24px;
  275. display: block;
  276. text-align: center;
  277. }
  278. .uploaderImage .coverImg .ico {
  279. top: 30%;
  280. }
  281. #allmap {
  282. width: 10px;
  283. height: 10px;
  284. left: -1000px;
  285. position: relative;
  286. }
  287. </style>