viewaddreddUploadImg.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <div>
  3. <div class="cameraDiv1">
  4. <div class="imgPre">
  5. <van-icon
  6. class="photobrowsing"
  7. name="expand-o"
  8. size="22px"
  9. color="#1989fa"
  10. v-if="imgArr != ''"
  11. @click="deleteImgs(imgArr)" />
  12. <img :src="imgArr" alt="" v-if="imgArr != ''" />
  13. </div>
  14. <p class="coverImg" @click="uploadImg">
  15. <van-icon class="photo ico" name="photograph" size="16px" color="#969696">{{
  16. imgText
  17. }}</van-icon>
  18. </p>
  19. </div>
  20. <p style="text-align: center">{{ imgText }}</p>
  21. </div>
  22. </template>
  23. <script>
  24. import { ImagePreview } from 'vant';
  25. import axios from 'axios';
  26. import { uploadImageaddress } from '@/api/index';
  27. export default {
  28. name: 'uploadImg',
  29. props: {
  30. uploadid: {
  31. type: String,
  32. default: '',
  33. },
  34. imgText: {
  35. type: String,
  36. default: '',
  37. },
  38. visitsId: {
  39. type: String,
  40. default: '',
  41. },
  42. taskId: {
  43. type: String,
  44. default: '',
  45. },
  46. collectionId: {
  47. type: String,
  48. default: '',
  49. },
  50. type: {
  51. type: Number,
  52. default: 1,
  53. },
  54. imgArr: {
  55. type: String,
  56. default: '',
  57. },
  58. },
  59. data() {
  60. return {
  61. shows: false,
  62. url: '',
  63. };
  64. },
  65. methods: {
  66. deleteImgs(val) {
  67. ImagePreview([val]);
  68. },
  69. uploadImg() {
  70. if (localStorage.getItem('chainName') == null) {
  71. this.$toast('请输入名称!');
  72. return;
  73. }
  74. let url = window.location.href;
  75. let that = this;
  76. let wx = this.wx;
  77. let qiyeData;
  78. const instance = axios.create();
  79. instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
  80. instance
  81. .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
  82. params: {
  83. url: url,
  84. },
  85. })
  86. .then((response) => {
  87. if (response.status == 200) {
  88. qiyeData = response.data.data;
  89. wx.config({
  90. beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
  91. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  92. appId: qiyeData.appId, // 必填,企业微信的corpID
  93. timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
  94. nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
  95. signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
  96. jsApiList: ['ready', 'chooseImage', 'uploadImage', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
  97. });
  98. wx.ready(function () {
  99. var locations = '';
  100. wx.getLocation({
  101. type: 'gcj02',
  102. success: function (response) {
  103. locations = response;
  104. wx.chooseImage({
  105. count: 1,
  106. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  107. sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
  108. defaultCameraMode: 'normal', //表示进入拍照界面的默认模式,目前有normal与batch两种选择,normal表示普通单拍模式,batch表示连拍模式,不传该参数则为normal模式。从3.0.26版本开始支持front和batch_front两种值,其中front表示默认为前置摄像头单拍模式,batch_front表示默认为前置摄像头连拍模式。(注:用户进入拍照界面仍然可自由切换两种模式)
  109. isSaveToAlbum: 0,
  110. success: function (res) {
  111. var localIds = '';
  112. if (res.localIds != undefined) {
  113. localIds = res.localIds[0];
  114. } else {
  115. localIds = res.localId;
  116. }
  117. wx.uploadImage({
  118. localId: localIds,
  119. isShowProgressTips: 1,
  120. success: function (res) {
  121. that.uploadImagev(res.serverId, locations.latitude, locations.longitude);
  122. },
  123. });
  124. },
  125. });
  126. },
  127. fail: function () {
  128. that.$dialog.alert({
  129. message: 'GPS未开启',
  130. });
  131. },
  132. });
  133. });
  134. }
  135. });
  136. },
  137. uploadImagev(meidaId, lat, lng) {
  138. var that = this;
  139. var form = {
  140. mediaId: meidaId,
  141. storeName: localStorage.getItem('chainName'),
  142. locationRemark: localStorage.getItem('locationRemark'),
  143. deptName: localStorage.getItem('deptName'),
  144. lat: lat,
  145. lng: lng,
  146. };
  147. var loind1 = that.$toast.loading({
  148. duration: 0,
  149. message: '上传中...',
  150. forbidClick: true,
  151. });
  152. uploadImageaddress(form).then((res) => {
  153. if (res.code == 200) {
  154. that.imgArr = res.data.url;
  155. loind1.clear();
  156. that.$toast('上传成功!');
  157. that.$emit('newimgarr', { fileUrl: res.data.url, type: that.type });
  158. } else {
  159. that.$toast('上传失败!');
  160. }
  161. });
  162. },
  163. },
  164. };
  165. </script>
  166. <style scoped>
  167. .cameraDiv1 {
  168. position: relative;
  169. height: 164px;
  170. width: 100%;
  171. }
  172. .cameraDiv1 img {
  173. position: absolute;
  174. width: 100%;
  175. display: block;
  176. height: 164px;
  177. top: 0;
  178. }
  179. .imgPre {
  180. height: 164px;
  181. width: 100%;
  182. background-color: white;
  183. border-radius: 6px;
  184. overflow: hidden;
  185. }
  186. .photos1 {
  187. margin: 70px auto;
  188. left: 50%;
  189. margin-left: -14px;
  190. }
  191. .photobrowsing {
  192. position: absolute;
  193. padding: 4px;
  194. right: 0;
  195. top: 0;
  196. z-index: 99;
  197. background-color: rgba(255, 255, 255, 0.8);
  198. border-bottom-left-radius: 3px;
  199. border-top-left-radius: 3px;
  200. }
  201. .coverImg {
  202. text-align: center;
  203. position: absolute;
  204. top: 0;
  205. left: 0;
  206. height: 164px;
  207. width: 100%;
  208. }
  209. .coverImg .ico {
  210. top: 42%;
  211. }
  212. </style>