feat: 添加组件配置文件并优化页面结构
- 新增 components.d.json 文件,包含所有组件的属性配置 - 添加 card-item-plugin 组件及其相关文件(json、ts、wxml、wxss) - 在 app.json 中添加新的生产流程管理页面路径 - 添加多个SVG图标文件用于菜单项 - 重构 popup-plugin 组件样式和关闭逻辑 - 更新 tab-bar-plugin 的激活状态逻辑 - 优化 search-popup 使用全局样式类 - 在首页添加菜单配置和页面跳转功能 - 调整组件样式细节和间距
This commit is contained in:
@@ -8,7 +8,13 @@ export const formatTime = (date: Date) => {
|
||||
const minute = date.getMinutes();
|
||||
const second = date.getSeconds();
|
||||
|
||||
return `${[year, month, day].map(formatNumber).join("-")} ${[hour, minute, second].map(formatNumber).join(":")}`;
|
||||
return `${[year, month, day].map(formatNumber).join("-")} ${[
|
||||
hour,
|
||||
minute,
|
||||
second,
|
||||
]
|
||||
.map(formatNumber)
|
||||
.join(":")}`;
|
||||
};
|
||||
|
||||
export const formatNumber = (n: number | string) => {
|
||||
@@ -16,24 +22,12 @@ export const formatNumber = (n: number | string) => {
|
||||
return n[1] ? n : `0${n}`;
|
||||
};
|
||||
|
||||
export const ToastOK = (title: string, duration = 2000) => {
|
||||
wx.showToast({
|
||||
title,
|
||||
icon: "success",
|
||||
duration,
|
||||
});
|
||||
};
|
||||
|
||||
export const ToastErr = (title: string, duration = 2000) => {
|
||||
wx.showToast({
|
||||
title,
|
||||
icon: "error",
|
||||
duration,
|
||||
});
|
||||
};
|
||||
|
||||
// 对话框
|
||||
export const showModal = (title: string, content: string, showCancel = false) => {
|
||||
export const showModal = (
|
||||
title: string,
|
||||
content: string,
|
||||
showCancel = false
|
||||
) => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
wx.showModal({
|
||||
title,
|
||||
@@ -51,36 +45,28 @@ export const showModal = (title: string, content: string, showCancel = false) =>
|
||||
};
|
||||
|
||||
/** 判断数据是不是数组类型 */
|
||||
export const isArray = (data: any) => {
|
||||
return data && Array.isArray(data);
|
||||
};
|
||||
export const isArray = (data: any) => data && Array.isArray(data);
|
||||
|
||||
/**
|
||||
* 转成数组
|
||||
* @param {*} data
|
||||
* @returns {Array}
|
||||
*/
|
||||
export const toArray = (data: any): any[] => {
|
||||
return isArray(data) ? data : [];
|
||||
};
|
||||
export const toArray = (data: any): any[] => (isArray(data) ? data : []);
|
||||
|
||||
/** 判断数据是不是对象类型 */
|
||||
export const isObject = (data: any) => {
|
||||
return data && `${Object.prototype.toString.call(data)}`.includes("Object");
|
||||
};
|
||||
|
||||
export const toObject = (data: any) => {
|
||||
return isObject(data) ? data : {};
|
||||
};
|
||||
export const toObject = (data: any) => (isObject(data) ? data : {});
|
||||
|
||||
export const reloadPage = () => {
|
||||
let pages = getCurrentPages(); //获取加载的页面
|
||||
let currentPage = pages[pages.length - 1]; //获取当前页面的对象
|
||||
let url = currentPage.route; //当前页面url
|
||||
// 关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。
|
||||
wx.redirectTo({
|
||||
url: "/" + url,
|
||||
});
|
||||
wx.redirectTo({ url: "/" + url });
|
||||
};
|
||||
|
||||
/** 判断是json数据 */
|
||||
@@ -106,13 +92,21 @@ export const jsonParse = (data: any): any[] | object | null => {
|
||||
if (typeof data == "string") {
|
||||
try {
|
||||
const obj = JSON.parse(data);
|
||||
if (["Array", "Object"].includes(Object.prototype.toString.call(obj).slice(8, -1))) {
|
||||
if (
|
||||
["Array", "Object"].includes(
|
||||
Object.prototype.toString.call(obj).slice(8, -1)
|
||||
)
|
||||
) {
|
||||
return obj;
|
||||
}
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
} else if (["Array", "Object"].includes(Object.prototype.toString.call(data).slice(8, -1))) {
|
||||
} else if (
|
||||
["Array", "Object"].includes(
|
||||
Object.prototype.toString.call(data).slice(8, -1)
|
||||
)
|
||||
) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -148,14 +142,10 @@ export const formatToDecimals = (str: any, num: number = 2) => {
|
||||
};
|
||||
|
||||
/** 获取权限 */
|
||||
export const getAuthInfo = () => {
|
||||
return toObject(wx.getStorageSync("auth_info"));
|
||||
};
|
||||
export const getAuthInfo = () => toObject(wx.getStorageSync("auth_info"));
|
||||
|
||||
export const goIndexPage = () => {
|
||||
wx.switchTab({
|
||||
url: "/pages/index/index",
|
||||
});
|
||||
wx.navigateTo({ url: "/pages/index/index" });
|
||||
};
|
||||
|
||||
export const isImageFile = (path: string) => {
|
||||
@@ -186,41 +176,37 @@ export const tabsConfigGet = () => {
|
||||
*/
|
||||
export const mediaPreview = (imageUrls: any[], currentUrl: string) => {
|
||||
console.log("媒体图片预览方法");
|
||||
const lastLen = `${currentUrl}`.indexOf("?") > -1 ? `${currentUrl}`.indexOf("?") : `${currentUrl}`.length;
|
||||
const lastLen =
|
||||
`${currentUrl}`.indexOf("?") > -1
|
||||
? `${currentUrl}`.indexOf("?")
|
||||
: `${currentUrl}`.length;
|
||||
|
||||
const suffix: any = currentUrl.substring(currentUrl.lastIndexOf(".") + 1, lastLen).toLocaleLowerCase();
|
||||
const suffix: any = currentUrl
|
||||
.substring(currentUrl.lastIndexOf(".") + 1, lastLen)
|
||||
.toLocaleLowerCase();
|
||||
|
||||
if (isImageFile("." + suffix)) {
|
||||
wx.previewImage({
|
||||
urls: imageUrls,
|
||||
current: currentUrl,
|
||||
showmenu: true,
|
||||
});
|
||||
wx.previewImage({ urls: imageUrls, current: currentUrl, showmenu: true });
|
||||
} else if (["mp3", "mp4", "m4a"].includes(suffix)) {
|
||||
wx.previewMedia({
|
||||
sources: [
|
||||
{
|
||||
url: currentUrl,
|
||||
type: "video",
|
||||
},
|
||||
],
|
||||
sources: [{ url: currentUrl, type: "video" }],
|
||||
fail() {
|
||||
wx.showToast({
|
||||
title: "播放失败",
|
||||
});
|
||||
wx.showToast({ title: "播放失败" });
|
||||
},
|
||||
});
|
||||
} else if (["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"].includes(suffix)) {
|
||||
} else if (
|
||||
["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"].includes(suffix)
|
||||
) {
|
||||
const downloadTask = wx.downloadFile({
|
||||
url: currentUrl,
|
||||
header: http.header,
|
||||
success: function (res) {
|
||||
success: (res) => {
|
||||
const filePath = res.tempFilePath;
|
||||
wx.openDocument({
|
||||
filePath: filePath,
|
||||
showMenu: true,
|
||||
fileType: suffix,
|
||||
success: function () {},
|
||||
success: () => {},
|
||||
});
|
||||
},
|
||||
fail() {},
|
||||
@@ -237,9 +223,7 @@ export const mediaPreview = (imageUrls: any[], currentUrl: string) => {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: "请前往网页端下载查看",
|
||||
});
|
||||
wx.showToast({ title: "请前往网页端下载查看" });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -252,9 +236,7 @@ export const uploadFile2 = (option: any) => {
|
||||
option = toObject(option);
|
||||
option.name = option.name || "files";
|
||||
|
||||
wx.showLoading({
|
||||
title: "文件上传中...",
|
||||
});
|
||||
wx.showLoading({ title: "文件上传中..." });
|
||||
wx.uploadFile({
|
||||
filePath: option.filePath,
|
||||
name: option.name,
|
||||
@@ -266,17 +248,13 @@ export const uploadFile2 = (option: any) => {
|
||||
url: option.url,
|
||||
success(res) {
|
||||
const resData = jsonParse(res.data);
|
||||
wx.showToast({
|
||||
title: "上传成功",
|
||||
});
|
||||
wx.showToast({ title: "上传成功" });
|
||||
if (option.success) {
|
||||
option.success(resData);
|
||||
}
|
||||
},
|
||||
fail() {
|
||||
wx.showToast({
|
||||
title: "上传失败",
|
||||
});
|
||||
wx.showToast({ title: "上传失败" });
|
||||
if (option.fail) {
|
||||
option.fail();
|
||||
}
|
||||
@@ -345,3 +323,4 @@ export const getCurrentPageRoute = () => {
|
||||
const currentPage = pages[pages.length - 1]; // 获取当前页面对象
|
||||
return `/${currentPage.route}`; // 获取当前页面路径
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user