123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- const baseUrl = "https://ndzx.hqedust.com/"
- const ossUrl = "https://sm-sign.oss-cn-shanghai.aliyuncs.com/cert/"
- const md5 = require('./md5.js');
- const formatTime = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
- return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
- }
- const formatDate = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- return [year, month, day].map(formatNumber).join('-')
- }
- const object2Date = ({year, month, date}) => {
- return [year, month, date].map(formatNumber).join('-')
- }
- const sec2Date = sec => {
- let date = new Date( sec * 1000 );
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- return [year, month, day].map(formatNumber).join('-')
- }
- const nextDate = datestr => {
- let date = new Date( datestr );
- date = new Date(+date + 86400*1000)
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- return [year, month, day].map(formatNumber).join('-')
- }
- const formatNumber = n => {
- n = n.toString()
- return n[1] ? n : '0' + n
- }
- const formatSeconds = theTime => {
- let theTime1 = 0
- let theTime2 = 0
- if (theTime > 60) {
- theTime1 = parseInt(theTime / 60)
- theTime = parseInt(theTime % 60)
- if (theTime1 > 60) {
- theTime2 = parseInt(theTime1 / 60)
- theTime1 = parseInt(theTime1 % 60)
- }
- }
- let result = '' + parseInt(theTime) + '秒'
- if (theTime1 > 0) {
- result = '' + parseInt(theTime1) + '分' + result
- }
- if (theTime2 > 0) {
- result = '' + parseInt(theTime2) + '小时' + result
- }
- return result
- }
- const getMultResult = select=>{
- let prevList = ["", "A","B","C", "D", "E","F"]
- let slist = ''+select
- let res = ""
- for( let i in slist){
- res+=prevList[slist[i]]
- console.log(slist[i], prevList[slist[i]] )
- }
- return res
- }
- var uploadFile = (tempFilePaths, fun) =>{
- let header={}
- let murl = `${baseUrl}upload`
- let version= "1.0"
- let mtime = parseInt(Date.now() / 1000);
- // 未登入
- let signstr = "hall_" + version + mtime;
- let sign = md5.md5(signstr).toLowerCase()
- wx.uploadFile({
- url: `${murl}?t=${mtime}&v=1&s=${sign}&u=0`,
- filePath: tempFilePaths,
- name: "avatar",
- header:header,
- success: function (res) {
- if( res.statusCode === 200){
- let { code, data, msg} = JSON.parse(res.data)
- if( code == 200 ){
- fun&&fun(code, data)
- }else{
- fun&&fun(code, msg)
- }
- }else{
- fun&&fun(404, "请求异常")
- }
- },
- fail: function (res) {
- fun&&fun(404, "" );
- }
- })
- }
- // 显示繁忙提示
- var showBusy = text => wx.showToast({
- title: text,
- icon: 'loading',
- duration: 2000
- })
- // 显示成功提示
- var showSuccess = text => wx.showToast({
- title: text,
- icon: 'success'
- })
- var showMsg = text => wx.showToast({
- title: text,
- image: '/assets/img_close.png',
- duration: 1000,
- mask: true
- })
- var showToast = (errCode, okText, text) => {
- if( errCode ==200 ){
- showSuccess( okText );
- }else{
- showMsg( text )
- }
- }
- // 显示失败提示
- var showModel = (title, content) => {
- wx.hideToast();
- wx.showModal({
- title,
- content: JSON.stringify(content),
- showCancel: false
- })
- }
- var downloadFile = ( imgSrc, cb )=>{
- var save = wx.getFileSystemManager();
- var number = Date.now()
- save.writeFile({
- filePath: wx.env.USER_DATA_PATH + '/pic_' + number + '.png',
- data: imgSrc,
- encoding: 'base64',
- success: res => {
- wx.saveImageToPhotosAlbum({
- filePath: wx.env.USER_DATA_PATH + '/pic_' + number + '.png',
- success: function (res) {
- wx.showToast({
- title: '保存成功',
- })
- cb &&cb( true );
- },
- fail: function (err) {
- cb &&cb( false );
- }
- })
- }, fail: err => {
- cb &&cb( false );
- }
- })
- }
-
- module.exports = {
- baseUrl,
- ossUrl,
- downloadFile,
- formatSeconds: formatSeconds,
- formatTime: formatTime,
- getMultResult,
- uploadFile,
- showModel,
- showSuccess,
- showToast,
- showMsg,
- sec2Date,
- nextDate,
- formatDate,
- object2Date,
- showBusy
- }
|