Files
PC-202306242200\Administrator 1c24452b6c first commit
2026-03-28 23:10:55 +08:00

98 lines
2.7 KiB
JavaScript

"use strict";
const common_vendor = require("../common/vendor.js");
const api_http = require("../api/http.js");
const toast = (title, icon = "none") => {
common_vendor.index.showToast({
title,
icon
});
};
const copy = (e) => common_vendor.index.setClipboardData({
data: e,
success: function() {
common_vendor.index.__f__("log", "at utils/fun.js:29", "success");
}
});
const timeFormat = (time, fmt = "yyyy-MM-dd hh:mm:ss", targetTimezone = 8) => {
try {
if (!time) {
return "";
}
if (typeof time === "string" && !isNaN(time))
time = Number(time);
let date;
if (typeof time === "number") {
if (time.toString().length == 10)
time *= 1e3;
date = new Date(time);
} else {
date = time;
}
const dif = date.getTimezoneOffset();
const timeDif = dif * 60 * 1e3 + targetTimezone * 60 * 60 * 1e3;
const east8time = date.getTime() + timeDif;
date = new Date(east8time);
let opt = {
"M+": date.getMonth() + 1,
//月份
"d+": date.getDate(),
//日
"h+": date.getHours(),
//小时
"m+": date.getMinutes(),
//分
"s+": date.getSeconds(),
//秒
"q+": Math.floor((date.getMonth() + 3) / 3),
//季度
S: date.getMilliseconds()
//毫秒
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (let k in opt) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? opt[k] : ("00" + opt[k]).substr(("" + opt[k]).length));
}
}
return fmt;
} catch (err) {
return time;
}
};
const uploadFiles = (urls) => {
common_vendor.index.__f__("log", "at utils/fun.js:96", urls);
return new Promise(async (resolve, reject) => {
common_vendor.index.uploadFile({
url: `${api_http.proxyObj["development"]}/app-api/infra/file/upload`,
// 上传接口地址
filePath: urls,
//必须通过 uni.chooseImage、uni.chooseMessageFile 等接口获取临时路径,不可直接使用静态路径
name: "file",
// 文件对应的 key
formData: {},
header: {
"Tenant-id": "134"
},
success: (uploadRes) => {
common_vendor.index.__f__("log", "at utils/fun.js:107", uploadRes);
const data = JSON.parse(uploadRes.data);
if (data.code == 0) {
resolve(data.data);
} else {
reject(data.msg);
}
},
fail: (err) => {
reject(err);
}
});
});
};
exports.copy = copy;
exports.timeFormat = timeFormat;
exports.toast = toast;
exports.uploadFiles = uploadFiles;
//# sourceMappingURL=../../.sourcemap/mp-weixin/utils/fun.js.map