uploadVTask.vue 7.7 KB

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