123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- /**
- * 显示消息提示框
- * @param content 提示的标题
- */
- export function toast(content) {
- uni.showToast({
- icon: 'none',
- title: content
- })
- }
- /**
- * 显示模态弹窗
- * @param content 提示的标题
- */
- export function showConfirm(content) {
- return new Promise((resolve, reject) => {
- uni.showModal({
- title: '提示',
- content: content,
- cancelText: '取消',
- confirmText: '确定',
- success: function(res) {
- resolve(res)
- }
- })
- })
- }
- /**
- * 参数处理
- * @param params 参数
- */
- export function tansParams(params) {
- let result = ''
- for (const propName of Object.keys(params)) {
- const value = params[propName]
- var part = encodeURIComponent(propName) + "="
- if (value !== null && value !== "" && typeof(value) !== "undefined") {
- if (typeof value === 'object') {
- for (const key of Object.keys(value)) {
- if (value[key] !== null && value[key] !== "" && typeof(value[key]) !== 'undefined') {
- let params = propName + '[' + key + ']'
- var subPart = encodeURIComponent(params) + "="
- result += subPart + encodeURIComponent(value[key]) + "&"
- }
- }
- } else {
- result += part + encodeURIComponent(value) + "&"
- }
- }
- }
- return result
- }
- /**
- * 时间戳转日期
- * @param {Object} timestamp 时间戳
- */
- export function timestampToTime(timestamp) {
- var date = new Date(timestamp); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
- var Y = date.getFullYear() + '-';
- var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
- var D = date.getDate() + ' ';
- var h = date.getHours() + ':';
- var m = date.getMinutes() + ':';
- var s = date.getSeconds();
- return Y + M + D + h + m + s;
- }
- var duration = 300;
- var timer = null;
- /**
- * 函数防抖
- * @param {Object} fn 目标函数
- * @param {Object} duration 间隔时间
- */
- export function debounce(fn, duration = duration) {
- if (timer) {
- clearTimeout(timer);
- }
- timer = setTimeout(function() {
- fn();
- }, duration)
- }
- /**
- * 时间戳转 时分秒(判断工时)
- * @param {Object} data 时间戳
- * @param {Object} flag 是否返回 HH:mm:ss 格式
- */
- // listData.value[i].taskTime = (timeStamp / 3600000).toFixed(2) === 'NaN' ? 0 : (timeStamp / 3600000)
- // .toFixed(2);
- export function toHHmmss(data, flag = true) {
- var time;
- var hours = Math.floor(data / (1000 * 60 * 60));
- var minutes = Math.floor((data % (1000 * 60 * 60)) / (1000 * 60));
- var seconds = (data % (1000 * 60)) / 1000;
- if (flag) {
- time = `${hours}小时${minutes}分钟${seconds}秒`;
- } else {
- time = (hours < 10 ? ('0' + hours) : hours) + ':' + (minutes < 10 ? ('0' + minutes) : minutes) + ':' + (
- seconds <
- 10 ? ('0' + seconds) : seconds);
- }
- return time;
- }
- export function getDate(date) {
- let year = date.getFullYear();
- let month = date.getMonth() + 1;
- let day = date.getDate();
- return `${year}-${month}-${day}`;
- }
|