初始化项目, 添加TDesign等包

This commit is contained in:
zhengw
2025-11-28 16:49:36 +08:00
commit 3e53beb7bb
980 changed files with 39201 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
/**
* Global Config Files
* Added By YangXB 2021.11.24
*/
export const servicePhone = "4000-5858-22";
export const defaultAvatarUrl =
"https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0";
export const base = {
appletName: "易宝赞数据化管理系统",
apiHost:
wx.getAccountInfoSync().miniProgram.envVersion == "release"
? "https://ebaozan.com/api/"
: "http://192.168.1.138:83/",
webViewBaseUrl:
wx.getAccountInfoSync().miniProgram.envVersion == "release" ? "https://ebaozan.com/" : "http://ebaozan.cf/",
cookieKey: "OwCookie",
};
// 头文件
export const http = {
header: {
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
},
unLoginCode: 110000,
};

273
miniprogram/utils/https.js Normal file
View File

@@ -0,0 +1,273 @@
/**
* 全局http工具集
* YangXB 2021.11.24
* */
import { base, http } from "./config";
import { getStorage, isArray, setStorage, ToastErr } from "./util";
/**
* 请求
* @param {*} url
* @param {*} options
* @param {*} config
*/
const request = (url, options, config = { showLoading: true, showError: true }) => {
// 获取缓存cookie
const header = { ...http.header };
const cookie = getStorage(base.cookieKey);
if (cookie && !header["Cookie"]) {
header["Cookie"] = cookie;
}
if (options["content-type"]) {
header["content-type"] = options["content-type"];
}
return new Promise((resolve, reject) => {
if (config.showLoading != false) {
wx.showLoading({ title: "加载中" });
}
url = `${url}`.startsWith("http") ? url : urlAddBaseUrl(url);
wx.request({
url: url,
method: options.method,
data: options.data,
header,
success(request) {
if (config.showLoading != false) {
wx.hideLoading();
}
// 写入缓存
if (!cookie) {
setStorage(base.cookieKey, request.header["Set-Cookie"]);
}
if (request.data.err_code === 0) {
//
} else {
if (config.showError != false) {
wx.showToast({
title: request.data.err_msg,
icon: "none",
});
}
if (request.data.err_code == 110000) {
const pages = getCurrentPages();
if (
!["pages/index/index", "pages/processEntry/processEntry", "pages/my/my"].includes(
pages[pages.length - 1].route
)
) {
wx.switchTab({ url: "/pages/index/index" });
}
}
}
resolve(request.data);
},
fail(error) {
if (config.showLoading != false) {
wx.hideLoading();
}
reject({ err_code: 44444, err_msg: error.data });
},
});
});
};
// 封装get方法
export const get = (url, data = {}, config) => {
return request(url, { method: "GET", data }, config);
};
// 封装post方法
export const post = (url, data = {}, config) => {
return request(url, { method: "POST", data }, config);
};
export const wxLogin = (config) => {
wx.login({
success: (res) => {
post("Applet/code2Sess", { code: res.code, name: "ch" }, config)
.then((res) => {
// 记录sessionKey
setStorage("session", {
openid: res.openid,
unionid: res.unionid,
time: Date.now() + 1000 * 3600 * 24, // 缓存一天过期
});
})
.catch((err) => {
ToastErr("服务失败:" + err.err_code);
});
},
});
};
// 检验微信前端登录状态
export const checkSession = () => {
wx.checkSession({
// 没有过期
success: () => {
// const session = wx.getStorageSync("session");
// console.log("checkSession生效", session);
// // 没有缓存,或者缓存已过期
// if (!session) {
// console.log("session缓存已不存在");
// wxLogin();
// } else {
// const time = session.time || 0;
// if (Date.now() > time) {
// console.log("session缓存已过期");
// wxLogin();
// }
// }
},
fail: () => {
console.log("checkSession失效");
// 已过期重新登录获取session_key
wxLogin();
},
});
};
export const loginStatus = () => {
return new Promise((resolve, reject) => {
post("Applet/loginStatus", {}, { showLoading: false })
.then((res) => {
setStorage("user_info", res.user_info);
setStorage("company_info", res.company_info);
setStorage("auth_info", res.auth_info);
setStorage("session_id", res.session_id);
resolve(res);
})
.catch((err) => {
login("", "", 4)
.then((res) => {
if (isArray(res.data)) {
post("Applet/loginOut").then((res) => {
checkSesskey({ showLoading: false, showError: false })
.then((res) => {})
.catch((err) => {
console.log("checkSesskey", err);
});
});
reject(res);
} else {
resolve(res);
}
})
.catch(() => {
reject(err);
});
});
});
};
/**
*
* @param {*} config { showLoading: true, showError: true }
*/
export const checkSesskey = (config) => {
return new Promise((resolve, reject) => {
post("Applet/checkSesskey", {}, config)
.then((res) => {
resolve(res);
})
.catch((err) => {
wxLogin(config);
reject(err);
});
});
};
// 后端登录
export const login = (encryptedData, iv, type, company_id) => {
return new Promise((resolve, reject) => {
const data = {
type: 2,
encryptedData,
iv,
};
if (company_id) {
data.companyID = company_id;
}
post("Applet/login", type == 4 ? { type } : data)
.then((res) => {
if (isArray(res.data)) {
resolve(res);
} else {
setStorage("user_info", res.user_info);
setStorage("company_info", res.companys_info);
setStorage("auth_info", res.auth_info);
loginStatus();
resolve(res);
}
})
.catch((err) => {
// 签名失败,重新登录
// if (err.err_code == 41444) {
// wxLogin();
// showModal("登录结果", "服务器开小差了,请重试");
// } else {
// showModal("登录结果", err.err_msg);
// }
// wx.removeStorageSync("loginExp");
if (type == 4) {
checkSesskey()
.then(() => {
resolve(res);
})
.catch(() => {
reject(err);
});
} else {
reject(err);
}
});
});
};
export const makeURL = (url, redirect = false, openID = false) => {
return (
base.apiHost +
(redirect ? "applet-wv?url=" : "") +
encodeURIComponent(url + (openID ? "?openID=" + wx.getStorageSync("session")["openid"] : "")) +
(redirect ? "&" : "?") +
"cookie=" +
encodeURI(wx.getStorageSync(base.cookieKey))
);
};
export const urlAddBaseUrl = (url) => {
if (typeof url == "string") {
if (url.startsWith("/")) {
url = url.substring(1);
}
}
return base.apiHost + url;
};
export const urlAddWebViewBaseUrl = (url) => {
if (typeof url == "string") {
if (url.startsWith("/")) {
url = url.substring(1);
}
}
return base.webViewBaseUrl + url;
};
/** formData请求 */
export const formDataRequest = (url, formData, config) => {
let data = formData.getData();
return request(
url,
{
method: "POST",
data: data.buffer,
"content-type": data.contentType,
},
config
);
};

View File

@@ -0,0 +1,54 @@
/** 首页菜单 */
const iconColor = "#0052D9";
export const menuConfig = [
{
title: "订单管理",
icon: "form",
iconColor: iconColor,
children: [
{ title: "订单列表", url: "/pages/orders/ordersList/ordersList", auth: "SF_VIEW_ORDERS" },
{ title: "流程管理", url: "/pages/orders/processManage/processManage", auth: "SF_VIEW_ORDER_PROCESS_MANAGE" },
{ title: "录入流程", url: "/pages/processEntry/processEntry", auth: "SF_ENTER_PROCESS" },
{ title: "工量查询", url: "/pages/orders/workload/workload", auth: "SF_VIEW_WORK_LIST" },
{ title: "订单备忘", url: "/pages/orders/orderMemo/orderMemo", auth: "SF_VIEW_ORDER_MEMO" },
{ title: "订单排序", url: "/pages/orders/ordersSort/ordersSort", auth: "SF_SET_ORDER_SORT" },
{ title: "板号查询", url: "/pages/orders/sale_no_query/sale_no_query", auth: "SF_VIEW_ORDER_SALE_NO_PROCESS" },
],
},
{
title: "客户管理",
icon: "user-vip",
iconColor: iconColor,
children: [
{ title: "供应商管理", url: "/pages/crm_manage/suppliers/suppliers", auth: "SF_VIEW_CRM_SUPPLIER" },
{ title: "经销商管理", url: "/pages/crm_manage/sales/sales", auth: "SF_VIEW_CRM_SALE" },
{ title: "经销商等级", url: "/pages/crm_manage/crm_level/crm_level", auth: "SF_VIEW_CRM_LEVEL" },
],
},
];
const iconPath = "/images/nav_icons/";
/** 导航栏 */
export const navTabBar = [
{
iconPath: `${iconPath}home.svg`,
selectedIconPath: `${iconPath}home2.svg`,
pagePath: "/pages/index/index",
text: "首页",
key: "1",
},
{
iconPath: `${iconPath}code.svg`,
selectedIconPath: `${iconPath}code2.svg`,
pagePath: "/pages/processEntry/processEntry",
text: "扫码",
key: "2",
},
{
iconPath: `${iconPath}my.svg`,
selectedIconPath: `${iconPath}my2.svg`,
pagePath: "/pages/my/my",
text: "我的",
key: "3",
},
];

View File

@@ -0,0 +1,72 @@
// 存储一个事件回调数组
const listeners: { [key: string]: any[] } = {};
// 触发事件的函数
function triggerEvent(key: string, data: any) {
if (listeners[key]) {
listeners[key].forEach((callback: any) => {
callback(data);
});
}
// 也可以触发一个通用的 'change' 事件
if (listeners["change"]) {
listeners["change"].forEach((callback: any) => {
callback({ key, data });
});
}
}
type IFun = Function & { $$functionKey?: string };
export const Subscribe = {
/**
* 设置
* @param key 订阅变量的key
* @param value 值
*/
set(key: string, value: any) {
// 1. 执行原有的存储操作
// setStorage(key, value);
// 2. 触发自定义事件,通知订阅者
triggerEvent(key, value);
},
// get(key: string) {
// return getStorage(key);
// },
remove(key: string) {
triggerEvent(key, null); // 或者触发一个 'remove' 事件
},
/**
* 订阅事件
* @param key 订阅变量的key
* @param functionKey 唯一的函数key(用于取消订阅的)
* @param callback 回调函数
*/
on(key: string, functionKey: string, callback: () => void) {
if (!listeners[key]) {
listeners[key] = [];
}
if (typeof callback == "function") {
(callback as IFun)["$$functionKey"] = functionKey;
listeners[key].push(callback);
} else {
console.log("订阅事件 callback 必须是函数");
}
},
/**
* 取消订阅
* @param key 订阅变量的key
* @param functionKey 唯一的函数key(用于取消订阅的)
*/
off(key: string, functionKey: string) {
if (!listeners[key]) return;
listeners[key] = listeners[key].filter((cb: IFun) => cb.$$functionKey != functionKey);
if (listeners[key].length == 0) {
delete listeners[key];
}
},
};

347
miniprogram/utils/util.ts Normal file
View File

@@ -0,0 +1,347 @@
import { http } from "./config";
export const formatTime = (date: 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(":")}`;
};
export const formatNumber = (n: number | string) => {
n = n.toString();
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) => {
return new Promise<void>((resolve, reject) => {
wx.showModal({
title,
content,
showCancel,
success(res) {
if (res.confirm) {
resolve();
} else if (res.cancel) {
reject();
}
},
});
});
};
/** 判断数据是不是数组类型 */
export const isArray = (data: any) => {
return data && Array.isArray(data);
};
/**
* 转成数组
* @param {*} data
* @returns {Array}
*/
export const toArray = (data: any): any[] => {
return 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 reloadPage = () => {
let pages = getCurrentPages(); //获取加载的页面
let currentPage = pages[pages.length - 1]; //获取当前页面的对象
let url = currentPage.route; //当前页面url
// 关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。
wx.redirectTo({
url: "/" + url,
});
};
/** 判断是json数据 */
export const isJson = (str: any) => {
if (str && typeof str == "string") {
try {
const obj = JSON.parse(str);
return obj && typeof obj == "object";
} catch (_e) {
//
}
}
return false;
};
/**
* 解码json数据
* @param data 数据
* @returns array | object | null
*/
export const jsonParse = (data: any): any[] | object | null => {
if (data) {
if (typeof data == "string") {
try {
const obj = JSON.parse(data);
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))) {
return data;
}
}
return null;
};
/**
* 判断是数字
* @param {*} value
* @returns Boolean
*/
export const isNumber = (value: any) => {
return !isNaN(parseFloat(value)) && isFinite(value);
};
/**
* 转成数字
* @param {*} str
* @returns Number
*/
export const toNumber = (str: any) => {
return isNumber(str) ? Number(str) : 0;
};
/**
* 保留小数
* @param {*} str 文本
* @param {*} num 位数
*/
export const formatToDecimals = (str: any, num: number = 2) => {
num = num === undefined ? 2 : toNumber(num);
return toNumber(str).toFixed(num);
};
/** 获取权限 */
export const getAuthInfo = () => {
return toObject(wx.getStorageSync("auth_info"));
};
export const goIndexPage = () => {
wx.switchTab({
url: "/pages/index/index",
});
};
export const isImageFile = (path: string) => {
return /\.(jpe?g|png|gif|svg|webp|bmp)$/i.test(path);
};
/** 滚动到顶部 */
export const scrollToTop = () => {
wx.pageScrollTo({ scrollTop: 0 });
};
/** 设置tabs配置 */
export const tabsConfigSet = (key: string, value: any) => {
const tabsConfig = toObject(tabsConfigGet());
tabsConfig[key] = value;
setStorage("tabsConfig", tabsConfig);
};
/** 获取tabs配置 */
export const tabsConfigGet = () => {
return getStorage("tabsConfig");
};
/**
* 媒体图片预览
* @param {*} imageUrls 图片地址数据
* @param {*} currentUrl 当前数据地址
*/
export const mediaPreview = (imageUrls: any[], currentUrl: string) => {
console.log("媒体图片预览方法");
const lastLen = `${currentUrl}`.indexOf("?") > -1 ? `${currentUrl}`.indexOf("?") : `${currentUrl}`.length;
const suffix: any = currentUrl.substring(currentUrl.lastIndexOf(".") + 1, lastLen).toLocaleLowerCase();
if (isImageFile("." + suffix)) {
wx.previewImage({
urls: imageUrls,
current: currentUrl,
showmenu: true,
});
} else if (["mp3", "mp4", "m4a"].includes(suffix)) {
wx.previewMedia({
sources: [
{
url: currentUrl,
type: "video",
},
],
fail() {
wx.showToast({
title: "播放失败",
});
},
});
} else if (["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"].includes(suffix)) {
const downloadTask = wx.downloadFile({
url: currentUrl,
header: http.header,
success: function (res) {
const filePath = res.tempFilePath;
wx.openDocument({
filePath: filePath,
showMenu: true,
fileType: suffix,
success: function () {},
});
},
fail() {},
complete() {
wx.hideLoading();
},
});
downloadTask.onProgressUpdate((res) => {
wx.showLoading({
title: `${res.progress}%`,
});
if (res.progress == 100) {
wx.hideLoading();
}
});
} else {
wx.showToast({
title: "请前往网页端下载查看",
});
}
};
/**
* 文件上传封装
* @param {*} option {filePath: '文件路径', name: 'files', url:'上传url',formData: {额外data},success: (data)=>{}, complete:()=>{},fail: ()=>{} }
*/
export const uploadFile2 = (option: any) => {
console.log("文件上传封装");
option = toObject(option);
option.name = option.name || "files";
wx.showLoading({
title: "文件上传中...",
});
wx.uploadFile({
filePath: option.filePath,
name: option.name,
header: {
...http.header,
cookie: "DFSESSID=" + wx.getStorageSync("session_id"),
},
formData: option.formData,
url: option.url,
success(res) {
const resData = jsonParse(res.data);
wx.showToast({
title: "上传成功",
});
if (option.success) {
option.success(resData);
}
},
fail() {
wx.showToast({
title: "上传失败",
});
if (option.fail) {
option.fail();
}
},
complete() {
wx.hideLoading();
if (option.complete) {
option.complete();
}
},
});
};
/**
* 获取dataset
* @param {*} e
*/
export const getDataSet = (e: any) => {
return e.currentTarget.dataset;
};
export const toastSuccess = (title: string) => {
wx.showToast({ title: `${title}`, icon: "success" });
};
export const toastError = (title: string) => {
wx.showToast({ title: `${title}`, icon: "error" });
};
export const toastSuccessNotIcon = (title: string) => {
wx.showToast({ title: `${title}`, icon: "none" });
};
export const getEnvVersion = wx.getAccountInfoSync().miniProgram.envVersion;
/**
* 获取缓存数据根据小程序版本
* @param key string
*/
export const getStorage = (key: string) => {
return wx.getStorageSync(`${getEnvVersion}_${key}`);
};
/**
* 设置缓存数据根据小程序版本
* @param key string
* @param data any
*/
export const setStorage = (key: string, data: any) => {
return wx.setStorageSync(`${getEnvVersion}_${key}`, data);
};
/**
* 移除缓存数据根据小程序版本
* @param key string
*/
export const removeStorage = (key: string) => {
return wx.removeStorageSync(`${getEnvVersion}_${key}`);
};
/**
* 获取当前页面路由
*/
export const getCurrentPageRoute = () => {
const pages = getCurrentPages(); // 获取页面栈
const currentPage = pages[pages.length - 1]; // 获取当前页面对象
return `/${currentPage.route}`; // 获取当前页面路径
};