feat: 将多个页面从JavaScript转换为TypeScript
- 将 agreement.js、no-auth-plugin.js、processEntry.js、https.js、 menuConfig.js、voiceUtil.js 文件重命名为对应的 .ts 扩展名 - 在 agreement.ts 中引入配置并动态设置标题 - 在 no-auth-plugin.ts 中使用工具函数替代硬编码跳转 - 为 processEntry.ts 添加类型注解并重构代码结构 - 为 https.ts 添加类型定义并优化错误处理 - 创建 menuConfig.ts 并迁移导航配置 - 为 voiceUtil.ts 添加类型注解
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// pages/agreement/agreement.js
|
||||
import { base } from "@/utils/config";
|
||||
|
||||
Page({
|
||||
/**
|
||||
* 页面的初始数据
|
||||
@@ -11,14 +12,12 @@ Page({
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {
|
||||
this.setData({
|
||||
type: options.type,
|
||||
});
|
||||
const appletName = base.appletName;
|
||||
this.setData({ type: options.type });
|
||||
wx.setNavigationBarTitle({
|
||||
title:
|
||||
options.type == "user"
|
||||
? "易宝赞数据化管理系统平台用户服务协议"
|
||||
: "易宝赞数据化管理系统隐私权政策",
|
||||
title: `${appletName}${
|
||||
options.type == "user" ? "平台用户服务协议" : "隐私权政策"
|
||||
}`,
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { goIndexPage } from "@/utils/util";
|
||||
Component({
|
||||
/**
|
||||
* 组件的属性列表
|
||||
@@ -13,10 +14,8 @@ Component({
|
||||
* 组件的方法列表
|
||||
*/
|
||||
methods: {
|
||||
navIndex: function () {
|
||||
wx.switchTab({
|
||||
url: "/pages/index/index",
|
||||
});
|
||||
navIndex() {
|
||||
goIndexPage();
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -1,5 +1,12 @@
|
||||
import { loginStatus, post } from "@/utils/https";
|
||||
import { formatTime, getAuthInfo, getDataSet, isArray, toArray, toObject } from "@/utils/util";
|
||||
import {
|
||||
formatTime,
|
||||
getAuthInfo,
|
||||
getDataSet,
|
||||
isArray,
|
||||
toArray,
|
||||
toObject,
|
||||
} from "@/utils/util";
|
||||
import { voiceRequest } from "@/utils/voiceUtil";
|
||||
|
||||
/** 拼接符号 */
|
||||
@@ -11,7 +18,7 @@ const RecallCodeMarking = "-";
|
||||
* 解析流程码
|
||||
* @param {string} value
|
||||
*/
|
||||
const parseQrCode = (value) => {
|
||||
const parseQrCode = (value: string) => {
|
||||
value = `${value || ""}`;
|
||||
const obj = {
|
||||
/** 工序码 */
|
||||
@@ -23,7 +30,9 @@ const parseQrCode = (value) => {
|
||||
};
|
||||
if (value.includes(ProcessCodeConcatSymbol)) {
|
||||
obj.code = value.substring(0, value.indexOf(ProcessCodeConcatSymbol));
|
||||
obj.key = value.substring(value.indexOf(ProcessCodeConcatSymbol) + ProcessCodeConcatSymbol.length);
|
||||
obj.key = value.substring(
|
||||
value.indexOf(ProcessCodeConcatSymbol) + ProcessCodeConcatSymbol.length
|
||||
);
|
||||
}
|
||||
|
||||
if (obj.code.includes(RecallCodeMarking)) {
|
||||
@@ -43,16 +52,16 @@ Page({
|
||||
processCodeMsg: "",
|
||||
rel_order_no: "",
|
||||
process_code: "",
|
||||
logsList: [],
|
||||
logsList: [] as any[],
|
||||
show: false,
|
||||
orders: [],
|
||||
orders: [] as any[],
|
||||
isLogin: false,
|
||||
isScanCode: false,
|
||||
voice: true,
|
||||
loading: true,
|
||||
authInfo: {},
|
||||
hideTabKeys: [],
|
||||
processItems: [],
|
||||
hideTabKeys: [] as string[],
|
||||
processItems: [] as any[],
|
||||
backFlag: false,
|
||||
selectedProcessCode: "",
|
||||
result: "",
|
||||
@@ -61,10 +70,10 @@ Page({
|
||||
defaultBonus: true,
|
||||
showDefaultBonus: false,
|
||||
defaultBonusConfig: {},
|
||||
defaultBonusConfigKeys: [],
|
||||
defaultBonusConfigKeys: [] as string[],
|
||||
rel_order_no_temp: "",
|
||||
},
|
||||
handleLogin(e) {
|
||||
handleLogin(e: any) {
|
||||
if (e.detail) {
|
||||
this.setData({ isLogin: true, authInfo: getAuthInfo() });
|
||||
this.init();
|
||||
@@ -72,13 +81,15 @@ Page({
|
||||
this.setData({ isLogin: false });
|
||||
}
|
||||
},
|
||||
backChange(e) {
|
||||
backChange(e: any) {
|
||||
this.data.backFlag = e.detail;
|
||||
this.setData({ backFlag: e.detail });
|
||||
wx.setStorageSync("processBackFlag", e.detail ? 1 : 0);
|
||||
if (this.data.selectedProcessCode) {
|
||||
const { code, key } = parseQrCode(this.data.selectedProcessCode);
|
||||
this.data.selectedProcessCode = `${code}${e.detail ? RecallCodeMarking : ""}`;
|
||||
this.data.selectedProcessCode = `${code}${
|
||||
e.detail ? RecallCodeMarking : ""
|
||||
}`;
|
||||
if (key) {
|
||||
this.data.selectedProcessCode += `${ProcessCodeConcatSymbol}${key}`;
|
||||
}
|
||||
@@ -101,8 +112,9 @@ Page({
|
||||
}
|
||||
}
|
||||
},
|
||||
processItemTap(e) {
|
||||
this.data.selectedProcessCode = e.currentTarget.dataset.code + (this.data.backFlag ? "-" : "");
|
||||
processItemTap(e: any) {
|
||||
this.data.selectedProcessCode =
|
||||
e.currentTarget.dataset.code + (this.data.backFlag ? "-" : "");
|
||||
wx.setStorageSync("selectedProcessCode", this.data.selectedProcessCode);
|
||||
this.setData({
|
||||
selectedProcessCode: this.data.selectedProcessCode,
|
||||
@@ -110,7 +122,7 @@ Page({
|
||||
this.getProcessName();
|
||||
},
|
||||
getExecProcess() {
|
||||
post("Orders/getExecProcess1").then((res) => {
|
||||
post("Orders/getExecProcess1").then((res: any) => {
|
||||
this.data.processItems = toArray(res.data);
|
||||
if (this.data.processItems.length == 1) {
|
||||
this.data.selectedProcessCode = this.data.processItems[0].code;
|
||||
@@ -140,18 +152,18 @@ Page({
|
||||
});
|
||||
this.getExecProcess();
|
||||
},
|
||||
voiceChange(event) {
|
||||
voiceChange(event: any) {
|
||||
this.setData({
|
||||
voice: event.detail,
|
||||
});
|
||||
wx.setStorageSync("processEntryVoice", `${event.detail}`);
|
||||
},
|
||||
getVoice(msg, cacheVoice) {
|
||||
getVoice(msg: string, cacheVoice?: boolean) {
|
||||
if (this.data.voice && msg) {
|
||||
voiceRequest(msg, cacheVoice);
|
||||
}
|
||||
},
|
||||
onLogTypeChange(e) {
|
||||
onLogTypeChange(e: any) {
|
||||
const data = getDataSet(e);
|
||||
this.setData({ logType: data.key });
|
||||
wx.setStorageSync("processEntry_logType", data.key);
|
||||
@@ -196,14 +208,14 @@ Page({
|
||||
},
|
||||
});
|
||||
},
|
||||
getProcess(real_code) {
|
||||
getProcess(real_code: any) {
|
||||
const code = parseQrCode(real_code);
|
||||
post("CompanyProcess/processChildList", {
|
||||
curr_page: 1,
|
||||
page_count: 1,
|
||||
real_code: code.code,
|
||||
})
|
||||
.then((res) => {
|
||||
.then((res: any) => {
|
||||
const data = res.data;
|
||||
if (Array.isArray(res.data) && data.length) {
|
||||
this.setData({
|
||||
@@ -225,7 +237,7 @@ Page({
|
||||
this.getVoice(`未找到工序`, true);
|
||||
}
|
||||
})
|
||||
.catch((res) => {
|
||||
.catch(() => {
|
||||
this.addMsg("未找到 " + real_code + " 工序");
|
||||
wx.showToast({
|
||||
title: "未找到该工序",
|
||||
@@ -239,14 +251,14 @@ Page({
|
||||
this.setProcess();
|
||||
}
|
||||
},
|
||||
LCProcessEnter(e) {
|
||||
LCProcessEnter(e: any) {
|
||||
const item = this.data.orders[e.currentTarget.dataset.index];
|
||||
this.data.rel_order_no_temp = item.rel_order_no;
|
||||
this.setProcess();
|
||||
},
|
||||
setProcess(other) {
|
||||
setProcess(other?: any) {
|
||||
const code = parseQrCode(this.data.process_code);
|
||||
const obj = {};
|
||||
const obj: any = {};
|
||||
if (code.key) {
|
||||
obj[this.data.rel_order_no_temp] = code.key;
|
||||
}
|
||||
@@ -256,12 +268,14 @@ Page({
|
||||
process_code: code.code,
|
||||
action: this.data.action,
|
||||
if_scan: 1,
|
||||
same_process: this.data.rel_order_no_temp.startsWith("LC") ? 1 : undefined,
|
||||
same_process: this.data.rel_order_no_temp.startsWith("LC")
|
||||
? 1
|
||||
: undefined,
|
||||
// defaultBonus: getDefaultBonus() != "0",
|
||||
}),
|
||||
other: JSON.stringify({ ...other, ...obj }),
|
||||
})
|
||||
.then((res) => {
|
||||
.then((res: any) => {
|
||||
if (res.bonus == 1) {
|
||||
const data = toObject(res.data);
|
||||
this.setData({
|
||||
@@ -270,10 +284,12 @@ Page({
|
||||
showDefaultBonus: true,
|
||||
});
|
||||
} else if (isArray(res.data) && res.data.length) {
|
||||
res.data.forEach((el) => {
|
||||
res.data.forEach((el: any) => {
|
||||
el.product_info_str = toArray(el.product_info)
|
||||
.map((ell) => {
|
||||
return `${ell.room_name || "未命名"}(${ell.goods_name || "未命名"})`;
|
||||
return `${ell.room_name || "未命名"}(${
|
||||
ell.goods_name || "未命名"
|
||||
})`;
|
||||
})
|
||||
.join(",");
|
||||
|
||||
@@ -303,7 +319,7 @@ Page({
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((res) => {
|
||||
.catch((res: any) => {
|
||||
this.addMsg(res.err_msg);
|
||||
if (res.err_code == "244269") {
|
||||
this.setData({
|
||||
@@ -322,7 +338,7 @@ Page({
|
||||
}
|
||||
});
|
||||
},
|
||||
onSelectBonus(e) {
|
||||
onSelectBonus(e: any) {
|
||||
const data = getDataSet(e);
|
||||
this.setProcess({ [data.order_no]: data.key });
|
||||
},
|
||||
@@ -337,7 +353,7 @@ Page({
|
||||
// });
|
||||
// setDefaultBonus(e.detail ? "1" : "0");
|
||||
// },
|
||||
addMsg(msg) {
|
||||
addMsg(msg: any) {
|
||||
const now = new Date();
|
||||
this.data.logsList.unshift({
|
||||
date: formatTime(now).substring(5),
|
||||
@@ -351,30 +367,24 @@ Page({
|
||||
});
|
||||
},
|
||||
clearMsg() {
|
||||
this.setData({
|
||||
logsList: [],
|
||||
});
|
||||
this.setData({ logsList: [] });
|
||||
},
|
||||
show() {
|
||||
this.setData({
|
||||
show: true,
|
||||
});
|
||||
this.setData({ show: true });
|
||||
},
|
||||
onClose() {
|
||||
this.setData({
|
||||
show: false,
|
||||
});
|
||||
this.setData({ show: false });
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {
|
||||
onLoad(_options) {
|
||||
this.setData({
|
||||
loading: true,
|
||||
voice: wx.getStorageSync("processEntryVoice") == "false" ? false : true,
|
||||
});
|
||||
loginStatus()
|
||||
.then((res) => {
|
||||
.then(() => {
|
||||
this.setData({
|
||||
isLogin: true,
|
||||
loading: false,
|
||||
Reference in New Issue
Block a user