添加组件及页面

This commit is contained in:
zhengw
2026-01-21 17:05:30 +08:00
parent a89e69c381
commit 7ff1a911dd
54 changed files with 1078 additions and 1009 deletions

View File

@@ -2,39 +2,39 @@
* Global Config Files
* Added By YangXB 2021.11.24
*/
export const servicePhone = "4000-5858-22";
export const servicePhone = '4000-5858-22';
export const colors = {
primary: "#0052d9",
success: "#2ba471",
warning: "#e37318",
danger: "#d54941",
info: "#029cd4",
gray: "#999999",
primary: '#0052d9',
success: '#2ba471',
warning: '#e37318',
danger: '#d54941',
info: '#029cd4',
gray: '#999999',
} as const;
export const defaultAvatarUrl =
"https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0";
'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0';
export const base = {
appletName: "易宝赞普惠版",
appletName: '易宝赞普惠版',
apiHost:
wx.getAccountInfoSync().miniProgram.envVersion == "release"
? "https://ebaozan.com/api/"
: "http://192.168.1.138:83/",
wx.getAccountInfoSync().miniProgram.envVersion == 'release'
? 'https://ebaozan.com/api/'
: 'http://192.168.1.138:93/',
webViewBaseUrl:
wx.getAccountInfoSync().miniProgram.envVersion == "release"
? "https://ebaozan.com/"
: "http://ebaozan.cf/",
cookieKey: "OwCookie",
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",
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest',
},
unLoginCode: 110000,
};

View File

@@ -2,39 +2,29 @@
* 全局http工具集
* YangXB 2021.11.24
* */
import { base, http } from "./config";
import {
getStorage,
goIndexPage,
isArray,
setStorage,
toastError,
} from "./util";
import { base, http } from './config';
import { getStorage, goIndexPage, isArray, setStorage, toastError } from './util';
/**
* 请求
*/
const request = (
url: string,
options: any,
config = { showLoading: true, showError: true }
) => {
const request = (url: string, options: any, config = { showLoading: true, showError: true }) => {
// 获取缓存cookie
const header: any = { ...http.header };
const cookie = getStorage(base.cookieKey);
if (cookie && !header["Cookie"]) {
header["Cookie"] = cookie;
if (cookie && !header['Cookie']) {
header['Cookie'] = cookie;
}
if (options["content-type"]) {
header["content-type"] = options["content-type"];
if (options['content-type']) {
header['content-type'] = options['content-type'];
}
return new Promise((resolve, reject) => {
if (config.showLoading != false) {
wx.showLoading({ title: "加载中" });
wx.showLoading({ title: '加载中' });
}
url = `${url}`.startsWith("http") ? url : urlAddBaseUrl(url);
url = `${url}`.startsWith('http') ? url : urlAddBaseUrl(url);
wx.request({
url: url,
method: options.method,
@@ -46,32 +36,32 @@ const request = (
}
// 写入缓存
if (!cookie) {
setStorage(base.cookieKey, request.header["Set-Cookie"]);
setStorage(base.cookieKey, request.header['Set-Cookie']);
}
if (request.data?.err_code === 0) {
//
resolve(request.data);
return;
} else {
if (config.showError != false) {
wx.showToast({
title: request.data.err_msg,
icon: "none",
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)
!['pages/index/index', 'pages/processEntry/processEntry', 'pages/my/my'].includes(
pages[pages.length - 1].route,
)
) {
goIndexPage();
}
}
}
resolve(request.data);
reject();
},
fail(error: any) {
if (config.showLoading != false) {
@@ -85,28 +75,28 @@ const request = (
// 封装get方法
export const get = (url: string, data = {}, config?: any): any => {
return request(url, { method: "GET", data }, config);
return request(url, { method: 'GET', data }, config);
};
// 封装post方法
export const post = (url: string, data = {}, config?: any): any => {
return request(url, { method: "POST", data }, config);
return request(url, { method: 'POST', data }, config);
};
export const wxLogin = (config?: any) => {
wx.login({
success: (res) => {
post("Applet/code2Sess", { code: res.code, name: "ch" }, config)
post('Applet/code2Sess', { code: res.code, name: 'ch' }, config)
.then((res: any) => {
// 记录sessionKey
setStorage("session", {
setStorage('session', {
openid: res.openid,
unionid: res.unionid,
time: Date.now() + 1000 * 3600 * 24, // 缓存一天过期
});
})
.catch((err: any) => {
toastError("服务失败:" + err.err_code);
toastError('服务失败:' + err.err_code);
});
},
});
@@ -132,7 +122,7 @@ export const checkSession = () => {
// }
},
fail: () => {
console.log("checkSession失效");
console.log('checkSession失效');
// 已过期重新登录获取session_key
wxLogin();
},
@@ -141,23 +131,23 @@ export const checkSession = () => {
export const loginStatus = () => {
return new Promise((resolve, reject) => {
post("Applet/loginStatus", {}, { showLoading: false })
post('Applet/loginStatus', {}, { showLoading: false })
.then((res: any) => {
setStorage("user_info", res.user_info);
setStorage("company_info", res.company_info);
setStorage("auth_info", res.auth_info);
setStorage("session_id", res.session_id);
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: any) => {
login("", "", 4)
login('', '', 4)
.then((res: any) => {
if (isArray(res.data)) {
post("Applet/loginOut").then(() => {
post('Applet/loginOut').then(() => {
checkSesskey({ showLoading: false, showError: false })
.then(() => {})
.catch((err) => {
console.log("checkSesskey", err);
console.log('checkSesskey', err);
});
});
reject(res);
@@ -178,7 +168,7 @@ export const loginStatus = () => {
*/
export const checkSesskey = (config?: any) => {
return new Promise<any>((resolve, reject) => {
post("Applet/checkSesskey", {}, config)
post('Applet/checkSesskey', {}, config)
.then((res: any) => {
resolve(res);
})
@@ -190,12 +180,7 @@ export const checkSesskey = (config?: any) => {
};
// 后端登录
export const login = (
encryptedData: any,
iv: any,
type: any,
company_id?: any
) => {
export const login = (encryptedData: any, iv: any, type?: any, company_id?: any) => {
return new Promise<any>((resolve, reject) => {
const data: any = { type: 2, encryptedData, iv };
@@ -203,14 +188,14 @@ export const login = (
data.companyID = company_id;
}
post("Applet/login", type == 4 ? { type } : data)
post('Applet/login', type == 4 ? { type } : data)
.then((res: any) => {
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);
setStorage('user_info', res.user_info);
setStorage('company_info', res.companys_info);
setStorage('auth_info', res.auth_info);
loginStatus();
resolve(res);
}
@@ -242,19 +227,17 @@ export const login = (
export const makeURL = (url: string, redirect = false, openID = false) => {
return (
base.apiHost +
(redirect ? "applet-wv?url=" : "") +
encodeURIComponent(
url + (openID ? "?openID=" + wx.getStorageSync("session")["openid"] : "")
) +
(redirect ? "&" : "?") +
"cookie=" +
(redirect ? 'applet-wv?url=' : '') +
encodeURIComponent(url + (openID ? '?openID=' + wx.getStorageSync('session')['openid'] : '')) +
(redirect ? '&' : '?') +
'cookie=' +
encodeURI(wx.getStorageSync(base.cookieKey))
);
};
export const urlAddBaseUrl = (url: string) => {
if (typeof url == "string") {
if (url.startsWith("/")) {
if (typeof url == 'string') {
if (url.startsWith('/')) {
url = url.substring(1);
}
}
@@ -262,8 +245,8 @@ export const urlAddBaseUrl = (url: string) => {
};
export const urlAddWebViewBaseUrl = (url: string) => {
if (typeof url == "string") {
if (url.startsWith("/")) {
if (typeof url == 'string') {
if (url.startsWith('/')) {
url = url.substring(1);
}
}
@@ -276,10 +259,10 @@ export const formDataRequest = (url: string, formData: any, config?: any) => {
return request(
url,
{
method: "POST",
method: 'POST',
data: data.buffer,
"content-type": data.contentType,
'content-type': data.contentType,
},
config
config,
);
};

View File

@@ -1,21 +1,26 @@
/** 首页菜单 */
const iconColor = "#0052D9";
const iconColor = '#0052D9';
export const menuConfig = [
{
title: "订单管理",
icon: "form",
title: '订单管理',
icon: 'form',
iconColor: iconColor,
children: [
{
title: "销售订单",
url: "/pages/orders/ordersList/ordersList",
auth: "SF_ERP_SALE_ORDERS_VIEW",
title: '销售订单',
url: '/pages/orders/ordersList/ordersList',
auth: 'SF_ERP_SALE_ORDERS_VIEW',
},
{
title: '订单排序',
url: '/pages/orders/orderSort/orderSort',
auth: 'SF_ERP_SALE_ORDERS_VIEW',
},
],
},
{
title: "生产管理",
icon: "form",
title: '生产管理',
icon: 'tools',
iconColor: iconColor,
children: [
// {
@@ -24,14 +29,14 @@ export const menuConfig = [
// auth: "SF_ERP_PRODUCT_TASK_VIEW",
// },
{
title: "流程管理",
url: "/pages/produce/processManage/processManage",
auth: "SF_ERP_PRODUCT_PROCESS_VIEW",
title: '流程管理',
url: '/pages/produce/processManage/processManage',
auth: 'SF_ERP_PRODUCT_PROCESS_VIEW',
},
{
title: "流程录入",
url: "/pages/processEntry/processEntry",
auth: "SF_ERP_PRODUCT_PROCESS_ENTER",
title: '录入流程',
url: '/pages/processEntry/processEntry',
auth: 'SF_ERP_PRODUCT_PROCESS_ENTER',
},
],
},

View File

@@ -1,4 +1,4 @@
import { http } from "./config";
import { http } from './config';
export const formatTime = (date: Date) => {
const year = date.getFullYear();
@@ -8,13 +8,9 @@ export const formatTime = (date: Date) => {
const minute = date.getMinutes();
const second = date.getSeconds();
return `${[year, month, day].map(formatNumber).join("-")} ${[
hour,
minute,
second,
]
return `${[year, month, day].map(formatNumber).join('-')} ${[hour, minute, second]
.map(formatNumber)
.join(":")}`;
.join(':')}`;
};
export const formatNumber = (n: number | string) => {
@@ -23,11 +19,7 @@ export const formatNumber = (n: number | string) => {
};
// 对话框
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,
@@ -56,7 +48,7 @@ export const toArray = (data: any): any[] => (isArray(data) ? data : []);
/** 判断数据是不是对象类型 */
export const isObject = (data: any) => {
return data && `${Object.prototype.toString.call(data)}`.includes("Object");
return data && `${Object.prototype.toString.call(data)}`.includes('Object');
};
export const toObject = (data: any) => (isObject(data) ? data : {});
@@ -66,15 +58,15 @@ export const reloadPage = () => {
let currentPage = pages[pages.length - 1]; //获取当前页面的对象
let url = currentPage.route; //当前页面url
// 关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。
wx.redirectTo({ url: "/" + url });
wx.redirectTo({ url: '/' + url });
};
/** 判断是json数据 */
export const isJson = (str: any) => {
if (str && typeof str == "string") {
if (str && typeof str == 'string') {
try {
const obj = JSON.parse(str);
return obj && typeof obj == "object";
return obj && typeof obj == 'object';
} catch (_e) {
//
}
@@ -89,24 +81,16 @@ export const isJson = (str: any) => {
*/
export const jsonParse = (data: any): any[] | object | null => {
if (data) {
if (typeof data == "string") {
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;
}
}
@@ -142,10 +126,10 @@ export const formatToDecimals = (str: any, num: number = 2) => {
};
/** 获取权限 */
export const getAuthInfo = () => toObject(wx.getStorageSync("auth_info"));
export const getAuthInfo = () => toObject(wx.getStorageSync('auth_info'));
export const goIndexPage = () => {
wx.navigateTo({ url: "/pages/index/index" });
wx.navigateTo({ url: '/pages/index/index' });
};
export const isImageFile = (path: string) => {
@@ -161,12 +145,12 @@ export const scrollToTop = () => {
export const tabsConfigSet = (key: string, value: any) => {
const tabsConfig = toObject(tabsConfigGet());
tabsConfig[key] = value;
setStorage("tabsConfig", tabsConfig);
setStorage('tabsConfig', tabsConfig);
};
/** 获取tabs配置 */
export const tabsConfigGet = () => {
return getStorage("tabsConfig");
return getStorage('tabsConfig');
};
/**
@@ -175,28 +159,24 @@ export const tabsConfigGet = () => {
* @param {*} currentUrl 当前数据地址
*/
export const mediaPreview = (imageUrls: any[], currentUrl: string) => {
console.log("媒体图片预览方法");
console.log('媒体图片预览方法');
const lastLen =
`${currentUrl}`.indexOf("?") > -1
? `${currentUrl}`.indexOf("?")
: `${currentUrl}`.length;
`${currentUrl}`.indexOf('?') > -1 ? `${currentUrl}`.indexOf('?') : `${currentUrl}`.length;
const suffix: any = currentUrl
.substring(currentUrl.lastIndexOf(".") + 1, lastLen)
.substring(currentUrl.lastIndexOf('.') + 1, lastLen)
.toLocaleLowerCase();
if (isImageFile("." + suffix)) {
if (isImageFile('.' + suffix)) {
wx.previewImage({ urls: imageUrls, current: currentUrl, showmenu: true });
} else if (["mp3", "mp4", "m4a"].includes(suffix)) {
} 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,
@@ -223,7 +203,7 @@ export const mediaPreview = (imageUrls: any[], currentUrl: string) => {
}
});
} else {
wx.showToast({ title: "请前往网页端下载查看" });
wx.showToast({ title: '请前往网页端下载查看' });
}
};
@@ -232,29 +212,29 @@ export const mediaPreview = (imageUrls: any[], currentUrl: string) => {
* @param {*} option {filePath: '文件路径', name: 'files', url:'上传url',formData: {额外data},success: (data)=>{}, complete:()=>{},fail: ()=>{} }
*/
export const uploadFile2 = (option: any) => {
console.log("文件上传封装");
console.log('文件上传封装');
option = toObject(option);
option.name = option.name || "files";
option.name = option.name || 'files';
wx.showLoading({ title: "文件上传中..." });
wx.showLoading({ title: '文件上传中...' });
wx.uploadFile({
filePath: option.filePath,
name: option.name,
header: {
...http.header,
cookie: "DFSESSID=" + wx.getStorageSync("session_id"),
cookie: 'FREESESSID=' + wx.getStorageSync('session_id'),
},
formData: option.formData,
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();
}
@@ -277,15 +257,15 @@ export const getDataSet = (e: any) => {
};
export const toastSuccess = (title: string) => {
wx.showToast({ title: `${title}`, icon: "success" });
wx.showToast({ title: `${title}`, icon: 'success' });
};
export const toastError = (title: string) => {
wx.showToast({ title: `${title}`, icon: "error" });
wx.showToast({ title: `${title}`, icon: 'error' });
};
export const toastSuccessNotIcon = (title: string) => {
wx.showToast({ title: `${title}`, icon: "none" });
wx.showToast({ title: `${title}`, icon: 'none' });
};
export const getEnvVersion = wx.getAccountInfoSync().miniProgram.envVersion;
@@ -295,7 +275,8 @@ export const getEnvVersion = wx.getAccountInfoSync().miniProgram.envVersion;
* @param key string
*/
export const getStorage = (key: string) => {
return wx.getStorageSync(`${getEnvVersion}_${key}`);
// return wx.getStorageSync(`${getEnvVersion}_${key}`);
return wx.getStorageSync(key);
};
/**
@@ -304,7 +285,8 @@ export const getStorage = (key: string) => {
* @param data any
*/
export const setStorage = (key: string, data: any) => {
return wx.setStorageSync(`${getEnvVersion}_${key}`, data);
// return wx.setStorageSync(`${getEnvVersion}_${key}`, data);
return wx.setStorageSync(key, data);
};
/**
@@ -312,7 +294,8 @@ export const setStorage = (key: string, data: any) => {
* @param key string
*/
export const removeStorage = (key: string) => {
return wx.removeStorageSync(`${getEnvVersion}_${key}`);
// return wx.removeStorageSync(`${getEnvVersion}_${key}`);
return wx.removeStorageSync(key);
};
/**
@@ -323,4 +306,3 @@ export const getCurrentPageRoute = () => {
const currentPage = pages[pages.length - 1]; // 获取当前页面对象
return `/${currentPage.route}`; // 获取当前页面路径
};