supervisortask.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div class="questionNamep">
  3. <div class="cameraDiv">
  4. <van-icon class="photo photos" name="photograph" size="22px" color="#969696"/>
  5. <input class="camera" style="opacity: 0;position: absolute; right: 0;" type="file" name="cover"
  6. :id="uploadid"
  7. accept="image/*"
  8. capture="camera"
  9. @change="readLocalFile($event)"/>
  10. </div>
  11. </div>
  12. </template>
  13. <script>
  14. import {addPhoto} from "@/api/index";
  15. export default {
  16. name: 'uploadImg',
  17. props: {
  18. uploadid: {
  19. type: String,
  20. default: ''
  21. },
  22. storeGroupId: {
  23. type: String,
  24. default: ''
  25. },
  26. visitsId: {
  27. type: String,
  28. default: ''
  29. },
  30. taskId: {
  31. type: String,
  32. default: ''
  33. },
  34. collectionId: {
  35. type: String,
  36. default: ''
  37. },
  38. objectType: {
  39. type: String,
  40. default: ''
  41. },
  42. type: {
  43. type: Number,
  44. default: 1
  45. },
  46. imgArr: {
  47. type: Array,
  48. default() {
  49. return []
  50. }
  51. },
  52. visitModel: {
  53. type: String,
  54. default: '1'
  55. },
  56. },
  57. data() {
  58. return {
  59. shows: false,
  60. url: ""
  61. }
  62. },
  63. methods: {
  64. // deleteImg(){
  65. //
  66. // },
  67. // CurentTime(){
  68. // var now = new Date();
  69. // var year = now.getFullYear(); //年
  70. // var month = now.getMonth() + 1; //月
  71. // var day = now.getDate(); //日
  72. // var hh = now.getHours(); //时
  73. // var mm = now.getMinutes(); //分
  74. // var clock = year + "-";
  75. // if(month < 10)
  76. // clock += "0";
  77. // clock += month + "-";
  78. // if(day < 10)
  79. // clock += "0";
  80. // clock += day + " ";
  81. // // if(hh < 10)
  82. // // clock += "0";
  83. // // clock += hh + ":";
  84. // // if (mm < 10) clock += '0';
  85. // // clock += mm;
  86. // return(clock);
  87. // },
  88. readLocalFile(e) {
  89. this.shows = true
  90. if (this.objectType == "" || this.objectType == null) {
  91. this.$toast("请选择类型!")
  92. return
  93. }
  94. var localFile = e.target.files[0];
  95. var reader = new FileReader();
  96. var content;
  97. var that = this;
  98. reader.onload = function (event) {
  99. content = event.target.result;
  100. localFile.content = content
  101. that.uploadImgs(localFile);
  102. }
  103. reader.onerror = function () {
  104. this.$toast("上传失败!")
  105. }
  106. content = reader.readAsDataURL(localFile, "UTF-8");
  107. },
  108. uploadImgs(file) {
  109. if (/\/(?:jpeg|png)/i.test(file.type) && file.size > 200000) {
  110. this.zcompress(file, 0.7)
  111. } else {
  112. this.zcompress(file, 1)
  113. }
  114. },
  115. zcompress(file, quiry) {
  116. var that = this;
  117. var loind1 = that.$toast.loading({
  118. duration: 0,
  119. message: '上传中...',
  120. forbidClick: true,
  121. });
  122. let canvas = document.createElement("canvas");
  123. let context = canvas.getContext("2d");
  124. let img = new Image();
  125. img.src = file.content;
  126. img.onload = () => {
  127. let scale = img.width / 750
  128. let newWidth = img.width / scale
  129. let newHeight = img.height / scale
  130. canvas.width = newWidth;
  131. canvas.height = newHeight;
  132. context.drawImage(img, 0, 0, newWidth, newHeight);
  133. context.fillStyle = "#D27D69";
  134. context.textBaseline = "middle";
  135. context.font = "bold "+(newWidth / 28) + "px Arial";
  136. var chainNameR = localStorage.getItem('chainNameR')
  137. var ORGName = localStorage.getItem('ORGName')
  138. var chainNameR1 = ""
  139. var chainNameR2 = ""
  140. if (chainNameR.length > 17) {
  141. chainNameR1 = chainNameR.slice(0, 16)
  142. chainNameR2 = chainNameR.slice(16)
  143. } else {
  144. chainNameR1 = chainNameR
  145. chainNameR2 = ""
  146. }
  147. context.fillText(ORGName + "", newWidth / 10, newHeight / 2 -60);
  148. context.fillText(that.parseTime(new Date(), '{y}-{m}-{d}') + chainNameR1 + "", newWidth / 10, newHeight / 2);
  149. context.fillText(chainNameR2 + "", newWidth / 10, newHeight / 2 + 60);
  150. context.fillStyle = "#8C588B ";
  151. context.fillText(ORGName + "", newWidth / 10, newHeight / 2 + 110);
  152. context.fillText(that.parseTime(new Date(), '{y}-{m}-{d}') + chainNameR1 + "",
  153. newWidth / 10, newHeight / 2 + 170);
  154. context.fillText(chainNameR2 + "", newWidth / 10, newHeight / 2 + 230);
  155. file.content = canvas.toDataURL(file.type, quiry);
  156. const formData = new FormData();
  157. formData.append("file",file);
  158. formData.append("collectionItemId", that.collectionId);
  159. formData.append("objectType", that.objectType);
  160. formData.append("storeGroupId", that.storeGroupId);
  161. formData.append("taskId", that.taskId);
  162. formData.append("visitsId", that.visitsId);
  163. formData.append("visitModel", that.visitModel);
  164. formData.append("visitSource", "1");
  165. addPhoto(formData).then(res => {
  166. if (res.code == 200) {
  167. loind1.clear();
  168. that.$toast("上传成功!")
  169. that.$emit('newimgarr', {fileUrl: file.content, id: res.data, type: 2});
  170. } else {
  171. that.$toast("上传失败!")
  172. }
  173. })
  174. };
  175. }
  176. },
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. .questionNamep {
  181. font-size: 16px;
  182. color: #484848;
  183. line-height: 40px;
  184. padding: 0 15px;
  185. box-sizing: border-box;
  186. position: relative;
  187. .cameraDivp {
  188. flex: 1;
  189. display: flex;
  190. align-items: center;
  191. justify-content: center;
  192. .photo {
  193. /*margin-top: 9px;*/
  194. float: right;
  195. }
  196. .camera {
  197. width: 60px;
  198. height: 100%;
  199. position: absolute;
  200. right: 0;
  201. top: 0;
  202. opacity: 0;
  203. z-index: 89;
  204. }
  205. }
  206. }
  207. </style>