renwuUpdateJin.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <template>
  2. <view class="content">
  3. <view class="param">
  4. <view class="proMiao mingchen">{{data.taskName}}</view>
  5. <view class="proMiao title">评分标准</view>
  6. <view class="prolittle">{{data.scoreStandard}}</view>
  7. <view class="proMiao title">任务负责人</view>
  8. <view class="prolittle">{{data.headerName}}</view>
  9. <view class="proMiao title">评分上限</view>
  10. <view class="prolittle">{{data.scoreLimit}}</view>
  11. <view class="proMiao">附件</view>
  12. <view class="prolittle" v-for="(item,index) in fileList3">
  13. <view style="color: rgba(0, 97, 255, 1);" @click="navigateToTU(item.name)">{{item.name}}</view>
  14. </view>
  15. <view class="proMiao title">权重</view>
  16. <view class="prolittle">{{data.weight}}</view>
  17. <view class="proMiao title">提醒时间</view>
  18. <view class="prolittle">{{data.remindTime}}</view>
  19. <view class="proMiao title">预警时间</view>
  20. <view class="prolittle">{{data.warnTime}}</view>
  21. <view class="proMiao title">任务周期</view>
  22. <view class="prolittle">{{data.startTime}} - {{data.endTime}}</view>
  23. <view class="proMiao title">完成说明</view>
  24. <textarea class="proINname proIMi" v-model="finishRemark" placeholder="请输入完成说明"/>
  25. <view class="proMiao">上传附件</view>
  26. <view class="upload-img">
  27. <uni-file-picker limit="3" :maxMb="2"
  28. @select='selectUpload'
  29. @delete="deleteHandle"
  30. :auto-upload='false'
  31. file-extname='pdf,docx,jpg,png,jpeg,doc,docm,dot,dotm,dotx,xlsx,xls,csv,xlsm,slxb,xlt,xltx'
  32. file-mediatype="all"
  33. @success='uploadSuccess'
  34. @fail='uploadFail'
  35. :list-styles='listStyles'
  36. v-model='fileList'
  37. ></uni-file-picker>
  38. </view>
  39. <span style="margin: 20rpx 0 0 20rpx;width: 700rpx;">支持pdf,docx,jpg,png,jpeg,doc,docm,dot,dotm,dotx,xlsx,xls,csv,xlsm,slxb,xlt,xltx格式,单个文件大小不超过2MB</span>
  40. <!-- 操作键 -->
  41. <view class="project">
  42. <view class="butt quxiao" @click="quxiao">取消</view>
  43. <view class="butt queren" @click="updateJindu">确定</view>
  44. </view>
  45. <view style="width: 100%;height: 60rpx;"></view>
  46. </view>
  47. <!-- 图片压缩 -->
  48. <Compress ref="Compress" />
  49. </view>
  50. </template>
  51. <script>
  52. import configdata from '@/common/config.js'
  53. // 引入压缩组件
  54. import Compress from '@/components/compress/compress.vue'
  55. export default {
  56. components:{
  57. Compress
  58. },
  59. data() {
  60. return {
  61. data:{},
  62. fileList3: [],
  63. // 完成进度上传附件
  64. fileList: [],
  65. fileList2: [],
  66. fileList22:'',
  67. listStyles: {
  68. "borderStyle": {
  69. "width": "0", // 边框宽度
  70. },
  71. "border": false, // 是否显示边框
  72. "dividline": false
  73. },
  74. finishRemark:'',//完成说明
  75. }
  76. },
  77. onLoad(option) {
  78. console.log(JSON.parse(decodeURIComponent(option.data)))
  79. this.data=JSON.parse(decodeURIComponent(option.data))
  80. var image=[]
  81. image=this.data.fileUrl.split(',')
  82. this.fileList3 =image.map(item =>{
  83. return {
  84. name: item
  85. }
  86. })
  87. },
  88. methods: {
  89. //跳转页面
  90. navigateToTU(url) {
  91. window.location.href = url;
  92. },
  93. //取消
  94. quxiao(){
  95. uni.navigateBack({
  96. delta:1
  97. })
  98. },
  99. //更新进度
  100. updateJindu(){
  101. let that = this
  102. uni.showLoading({
  103. title: '加载中',
  104. mask: true, // 是否显示透明蒙层,防止触摸穿透
  105. });
  106. var data={
  107. "taskId": that.data.id,
  108. "finishRemark": that.finishRemark,
  109. "fileUrl":that.fileList22
  110. }
  111. that.$Request.postT('/api/sysTask/submitTask',data).then(res => {
  112. if (res.code==200) {
  113. uni.showToast({
  114. title: '更新成功',
  115. icon: 'none',
  116. duration:800
  117. });
  118. uni.hideLoading()
  119. setTimeout(function() {
  120. uni.navigateBack({
  121. delta:1
  122. })
  123. // uni.switchTab({
  124. // url:'/pages/project/index'
  125. // })
  126. }, 1000)
  127. } else {
  128. uni.hideLoading();
  129. uni.showToast({
  130. title: res.message,
  131. icon: 'none',
  132. duration:800
  133. });
  134. }
  135. });
  136. },
  137. // 上传附件
  138. uploadSuccess(e) {
  139. console.log('上传成功', e)
  140. },
  141. uploadFail(e) {
  142. console.log('上传失败:', e)
  143. },
  144. //删除文件
  145. deleteHandle(index){
  146. console.log(index)
  147. this.fileList2.splice(index.index,1)
  148. console.log(this.fileList2)
  149. this.fileList22=this.fileList2.join(",")
  150. console.log(this.fileList22)
  151. // uni.showLoading({
  152. // title: '删除中',
  153. // mask: true, // 是否显示透明蒙层,防止触摸穿透
  154. // });
  155. // var data={
  156. // "fileName": this.fileList2[index]
  157. // }
  158. // this.$Request.postT('/api/sysFile/delete',data).then(res => {
  159. // if (res.code==200) {
  160. // uni.showToast({
  161. // title: '删除成功',
  162. // icon: 'none',
  163. // duration:800
  164. // });
  165. // uni.hideLoading()
  166. // } else {
  167. // uni.hideLoading();
  168. // uni.showToast({
  169. // title: res.message,
  170. // icon: 'none',
  171. // duration:800
  172. // });
  173. // }
  174. // });
  175. },
  176. async selectUpload(e) {
  177. console.log('上传:', e)
  178. // console.log((e.tempFiles[0].size / 1024 > 1024 * 2),'大小')
  179. if(e.tempFiles.length>0){
  180. for (let i = 0; i < e.tempFilePaths.length; i++) {
  181. if ((e.tempFiles[i].size / 1024 > 1024 * 2)) {
  182. console.log('过大',e.tempFiles[i].extname)
  183. if(e.tempFiles[i].extname=='jpg' || e.tempFiles[i].extname=='png'||e.tempFiles[i].extname=='jpeg'){
  184. this.yaimg(e.tempFilePaths[i])
  185. }else{
  186. uni.showModal({
  187. title: '提示',
  188. content: '文件大于2M,无法上传',
  189. showCancel: false, // 是否显示取消按钮,默认为 true // 是否显示取消按钮,默认为 true
  190. success: function(res) {
  191. if (res.confirm) {
  192. }
  193. }
  194. });
  195. }
  196. }else{
  197. this.imgUpload(e.tempFiles[i].file);
  198. }
  199. }
  200. }
  201. },
  202. //上传图片
  203. async imgUpload(result){
  204. uni.showLoading({
  205. title: '上传中',
  206. mask: true, // 是否显示透明蒙层,防止触摸穿透
  207. });
  208. let data = new FormData();
  209.   data.set("file", result);
  210.   let res = await this.$axios({
  211.     method: "post",
  212.     url: this.config('APIHOST1') + "/api/sysFile/upload",
  213.     headers: {
  214. tokenW: sessionStorage.getItem("token"),
  215. "Content-Type": "multipart/form-data"
  216.     },
  217.     data: data,
  218.   });
  219. // return res
  220.   console.log(res, "图片上传成功");
  221.   if (res.data.code == 200) {
  222. console.log(this.fileList)
  223.     this.fileList2.push(res.data.data);
  224. this.fileList22=this.fileList2.join(",")
  225. // console.log(this.fileList2.join(","))
  226. uni.hideLoading();
  227.   } else if(res.message=="登录凭证已过去,请重新登录"){
  228. sessionStorage.removeItem("token")
  229. sessionStorage.removeItem("roleId")
  230. uni.showModal({
  231. title: '提示',
  232. content: '用户信息失效,请重新登录!',
  233. showCancel: false, // 是否显示取消按钮,默认为 true // 是否显示取消按钮,默认为 true
  234. success: function(res) {
  235. if (res.confirm) {
  236. }
  237. }
  238. });
  239. uni.hideLoading();
  240. }else {
  241.     uni.showToast({
  242. title: res.message,
  243. icon: 'none',
  244. duration:800
  245. });
  246. uni.hideLoading();
  247.   }
  248. },
  249. /**
  250. * 压缩图片
  251. * @description 由组件处理,只需传入临时路径
  252. * @param {Object} url - 临时路径
  253. * @return void
  254. */
  255. yaimg(url) {
  256. uni.showLoading({
  257. title: '压缩中',
  258. mask: true, // 是否显示透明蒙层,防止触摸穿透
  259. });
  260. // 组件参数也有文档,详见文章的最底部!
  261. // const config = {
  262. // src: url,//要压缩的临时路径
  263. // maxSize: 800,//压缩后的最大尺寸
  264. // fileType: 'png',//压缩后的文件类型,可选值 jpg、png
  265. // quality: 0.6,//压缩后的质量(仅jpg类型有效,原因可自行阅读官方canvas文档),可选值 0 ~ 1,值越大越清晰(图片也越大)
  266. // }
  267. // console.log(config)
  268. // 调用压缩方法
  269. this.$refs.Compress.compress({
  270. src: url,//要压缩的临时路径
  271. maxSize: 800,//压缩后的最大尺寸
  272. fileType: '',//压缩后的文件类型,可选值 jpg、png
  273. quality: 0.6,//压缩后的质量(仅jpg类型有效,原因可自行阅读官方canvas文档),可选值 0 ~ 1,值越大越清晰(图片也越大)
  274. }).then((res) => {
  275. // console.log('返回的base64编码', res)
  276. this.base = res
  277. // 时间戳 + 随机数, 防止文件名重复
  278. let timestamp = new Date().getTime();
  279. let sunumber = Math.floor(Math.random()*999);
  280. // H5需要将base64转为file对象进行上传
  281. // 第一个参数是base64编码, 第二个是文件名
  282. var file = this.base64ToFile(res, timestamp + sunumber)
  283. // 最终压缩完毕的file对象
  284. console.log('压缩后的图片(File对象)', file)
  285. this.upload(file)
  286. this.file = file
  287. uni.hideLoading();
  288. //上传到服务器
  289. // this.upload(file)
  290. }).catch((err) => {
  291. console.log('压缩失败',err)
  292. uni.hideLoading();
  293. })
  294. },
  295. /**
  296. * 压缩后上传到服务器
  297. * @description 这块需要您自行处理
  298. * @param {Object} file - 要上传的file对象
  299. * @return void
  300. */
  301. async upload(file){
  302. uni.showLoading({
  303. title: '上传中',
  304. mask: true, // 是否显示透明蒙层,防止触摸穿透
  305. });
  306. let data = new FormData();
  307.   data.set("file", file);
  308. console.log(data)
  309.   let res = await this.$axios({
  310.     method: "post",
  311.     url: this.config('APIHOST1') + "/api/sysFile/upload",
  312.     headers: {
  313. tokenW: sessionStorage.getItem("token"),
  314. "Content-Type": "multipart/form-data"
  315.     },
  316.     data: data,
  317.   });
  318. // return res
  319.   console.log(res, "图片上传成功",res.data.code == 200);
  320.   if (res.data.code == 200) {
  321.     this.fileList2.push(res.data.data);
  322. this.fileList22=this.fileList2.join(",")
  323. console.log(this.fileList22)
  324. uni.hideLoading();
  325.   }else {
  326.     uni.showToast({
  327. title: res.message,
  328. icon: 'none',
  329. duration:800
  330. });
  331. uni.hideLoading();
  332.   }
  333. },
  334. /**
  335. * base64 → File
  336. * @description 转换函数
  337. * @param {String} base64- base64完整字符串
  338. * @param {String} name - 文件名
  339. * @return Object
  340. */
  341. base64ToFile(base64, name) {
  342. if (typeof base64 != 'string') { return; }
  343. var arr = base64.split(',')
  344. var type = arr[0].match(/:(.*?);/)[1]
  345. var fileExt = type.split('/')[1]
  346. var bstr = atob(arr[1])
  347. var n = bstr.length
  348. var u8arr = new Uint8Array(n)
  349. while (n--) {
  350. u8arr[n] = bstr.charCodeAt(n)
  351. }
  352. return new File([u8arr], `${name}.` + fileExt, {
  353. type: type
  354. })
  355. },
  356. config: function (name) {
  357. var info = null
  358. if (name) {
  359. var name2 = name.split('.') //字符分割
  360. if (name2.length > 1) {
  361. info = configdata[name2[0]][name2[1]] || null
  362. } else {
  363. info = configdata[name] || null
  364. }
  365. if (info == null) {
  366. let web_config = cache.get('web_config')
  367. if (web_config) {
  368. if (name2.length > 1) {
  369. info = web_config[name2[0]][name2[1]] || null
  370. } else {
  371. info = web_config[name] || null
  372. }
  373. }
  374. }
  375. }
  376. return info
  377. },
  378. }
  379. }
  380. </script>
  381. <style>
  382. .content {
  383. display: flex;
  384. flex-direction: column;
  385. align-items: center;
  386. justify-content: center;
  387. }
  388. .param{
  389. margin: 20rpx 0 0 0;
  390. width: 100%;
  391. background-color: rgba(255, 255, 255, 1);
  392. font-size: 28rpx;
  393. font-weight: 400;
  394. line-height: 41rpx;
  395. color: rgba(0, 0, 0, 1);
  396. }
  397. .proMiao{
  398. margin: 31rpx 0 0 20rpx;
  399. width: 710rpx;
  400. }
  401. .prolittle{
  402. margin: 5rpx 0 0 20rpx;
  403. width: 710rpx;
  404. word-wrap: break-word;
  405. word-break: break-all;
  406. white-space: pre-line;
  407. }
  408. .proINname{
  409. margin: 25rpx 0 0 21rpx;
  410. width: 709rpx;
  411. height: 90rpx;
  412. border-radius: 13rpx;
  413. background: rgba(245, 248, 252, 1);
  414. border: 1rpx solid rgba(229, 229, 229, 1);
  415. font-size: 28rpx;
  416. line-height: 90rpx;
  417. /* color: rgba(179, 179, 179, 1); */
  418. }
  419. .proIMi{
  420. height: 315rpx;
  421. }
  422. .mingchen{
  423. font-size: 32rpx;
  424. font-weight: 500;
  425. line-height: 46rpx;
  426. }
  427. .title{
  428. color: rgba(102, 102, 102, 1);
  429. }
  430. /* 操作键 */
  431. .project{
  432. display: flex;
  433. margin: 61rpx 0 0 0;
  434. justify-content: space-evenly;
  435. }
  436. .butt{
  437. width: 330rpx;
  438. height: 90rpx;
  439. border-radius: 117rpx;
  440. font-size: 32rpx;
  441. line-height: 90rpx;
  442. text-align: center;
  443. }
  444. .quxiao{
  445. border: 1rpx solid rgba(0, 97, 255, 1);
  446. color: rgba(0, 97, 255, 1);
  447. }
  448. .queren{
  449. background: rgba(0, 97, 255, 1);
  450. color: rgba(255, 255, 255, 1);
  451. }
  452. </style>