| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- // this.$time.dateFormat('yyyy-MM-dd',new Date())
- // 格式 时间
- import {
- encryptDes,
- decryptDes
- } from '@/encryption/index.js' // 引用路径根据自己的文件结构而定
- import
- Base64
- from 'base-64'
- export default {
- // 时间格式化
- dateFormat: function(fmt, date) {
- if (date == null) return ''
- if (typeof date === 'string') {
- date = new Date(Date.parse(date.replace(/-/g, '/').replace('.0', '')))
- } else {
- date = new Date(date)
- }
- let ret
- const opt = {
- 'y+': date.getFullYear().toString(), // 年
- 'M+': (date.getMonth() + 1).toString(), // 月
- 'd+': date.getDate().toString(), // 日
- 'H+': date.getHours().toString(), // 时
- 'm+': date.getMinutes().toString(), // 分
- 'S+': date.getSeconds().toString() // 秒
- // 有其他格式化字符需求可以继续添加,必须转化成字符串
- }
- for (const k in opt) {
- ret = new RegExp('(' + k + ')').exec(fmt)
- // opt = opt.replace('-','/')
- if (ret) {
- fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, '0')))
- }
- }
- return fmt
- },
- // 秒数转换分钟秒
- minuteSecond: function(second) {
- var second = Math.floor(second)
- return this.dateFormat(
- 'mm:SS',
- '2000/03/02 05:' + Math.floor(second / 60) + ':' + (second % 60)
- )
- },
- // 根据给定日期算出星期
- getWeek: function(date) {
- if (date == null) return ''
- if (typeof date === 'string') {
- date = new Date(Date.parse(date.replace(/-/g, '/').replace('.0', '')))
- }
- var week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
- return week[date.getDay()]
- },
- // 上传图片
- uploadPictures(successCallback) {
- let userinfo = uni.getStorageSync('userinfo')
- let d = new Date()
- let Fzitem = this.dateFormat("yyyy-MM-dd HH:mm:SS", d) //2022-08-08 14:02:59
- let shijian = '123456789/' + Fzitem //定义时间 + 封装时间
- let jmi = encryptDes(shijian, "bjtdba123")
- let bas = Base64.encode(jmi + "," + Fzitem)
-
- uni.chooseFile({
- count: 1,
- mediaType: ['image'],
- success: function (data) {
- console.log('---------2', data)
- uni.uploadFile({
- url: '/gateway/merchant_service/merchantSettleInService/uploadPicture',
- filePath: data.tempFiles[0].path,
- name: 'file',
- formData: {
- 'uid': userinfo.uid
- },
- header: {
- 'authorization': uni.getStorageSync('token'), //请求头信息
- 'volunteerdes': bas // DES+B64加密
- },
- success: function(res) {
- let filedata = res.data ? JSON.parse(res.data) : {};
- if (filedata.status == 200) {
- successCallback && successCallback(filedata.data.urlMap.url)
- } else {
- uni.showToast({
- title: filedata.message,
- icon: "none"
- })
- }
- },
- fail: function(res) {
- console.log('url = ',url,'res = ',res,)
- uni.showToast({
- title:res.data.message,
- icon: "none"
- })
- }
- })
- },
- fail: function (error) {
- console.log('---------3',error)
- uni.showToast({
- title:error.message,
- icon: "none"
- })
- }
- });
-
-
- // wx.chooseImage({
-
- // //count表示一次可以选择多少照片
- // count: 1,
- // //sizeType所选的图片的尺寸,original原图,compressed压缩图
- // sizeType: ['original', 'compressed'],
- // //如果sourceType为camera则调用摄像头,为album时调用相册
- // sourceType: [that.data.sourceType[tapIndex]],
- // success(res) {
- // console.log('---------3')
- // // tempFilePath可以作为img标签的src属性显示图片
- // const tempFilePaths = res.tempFilePaths
- // //将选择到的图片缓存到本地storage中
- // wx.setStorageSync('tempFilePaths', tempFilePaths)
- // /*
- // 由于在我们选择图片后图片只是保存到storage中,所以我们需要调用一次 setHeader()方法来使页面上的头像更新
- // */
- // that.setHeader();
- // wx.showToast({
- // title: '设置成功',
- // icon: 'success',
- // duration: 2000
- // })
- // }
- // })
-
- // wx.chooseMessageFile({
- // success: chooseImageRes => {
- // const tempFilePaths = chooseImageRes.tempFiles;
- // console.log('chooseImageRes=",chooseImageRes);
- // let repeatImg = this.uploadImg.find(item => {
- // return item.name == chooseImageRes.tempFiles[0].name;
- // });
- // console.log('tempFilePaths=',tempFilePaths[0])
- // if(repeatImg == undefined){
- // uni.uploadFile({
- // url:filePath: tempFilePaths[0].path,
- // name: 'file',
- // formData:{
- // user: "test'
- // },
- // success: uploadFileRes => {
- // console.log('uploadFileRes==',uploadFileRes)
- // console.log(JsoN.parse(uploadFileRes.data));
- // let temporaryImg=JSON.parse(uploadFileRes.data);
- // this.uploadImg.push({ name: chooseImageRes.tempFiles[0].name, url: temporaryImg.data[0].data.url });
- // console.log('上传====',this.uploadImg);
- // }
- // });
-
- // } else {
- // this.msgType = 'error';
- // this.message
- // this.open();
- // }
- // }
- // });
-
- },
-
- // 验证邮箱
- isEmailAvailable(emailInput) {
- var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
- if (!myreg.test(emailInput)) {
- return false;
- } else {
- return true;
- }
- }
- }
|