123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- /**
- * 通用函数
- */
- var config = require('./config.js');
- var fun_aes = require('./aes.js');
- const app = getApp();
- /**
- * 格式化秒
- * @param int value 总秒数
- * @return string result 格式化后的字符串
- */
- function formatSeconds(that, value, tail = true) {
- var that = that
- var theTime = parseInt(value); // 需要转换的时间秒
- var theTime1 = 0; // 分
- var theTime2 = 0; // 小时
- var theTime3 = 0; // 天
- if (theTime === 0) {
- return parseInt(theTime) + '秒';
- return parseInt(theTime) + that.i18n['秒'];
- }
- if (theTime > 60) {
- theTime1 = parseInt(theTime / 60);
- theTime = parseInt(theTime % 60);
- if (theTime1 > 60) {
- theTime2 = parseInt(theTime1 / 60);
- theTime1 = parseInt(theTime1 % 60);
- if (theTime2 > 24) {
- //大于24小时
- theTime3 = parseInt(theTime2 / 24);
- theTime2 = parseInt(theTime2 % 24);
- }
- }
- }
- var result = '';
- if (theTime > 0) {
- // result = '' + parseInt(theTime) + '秒';
- result = '' + parseInt(theTime) + that.i18n['秒'];
- }
- if (theTime1 > 0) {
- // result = '' + parseInt(theTime1) + '分' + (tail ? result : '');
- result = '' + parseInt(theTime1) + that.i18n['分'] + (tail ? result : '');
- }
- if (theTime2 > 0) {
- // result = '' + parseInt(theTime2) + '小时' + (tail ? result : '');
- result = '' + parseInt(theTime2) + that.i18n['小时'] + (tail ? result : '');
- }
- if (theTime3 > 0) {
- // result = '' + parseInt(theTime3) + '天' + (tail ? result : '');
- result = '' + parseInt(theTime3) + that.i18n['天'] + (tail ? result : '');
- }
- return result;
- }
- function loading(that) {
- uni.showLoading({
- title: that.i18n['正在加载数据...'],
- mask: true
- });
- }
- /**
- * 成功提示
- */
- function successToast(that,title, duration) {
- uni.showToast({
- title: title || that.i18n['成功'],
- icon: 'success',
- duration: duration || 1500,
- mask: true
- });
- }
- /**
- * 简单提示
- */
- function simpleToast(that,title, duration) {
- uni.showToast({
- title: title || that.i18n['成功'],
- icon: 'none',
- duration: duration || 1500
- });
- }
- /**
- * 选择并上传图片
- */
- function uploadImg(that,callback) {
- uni.chooseImage({
- count: 1,
- success: function (res) {
- var tempFilePaths = res.tempFilePaths;
- uni.uploadFile({
- url: config.API_UP_IMG_URL,
- filePath: tempFilePaths[0],
- name: 'imgFile',
- success: function (res1) {
- var rtDataObj = JSON.parse(res1.data);
- if (rtDataObj.code == 200) {
- callback(rtDataObj.data[0].url);
- } else {
- uni.showModal({
- title: that.i18n['错误'],
- content: that.i18n['上传失败']+'[' + rtDataObj.message + ']'
- });
- }
- }
- });
- }
- });
- }
- /**
- * 选择并上传图片 七牛存储
- */
- function upLoadImgQiNiu(that,callback) {
- const http = require('./http.js');
- uni.chooseImage({
- count: 1,
- success: function (res) {
- const tempFilePaths = res.tempFilePaths;
- loading();
- http.getApi(config.API_QINIU_UP_IMG_TOKEN, {}, function (response) {
- if (response.data.code === 200) {
- const token = response.data.data.token;
- uni.uploadFile({
- url: config.QINIU_UPLOAD_SITE,
- filePath: tempFilePaths[0],
- name: 'file',
- formData: {
- token: token
- },
- success: function (res1) {
- uni.hideLoading();
- var rtDataObj = JSON.parse(res1.data);
- const key = rtDataObj.key;
- callback(config.QINIU_SITE + key);
- },
- fail: function (res) {
- simpleToast(that.i18n['上传失败']);
- uni.hideLoading();
- }
- });
- } else {
- simpleToast(response.data.msg);
- uni.hideLoading();
- }
- });
- }
- });
- }
- module.exports = {
- formatSeconds: formatSeconds,
- loading: loading,
- successToast: successToast,
- simpleToast: simpleToast,
- uploadImg: uploadImg,
- upLoadImgQiNiu: upLoadImgQiNiu
- };
|