item.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // this.$time.dateFormat('yyyy-MM-dd',new Date())
  2. // 格式 时间
  3. import {
  4. encryptDes,
  5. decryptDes
  6. } from '@/encryption/index.js' // 引用路径根据自己的文件结构而定
  7. import
  8. Base64
  9. from 'base-64'
  10. export default {
  11. // 时间格式化
  12. dateFormat: function(fmt, date) {
  13. if (date == null) return ''
  14. if (typeof date === 'string') {
  15. date = new Date(Date.parse(date.replace(/-/g, '/').replace('.0', '')))
  16. } else {
  17. date = new Date(date)
  18. }
  19. let ret
  20. const opt = {
  21. 'y+': date.getFullYear().toString(), // 年
  22. 'M+': (date.getMonth() + 1).toString(), // 月
  23. 'd+': date.getDate().toString(), // 日
  24. 'H+': date.getHours().toString(), // 时
  25. 'm+': date.getMinutes().toString(), // 分
  26. 'S+': date.getSeconds().toString() // 秒
  27. // 有其他格式化字符需求可以继续添加,必须转化成字符串
  28. }
  29. for (const k in opt) {
  30. ret = new RegExp('(' + k + ')').exec(fmt)
  31. // opt = opt.replace('-','/')
  32. if (ret) {
  33. fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, '0')))
  34. }
  35. }
  36. return fmt
  37. },
  38. // 秒数转换分钟秒
  39. minuteSecond: function(second) {
  40. var second = Math.floor(second)
  41. return this.dateFormat(
  42. 'mm:SS',
  43. '2000/03/02 05:' + Math.floor(second / 60) + ':' + (second % 60)
  44. )
  45. },
  46. // 根据给定日期算出星期
  47. getWeek: function(date) {
  48. if (date == null) return ''
  49. if (typeof date === 'string') {
  50. date = new Date(Date.parse(date.replace(/-/g, '/').replace('.0', '')))
  51. }
  52. var week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
  53. return week[date.getDay()]
  54. },
  55. // 上传图片
  56. uploadPictures(successCallback) {
  57. let userinfo = uni.getStorageSync('userinfo')
  58. let d = new Date()
  59. let Fzitem = this.dateFormat("yyyy-MM-dd HH:mm:SS", d) //2022-08-08 14:02:59
  60. let shijian = '123456789/' + Fzitem //定义时间 + 封装时间
  61. let jmi = encryptDes(shijian, "bjtdba123")
  62. let bas = Base64.encode(jmi + "," + Fzitem)
  63. uni.chooseFile({
  64. count: 1,
  65. mediaType: ['image'],
  66. success: function (data) {
  67. console.log('---------2', data)
  68. uni.uploadFile({
  69. url: '/gateway/merchant_service/merchantSettleInService/uploadPicture',
  70. filePath: data.tempFiles[0].path,
  71. name: 'file',
  72. formData: {
  73. 'uid': userinfo.uid
  74. },
  75. header: {
  76. 'authorization': uni.getStorageSync('token'), //请求头信息
  77. 'volunteerdes': bas // DES+B64加密
  78. },
  79. success: function(res) {
  80. let filedata = res.data ? JSON.parse(res.data) : {};
  81. if (filedata.status == 200) {
  82. successCallback && successCallback(filedata.data.urlMap.url)
  83. } else {
  84. uni.showToast({
  85. title: filedata.message,
  86. icon: "none"
  87. })
  88. }
  89. },
  90. fail: function(res) {
  91. console.log('url = ',url,'res = ',res,)
  92. uni.showToast({
  93. title:res.data.message,
  94. icon: "none"
  95. })
  96. }
  97. })
  98. },
  99. fail: function (error) {
  100. console.log('---------3',error)
  101. uni.showToast({
  102. title:error.message,
  103. icon: "none"
  104. })
  105. }
  106. });
  107. // wx.chooseImage({
  108. // //count表示一次可以选择多少照片
  109. // count: 1,
  110. // //sizeType所选的图片的尺寸,original原图,compressed压缩图
  111. // sizeType: ['original', 'compressed'],
  112. // //如果sourceType为camera则调用摄像头,为album时调用相册
  113. // sourceType: [that.data.sourceType[tapIndex]],
  114. // success(res) {
  115. // console.log('---------3')
  116. // // tempFilePath可以作为img标签的src属性显示图片
  117. // const tempFilePaths = res.tempFilePaths
  118. // //将选择到的图片缓存到本地storage中
  119. // wx.setStorageSync('tempFilePaths', tempFilePaths)
  120. // /*
  121. // 由于在我们选择图片后图片只是保存到storage中,所以我们需要调用一次 setHeader()方法来使页面上的头像更新
  122. // */
  123. // that.setHeader();
  124. // wx.showToast({
  125. // title: '设置成功',
  126. // icon: 'success',
  127. // duration: 2000
  128. // })
  129. // }
  130. // })
  131. // wx.chooseMessageFile({
  132. // success: chooseImageRes => {
  133. // const tempFilePaths = chooseImageRes.tempFiles;
  134. // console.log('chooseImageRes=",chooseImageRes);
  135. // let repeatImg = this.uploadImg.find(item => {
  136. // return item.name == chooseImageRes.tempFiles[0].name;
  137. // });
  138. // console.log('tempFilePaths=',tempFilePaths[0])
  139. // if(repeatImg == undefined){
  140. // uni.uploadFile({
  141. // url:filePath: tempFilePaths[0].path,
  142. // name: 'file',
  143. // formData:{
  144. // user: "test'
  145. // },
  146. // success: uploadFileRes => {
  147. // console.log('uploadFileRes==',uploadFileRes)
  148. // console.log(JsoN.parse(uploadFileRes.data));
  149. // let temporaryImg=JSON.parse(uploadFileRes.data);
  150. // this.uploadImg.push({ name: chooseImageRes.tempFiles[0].name, url: temporaryImg.data[0].data.url });
  151. // console.log('上传====',this.uploadImg);
  152. // }
  153. // });
  154. // } else {
  155. // this.msgType = 'error';
  156. // this.message
  157. // this.open();
  158. // }
  159. // }
  160. // });
  161. },
  162. // 验证邮箱
  163. isEmailAvailable(emailInput) {
  164. var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  165. if (!myreg.test(emailInput)) {
  166. return false;
  167. } else {
  168. return true;
  169. }
  170. }
  171. }