reconditionAlarmUpload.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <view>
  3. <!-- <view class="input-box ddflex">
  4. <view class="input fflex">
  5. <input class="fflex" placeholder="请输入设备编号"/>
  6. </view>
  7. <image class="saoma" src="../../static/pages/images/saoma.png"></image>
  8. </view> -->
  9. <view>
  10. <view class="item ddflex">
  11. <view class="label">类型</view>
  12. <view class="item-input fflex">
  13. 整柜巡检
  14. </view>
  15. </view>
  16. <view class="item ddflex">
  17. <view class="label">机柜编号</view>
  18. <view class="item-input fflex">
  19. CHZD04TTCC200329109
  20. </view>
  21. </view>
  22. <view class="item ddflex">
  23. <view class="label">描述</view>
  24. <view class="item-input fflex">
  25. 定期巡检提醒
  26. </view>
  27. </view>
  28. <view class="item ddflex">
  29. <view class="label">提醒时间</view>
  30. <view class="item-input fflex">
  31. 2022-12-31 17:16:37
  32. </view>
  33. </view>
  34. <!-- <view class="item ddflex">
  35. <view class="label">提醒时间</view>
  36. <view class="item-input fflex">
  37. <biaofundatetimepicker class="biao fflex" :dateStr="time"
  38. placeholder="提醒时间" fields="minute" @change="changeEndDatetimePicker"></biaofundatetimepicker>
  39. </view>
  40. </view> -->
  41. <!-- <view class="item ddflex">
  42. <view class="label">检修记录表</view>
  43. <view class="item-input fflex" style="color: #2A82E4;" @click="choiceImages">
  44. 点击上传
  45. </view>
  46. </view> -->
  47. <view class="img-box ddflex" @click="choiceImages" v-if="imageList.length==0">
  48. <image style="width: 54rpx;height: 54rpx;margin-bottom: 12rpx;" src="../static/images/xj.png"></image>
  49. <view>添加图片</view>
  50. </view>
  51. <image v-else style="width: 100%;margin: 30rpx;" :src="imageList[0]" mode="widthFix" @click="choiceImages"></image>
  52. <!-- <view class="ddflex" style="margin-bottom: 40rpx;padding: 30rpx;">
  53. <view class="product-image" v-for="item,index in imageList">
  54. <image style="width: 100%;height: 100%;margin-bottom: 0;" :src="item"></image>
  55. <image class="product-image-delete" src="../static/images/imagecuo.png" @click="removeProductImage(index)"></image>
  56. </view>
  57. </view> -->
  58. </view>
  59. <!-- 保存按钮 -->
  60. <view class="savepadding submit-box">
  61. <view class="submit-btn">
  62. 保存
  63. </view>
  64. </view>
  65. <canvas canvas-id="canvas" :style="'width:' + cWidth + 'px;height:' + cHeight +'px;position: absolute;left:-1000px;top:-1000px;'"></canvas>
  66. </view>
  67. </template>
  68. <script>
  69. const app = getApp();
  70. const req = require("../../utils/request.js");
  71. import biaofundatetimepicker from '../../components/biaofun-datetime-picker/biaofun-datetime-picker.vue';
  72. export default {
  73. components: {
  74. biaofundatetimepicker
  75. },
  76. props: {},
  77. data() {
  78. return {
  79. systems: {},
  80. isTop:0,
  81. name:'白云科技门店',
  82. time:'',
  83. imageList:[],
  84. cWidth: 0,
  85. cHeight: 0,
  86. }
  87. },
  88. onLoad(options) {
  89. },
  90. onShow() {
  91. },
  92. methods: {
  93. changeEndDatetimePicker(val) {
  94. this.time = val.f1 + " " + val.hh+":"+val.mm+":"+"00"
  95. },
  96. // 图片移除
  97. // 移除产品图片
  98. removeProductImage(index){
  99. this.imageList.splice(index,1)
  100. },
  101. // 图片上传
  102. choiceImages(event) {
  103. let that = this;
  104. uni.chooseImage({
  105. count: 9,
  106. sourceType: ['album', 'camera'],
  107. sizeType: ['compressed'],
  108. async success(res) {
  109. console.log(res);
  110. let list = res.tempFiles;
  111. console.log(list);
  112. let allList = [];
  113. for (let i = 0; i < list.length; i++) {
  114. //两M
  115. if (list[i].size > 50000) {
  116. var path = await that.compressImg(list[i].path)
  117. console.log(path)
  118. var data = {
  119. formData: {
  120. flag: 726
  121. },
  122. filePath: path,
  123. name: 'file'
  124. }
  125. allList.push(data);
  126. } else {
  127. var data = {
  128. formData: {
  129. flag: 722
  130. },
  131. filePath: list[i].path,
  132. name: 'file'
  133. }
  134. allList.push(data);
  135. }
  136. }
  137. console.log(allList)
  138. let successUp = 0;
  139. let failUp = 0;
  140. let count = 0
  141. // 多图上传 allList:图片数组 successUp:上传成功次数 现在上传的下标
  142. that.uploadImgs(allList, successUp, failUp, count);
  143. },
  144. fail(err) {}
  145. })
  146. },
  147. //通过canvans缩放长宽来压缩图片 path:图片本地路径 limitNum:压缩到长宽多大
  148. async compressImg(path, multiple = 2, limitNum = 600) {
  149. console.log('图片链接', path)
  150. let that = this;
  151. return new Promise((resolve, reject) => {
  152. uni.getImageInfo({
  153. src: path,
  154. success(res) {
  155. var canvasWidth = res.width //图片原始长宽
  156. var canvasHeight = res.height
  157. console.log('图片的基本信息', res)
  158. // while循环 保证宽高在100以内 Math.trunc()去掉小数点右边数
  159. while (canvasWidth > limitNum || canvasHeight > limitNum) {
  160. canvasWidth = Math.trunc(res.width / multiple)
  161. canvasHeight = Math.trunc(res.height / multiple)
  162. multiple++
  163. }
  164. //设置画布长宽
  165. that.setData({
  166. cWidth: canvasWidth,
  167. cHeight: canvasHeight
  168. })
  169. //----------绘制图形并取出图片路径--------------
  170. var ctx = uni.createCanvasContext('canvas')
  171. ctx.drawImage(res.path, 0, 0, canvasWidth, canvasHeight)
  172. ctx.draw(false, setTimeout(() => {
  173. uni.canvasToTempFilePath({
  174. canvasId: 'canvas',
  175. destWidth: canvasWidth,
  176. destHeight: canvasHeight,
  177. success: function(res) {
  178. console.log(res.tempFilePath) //图片路径
  179. resolve(res.tempFilePath)
  180. },
  181. fail: function(res) {
  182. console.log(res.errMsg)
  183. }
  184. })
  185. }, 100))
  186. },
  187. fail: function(res) {
  188. console.log(res.errMsg)
  189. },
  190. })
  191. })
  192. },
  193. //多张图片上传
  194. uploadImgs: function(allList, successUp, failUp, count) {
  195. console.log(allList, successUp, failUp, count)
  196. let that = this;
  197. let length = allList.length; //总共上传的数量
  198. var promise = Promise.all(allList.map(tempFilePath => {
  199. return new Promise(function(resolve, reject) {
  200. req.loadIng("上传中");
  201. req.uploadFile('/api/nocheck/upload', tempFilePath.filePath, res => {
  202. that.imageList = that.imageList.concat(res.src);
  203. resolve()
  204. });
  205. });
  206. }));
  207. promise.then(function(results) {
  208. uni.showToast({
  209. title: '上传成功',
  210. icon: 'success',
  211. duration: 2000
  212. });
  213. // console.log(results);
  214. }).catch(function(err) {
  215. uni.hideToast()
  216. // console.log(err);
  217. });
  218. },
  219. },
  220. mounted() {
  221. const systemInfo = uni.getSystemInfoSync();
  222. // px转换到rpx的比例
  223. let pxToRpxScale = 750 / systemInfo.windowWidth;
  224. let systems = {
  225. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  226. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  227. };
  228. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  229. this.systems = systems;
  230. },
  231. onPageScroll: function(e) {
  232. if (e.scrollTop > this.systems.barHeight) {
  233. this.isTop = 1;
  234. } else {
  235. this.isTop = 0;
  236. }
  237. }
  238. }
  239. </script>
  240. <style>
  241. @import "./reconditionAlarmUpload.css";
  242. </style>