uploadKTask.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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">
  7. </van-icon>
  8. <span>{{ imgText }}</span>
  9. </p>
  10. </div>
  11. </van-col>
  12. </template>
  13. <script>
  14. import {ImagePreview} from "vant";
  15. import {addPhotoK} from "@/api/clew";
  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. data() {
  54. return {
  55. shows: false,
  56. url: ""
  57. }
  58. },
  59. methods: {
  60. deleteImgs(val) {
  61. ImagePreview([val]);
  62. },
  63. uploadImg(){
  64. let url = window.location.href;
  65. let that = this;
  66. let wx = this.wx
  67. let qiyeData
  68. const instance = axios.create();
  69. instance.defaults.headers.common['userId'] = localStorage.getItem("loginName");
  70. instance.get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket',
  71. {
  72. params: {
  73. url: url
  74. }
  75. }).then(response => {
  76. if (response.status == 200) {
  77. qiyeData = response.data.data;
  78. wx.config({
  79. beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
  80. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  81. appId: qiyeData.appId, // 必填,企业微信的corpID
  82. timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
  83. nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
  84. signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
  85. jsApiList: ["ready", "chooseImage","uploadImage"] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
  86. });
  87. wx.ready(function () {
  88. wx.chooseImage({
  89. count: 1,
  90. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  91. sourceType:['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  92. defaultCameraMode: "normal", //表示进入拍照界面的默认模式,目前有normal与batch两种选择,normal表示普通单拍模式,batch表示连拍模式,不传该参数则为normal模式。从3.0.26版本开始支持front和batch_front两种值,其中front表示默认为前置摄像头单拍模式,batch_front表示默认为前置摄像头连拍模式。(注:用户进入拍照界面仍然可自由切换两种模式)
  93. isSaveToAlbum:0,
  94. success: function (res) {
  95. var localIds=""
  96. if(res.localIds!=undefined){
  97. localIds= res.localIds[0]
  98. }else{
  99. localIds=res.localId
  100. }
  101. wx.uploadImage({
  102. localId: localIds, // 需要上传的图片的本地ID,由chooseImage接口获得
  103. isShowProgressTips: 1, // 默认为1,显示进度提示
  104. success: function (res) {
  105. that.uploadImagev(res.serverId)
  106. }
  107. });
  108. }
  109. });
  110. })
  111. }
  112. });
  113. },
  114. uploadImagev(meidaId){
  115. var that = this;
  116. var form={
  117. mediaId:meidaId,
  118. customerClueId:that.customId,
  119. customerClueItemId:that.summaryId
  120. }
  121. var loind1 = that.$toast.loading({
  122. duration: 0,
  123. message: '上传中...',
  124. forbidClick: true,
  125. });
  126. addPhotoK(form).then(res=>{
  127. if (res.code == 200) {
  128. that.imgArr = res.data.url
  129. loind1.clear();
  130. that.$toast("上传成功!")
  131. that.$emit('newimgarr', {fileUrl: res.data.url,id:res.data.fileId,fileType:res.fileType,fileName:res.fileName, type: that.type,index:that.indexImg});
  132. } else {
  133. that.$toast("上传失败!")
  134. }
  135. })
  136. }
  137. },
  138. }
  139. </script>
  140. <style scoped>
  141. .uploaderImage {
  142. position: relative;
  143. height: 80px;
  144. width: 80px;
  145. border: 1px solid #ccc;
  146. border-radius: 5px;
  147. }
  148. .uploaderImage img {
  149. position: absolute;
  150. width: 100%;
  151. display: block;
  152. height: 40px;
  153. top: 0;
  154. }
  155. .imgPre {
  156. height: 164px;
  157. width: 100%;
  158. background-color: white;
  159. border-radius: 6px;
  160. overflow: hidden;
  161. }
  162. .photos1 {
  163. margin: 70px auto;
  164. left: 50%;
  165. margin-left: -14px;
  166. }
  167. .photobrowsing {
  168. position: absolute;
  169. padding: 4px;
  170. right: 0;
  171. top: 0;
  172. z-index: 99;
  173. background-color: rgba(255, 255, 255, 0.8);
  174. border-bottom-left-radius: 3px;
  175. border-top-left-radius: 3px
  176. }
  177. .uploaderImage .coverImg {
  178. text-align: center;
  179. position: absolute;
  180. top: 0;
  181. left: 0;
  182. height: 80px;
  183. margin: 0;
  184. width: 100%;
  185. }
  186. .uploaderImage .coverImg span{
  187. padding-top: 24px;
  188. display: block;text-align: center;
  189. }
  190. .uploaderImage .coverImg .ico {
  191. top: 30%;
  192. }
  193. #allmap{
  194. width: 10px;
  195. height: 10px;
  196. left: -1000px;
  197. position: relative;
  198. }
  199. </style>