@infly/libs 2.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +5 -0
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/bin/cli.js +30 -0
- package/build/build-dist/index.js +644 -0
- package/build/build-dist/zip.js +57 -0
- package/build/webpack5/inline-runtime-plugin.js +35 -0
- package/build/webpack5/webpack.base.js +227 -0
- package/dataInit/commonTypeMap.js +31 -0
- package/dataInit/marketingActivitiesMap.js +214 -0
- package/dataInit/orderMap.js +13 -0
- package/dataInit/personalMap.js +19 -0
- package/dataInit/settlementMap.js +17 -0
- package/index.js +13 -0
- package/lib/index.js +6 -0
- package/lib/server/connect.js +3011 -0
- package/lib/server/serve-static.js +4848 -0
- package/module/Permission.js +138 -0
- package/module/REST.js +97 -0
- package/module/TokenService.js +127 -0
- package/module/Uts.js +7222 -0
- package/package.json +88 -0
- package/script/git-automation/check-packages.js +44 -0
- package/script/git-automation/git-clone.js +69 -0
- package/script/git-automation/git-submodule.js +17 -0
- package/script/git-automation/index.js +488 -0
- package/script/index.js +26 -0
- package/script/webhook/webhook.js +60 -0
- package/store/index.js +0 -0
- package/store/modules/user.js +166 -0
- package/tools/file-export.js +142 -0
- package/tools/file-process.js +49 -0
- package/tools/format.js +31 -0
- package/tools/project-preview.js +135 -0
- package/types/unused.index.d.ts +71 -0
- package/webpack.config.js +38 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import Uts from "../../module/Uts.js";
|
|
2
|
+
import TokenService from "../../module/TokenService.js";
|
|
3
|
+
|
|
4
|
+
const CONFIG = {
|
|
5
|
+
router: {},
|
|
6
|
+
settings: {},
|
|
7
|
+
login: () => Promise.resolve(),
|
|
8
|
+
getInfo: () => Promise.resolve(),
|
|
9
|
+
resetRouter: () => {}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function init(config = {}) {
|
|
13
|
+
const { settings } = config || {};
|
|
14
|
+
if (Uts.notEmptyObject(settings)) {
|
|
15
|
+
TokenService.init(settings);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (Uts.notEmptyObject(config)) {
|
|
19
|
+
Uts.mergeObjectWithReference(CONFIG, config);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const getDefaultState = () => {
|
|
24
|
+
return {
|
|
25
|
+
token: TokenService.getToken(),
|
|
26
|
+
name: "",
|
|
27
|
+
avatar: "",
|
|
28
|
+
user: {
|
|
29
|
+
id: "",
|
|
30
|
+
email: "",
|
|
31
|
+
header: "",
|
|
32
|
+
level_id: "",
|
|
33
|
+
level_name: "",
|
|
34
|
+
is_active_str: "",
|
|
35
|
+
mobile: "",
|
|
36
|
+
nickname: "",
|
|
37
|
+
role: "",
|
|
38
|
+
username: "",
|
|
39
|
+
company: "",
|
|
40
|
+
affiliation: {
|
|
41
|
+
province: "",
|
|
42
|
+
city: "",
|
|
43
|
+
district: ""
|
|
44
|
+
},
|
|
45
|
+
dimensionality_choices: [],
|
|
46
|
+
merchant_set: [],
|
|
47
|
+
merchantinfo: {},
|
|
48
|
+
map_key: ""
|
|
49
|
+
},
|
|
50
|
+
chatToken: TokenService.getChatToken() // 商家端聊天管理token
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const userModule = {
|
|
55
|
+
namespaced: true,
|
|
56
|
+
state: () => getDefaultState(),
|
|
57
|
+
mutations: {
|
|
58
|
+
RESET_STATE: (state) => {
|
|
59
|
+
Uts.mergeObjectWithReference(state, getDefaultState());
|
|
60
|
+
},
|
|
61
|
+
SET_USER: (state, user) => (state.user = user),
|
|
62
|
+
SET_TOKEN: (state, token) => {
|
|
63
|
+
state.token = token;
|
|
64
|
+
TokenService.setToken(token);
|
|
65
|
+
},
|
|
66
|
+
SET_NAME: (state, name) => {
|
|
67
|
+
state.name = name;
|
|
68
|
+
},
|
|
69
|
+
SET_AVATAR: (state, avatar) => {
|
|
70
|
+
state.avatar = avatar;
|
|
71
|
+
},
|
|
72
|
+
SET_MAPKEY: (state, mapKey) => {
|
|
73
|
+
Uts.storage.set("mapKey", mapKey);
|
|
74
|
+
},
|
|
75
|
+
//邮惠权益商家端聊天管理的登录凭证
|
|
76
|
+
SET_CHAT_TOKEN: (state, token) => {
|
|
77
|
+
state.chatToken = token;
|
|
78
|
+
TokenService.setChatToken(token);
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
actions: {
|
|
82
|
+
login({ commit }, userInfo) {
|
|
83
|
+
const { mobile, sms_code } = userInfo;
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
CONFIG.login({
|
|
86
|
+
mobile: mobile,
|
|
87
|
+
sms_code: sms_code
|
|
88
|
+
})
|
|
89
|
+
.then((response) => {
|
|
90
|
+
commit("SET_TOKEN", response.token);
|
|
91
|
+
resolve();
|
|
92
|
+
})
|
|
93
|
+
.catch((error) => {
|
|
94
|
+
reject(error);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
getInfo({ commit, state }) {
|
|
100
|
+
return new Promise((resolve, reject) => {
|
|
101
|
+
CONFIG.getInfo(state.token)
|
|
102
|
+
.then((response) => {
|
|
103
|
+
if (!response) {
|
|
104
|
+
reject("验证失败,请重新登录。");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const { name, header, map_key, merchantinfo } = response;
|
|
108
|
+
const { service_token } = merchantinfo || {};
|
|
109
|
+
commit("SET_USER", response);
|
|
110
|
+
commit("SET_NAME", name);
|
|
111
|
+
commit("SET_AVATAR", header);
|
|
112
|
+
commit("SET_MAPKEY", map_key);
|
|
113
|
+
|
|
114
|
+
if (service_token) {
|
|
115
|
+
commit("SET_CHAT_TOKEN", service_token);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
resolve(response);
|
|
119
|
+
})
|
|
120
|
+
.catch((error) => {
|
|
121
|
+
reject(error);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
logout({ commit, state }) {
|
|
127
|
+
return new Promise((resolve, reject) => {
|
|
128
|
+
TokenService.removeAllTokens();
|
|
129
|
+
commit("RESET_STATE");
|
|
130
|
+
commit("SET_MAPKEY", "");
|
|
131
|
+
|
|
132
|
+
if (CONFIG.router) {
|
|
133
|
+
Uts.isFunction(CONFIG.router.push) && CONFIG.router.push("/login");
|
|
134
|
+
Uts.isFunction(CONFIG.router.resetRouter) &&
|
|
135
|
+
CONFIG.router.resetRouter();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (TokenService.getUrlToken()) {
|
|
139
|
+
TokenService.removeUrlToken();
|
|
140
|
+
}
|
|
141
|
+
resolve();
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
resetToken({ commit }) {
|
|
146
|
+
return new Promise((resolve) => {
|
|
147
|
+
commit("SET_TOKEN", "");
|
|
148
|
+
commit("SET_MAPKEY", "");
|
|
149
|
+
commit("RESET_STATE");
|
|
150
|
+
resolve();
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
refreshToken({ commit }, { token }) {
|
|
155
|
+
return new Promise((resolve, reject) => {
|
|
156
|
+
commit("SET_TOKEN", token);
|
|
157
|
+
resolve();
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export default {
|
|
164
|
+
...userModule,
|
|
165
|
+
init
|
|
166
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 统一文件导出函数
|
|
3
|
+
* @param {Object} config - 配置对象
|
|
4
|
+
* @param {string} config.url - 请求文件的 URL
|
|
5
|
+
* @param {string} config.fileName - 导出文件的基础名称
|
|
6
|
+
* @param {Object} [config.params={}] - 请求参数
|
|
7
|
+
* @param {string} [config.suffix=".csv"] - 文件后缀名
|
|
8
|
+
* @param {Object} config.request - 请求封装实例 (如 axios 实例)
|
|
9
|
+
* @param {string} [config.reqMethod="get"] - 请求方法 ('get' 或 'post')
|
|
10
|
+
* @param {Object} [config.Message={}] - Element UI Message 组件实例
|
|
11
|
+
* @param {Object} [config.MessageBox={}] - Element UI MessageBox 组件实例
|
|
12
|
+
* @param {Object} [config.Loading={}] - Element UI Loading 组件实例
|
|
13
|
+
*/
|
|
14
|
+
async function exportFile(config) {
|
|
15
|
+
// 1. 参数解构与默认值,并进行基本校验
|
|
16
|
+
const {
|
|
17
|
+
url,
|
|
18
|
+
fileName,
|
|
19
|
+
params = {},
|
|
20
|
+
suffix = ".csv",
|
|
21
|
+
request,
|
|
22
|
+
reqMethod = "get",
|
|
23
|
+
Message = {},
|
|
24
|
+
MessageBox = {},
|
|
25
|
+
Loading = {}
|
|
26
|
+
} = config || {};
|
|
27
|
+
|
|
28
|
+
if (!url || !request) {
|
|
29
|
+
console.error("exportFile: 缺少必要的参数 (url, fileName, request)");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let loadingInstance = null;
|
|
34
|
+
|
|
35
|
+
// 辅助函数:显示消息
|
|
36
|
+
const showMessage = (type, msg) => {
|
|
37
|
+
if (Message && Uts.isFunction(Message[type])) {
|
|
38
|
+
Message[type](msg);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// 辅助函数:显示加载
|
|
43
|
+
const showLoading = () => {
|
|
44
|
+
if (Loading && Uts.isFunction(Loading.service)) {
|
|
45
|
+
loadingInstance = Loading.service({
|
|
46
|
+
text: "文件正在下载中,请等候...",
|
|
47
|
+
spinner: "el-icon-loading",
|
|
48
|
+
background: "rgba(0, 0, 0, 0.7)"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// 辅助函数:隐藏加载
|
|
54
|
+
const hideLoading = () => {
|
|
55
|
+
if (loadingInstance && Uts.isFunction(loadingInstance.close)) {
|
|
56
|
+
loadingInstance.close();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// 辅助函数:处理文件下载
|
|
61
|
+
const handleDownload = (blob, fullFileName) => {
|
|
62
|
+
if ("download" in document.createElement("a")) {
|
|
63
|
+
const elink = document.createElement("a");
|
|
64
|
+
elink.style.display = "none";
|
|
65
|
+
elink.href = URL.createObjectURL(blob);
|
|
66
|
+
elink.download = fullFileName;
|
|
67
|
+
document.body.appendChild(elink);
|
|
68
|
+
elink.click();
|
|
69
|
+
URL.revokeObjectURL(elink.href);
|
|
70
|
+
document.body.removeChild(elink);
|
|
71
|
+
} else {
|
|
72
|
+
// IE10+下载
|
|
73
|
+
navigator.msSaveBlob(blob, fullFileName);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
// 2. 确认框
|
|
79
|
+
if (MessageBox && Uts.isFunction(MessageBox.confirm)) {
|
|
80
|
+
await MessageBox.confirm("导出筛选后的所有文件, 是否继续?", "提示", {
|
|
81
|
+
confirmButtonText: "确定",
|
|
82
|
+
cancelButtonText: "取消",
|
|
83
|
+
type: "warning"
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
showLoading(); // 显示加载
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
// 3. 请求文件流
|
|
91
|
+
const requestConfig = {
|
|
92
|
+
responseType: "arraybuffer",
|
|
93
|
+
timeout: 0
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
let res;
|
|
97
|
+
if (reqMethod === "get") {
|
|
98
|
+
res = await request.get(url, { ...params, ...requestConfig });
|
|
99
|
+
} else if (reqMethod === "post") {
|
|
100
|
+
res = await request.post(url, params, requestConfig);
|
|
101
|
+
} else {
|
|
102
|
+
console.warn(`exportFile: 不支持的请求方法 '${reqMethod}'`);
|
|
103
|
+
showMessage("error", "导出失败:不支持的请求方法!");
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const blob = new Blob([res], { type: "application/octet-stream" });
|
|
108
|
+
const fullFileName = `${fileName}_${new Date().toISOString().slice(0, 10)}${suffix}`;
|
|
109
|
+
|
|
110
|
+
handleDownload(blob, fullFileName); // 处理文件下载
|
|
111
|
+
showMessage("success", "文件导出成功!");
|
|
112
|
+
} catch (err) {
|
|
113
|
+
console.error("导出错误:", err);
|
|
114
|
+
const { response } = err || {};
|
|
115
|
+
const { status, statusText } = response || {};
|
|
116
|
+
|
|
117
|
+
if (status === 403 || statusText === "Forbidden") {
|
|
118
|
+
showMessage("error", "无操作权限!");
|
|
119
|
+
} else if (status === 404) {
|
|
120
|
+
showMessage("error", "导出地址未找到!");
|
|
121
|
+
} else if (err.message && err.message.includes("timeout")) {
|
|
122
|
+
showMessage("error", "导出超时,请稍后再试!");
|
|
123
|
+
} else {
|
|
124
|
+
showMessage("error", "导出异常,请稍后再试!");
|
|
125
|
+
}
|
|
126
|
+
} finally {
|
|
127
|
+
hideLoading(); // 隐藏加载
|
|
128
|
+
}
|
|
129
|
+
} catch (err) {
|
|
130
|
+
// 捕获 MessageBox.confirm 的取消操作
|
|
131
|
+
if (err === "cancel") {
|
|
132
|
+
showMessage("info", "已取消导出");
|
|
133
|
+
} else {
|
|
134
|
+
console.error("导出流程中断:", err);
|
|
135
|
+
showMessage("error", "导出流程异常中断!");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
exportFile
|
|
142
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 覆盖写入构建脚本
|
|
6
|
+
* @param {String} filePath - 覆盖文件路径
|
|
7
|
+
* @param {Array | Object} scriptsList - 写入脚本配置
|
|
8
|
+
* @param {String} 更新字段值
|
|
9
|
+
*/
|
|
10
|
+
function scriptWrite(filePath, scriptsList, updateKey = "scripts") {
|
|
11
|
+
const pkg = JSON.parse(fs.readFileSync(filePath));
|
|
12
|
+
pkg[updateKey] = pkg[updateKey] || {};
|
|
13
|
+
if (Array.isArray(scriptsList)) {
|
|
14
|
+
scriptsList.forEach(item => {
|
|
15
|
+
pkg[updateKey][item.key] = item.value;
|
|
16
|
+
});
|
|
17
|
+
} else if (typeof scriptsList === "object") {
|
|
18
|
+
pkg[updateKey] = scriptsList;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
fs.writeFileSync(filePath, JSON.stringify(pkg, null, 2));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 获取文件绝对路径
|
|
26
|
+
* @param {String} filePath - 文件路径
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
function targetProjectFileResolve(filePath) {
|
|
30
|
+
// 初始脚本自动执行路径会自动读取node_modules
|
|
31
|
+
const projectRoot = process.cwd();
|
|
32
|
+
const absoluteProjectRoot = projectRoot.replace(/\\node_modules.*$/g, "");
|
|
33
|
+
return path.resolve(absoluteProjectRoot, filePath);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 获取文件绝对路径
|
|
38
|
+
* @param {String} filePath - 文件路径
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
function currentProjectFileResolve(filePath) {
|
|
42
|
+
return path.join(__dirname, filePath);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
scriptWrite,
|
|
47
|
+
targetProjectFileResolve,
|
|
48
|
+
currentProjectFileResolve
|
|
49
|
+
};
|
package/tools/format.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具函数集合
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 处理金额显示,限制显示长度
|
|
7
|
+
* @param {string} floor_amount - 金额字符串,用分号分隔
|
|
8
|
+
* @param {number} length - 显示长度
|
|
9
|
+
* @returns {object} 返回包含 vHtml 和 length 的对象
|
|
10
|
+
*/
|
|
11
|
+
function handleFlowAmount(floor_amount = "", length) {
|
|
12
|
+
if (!floor_amount) {
|
|
13
|
+
return {
|
|
14
|
+
vHtml: "",
|
|
15
|
+
length: 0
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const array = floor_amount.split(";");
|
|
20
|
+
const limitedArray = array.slice(0, length);
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
vHtml: limitedArray.join("<br>"),
|
|
24
|
+
length: array.length
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default {
|
|
29
|
+
handleFlowAmount
|
|
30
|
+
};
|
|
31
|
+
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const net = require("net");
|
|
4
|
+
const { execSync } = require("child_process");
|
|
5
|
+
|
|
6
|
+
const { scriptWrite } = require("./file-process.js");
|
|
7
|
+
const { previewList } = require("../script");
|
|
8
|
+
|
|
9
|
+
const projectRoot = process.cwd().replace(/\\node_modules.*$/g, "");
|
|
10
|
+
const projectPkgPath = path.resolve(projectRoot, "package.json");
|
|
11
|
+
const projectVueConfigPath = path.resolve(projectRoot, "vue.config.js");
|
|
12
|
+
const projectConfig = fs.existsSync(projectVueConfigPath) ? require(projectVueConfigPath) : {};
|
|
13
|
+
const rawArgv = process.argv.slice(2);
|
|
14
|
+
const args = rawArgv.join(" ");
|
|
15
|
+
|
|
16
|
+
const DEFAULT_CONFIG = {
|
|
17
|
+
port: 9001,
|
|
18
|
+
publicPath: "/",
|
|
19
|
+
outputDir: "dist"
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function scriptInit() {
|
|
23
|
+
if (fs.existsSync(projectVueConfigPath)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
scriptWrite(projectPkgPath, previewList);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 检查端口是否可用
|
|
31
|
+
* @param {number} port - 端口号
|
|
32
|
+
* @returns {Promise<boolean>} - 端口是否可用
|
|
33
|
+
*/
|
|
34
|
+
function isPortAvailable(port) {
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
const server = net.createServer();
|
|
37
|
+
|
|
38
|
+
server.listen(port, () => {
|
|
39
|
+
server.once('close', () => {
|
|
40
|
+
resolve(true);
|
|
41
|
+
});
|
|
42
|
+
server.close();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
server.on('error', () => {
|
|
46
|
+
resolve(false);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 查找可用端口
|
|
53
|
+
* @param {number} startPort - 起始端口
|
|
54
|
+
* @param {number} maxTries - 最大尝试次数
|
|
55
|
+
* @returns {Promise<number>} - 可用端口
|
|
56
|
+
*/
|
|
57
|
+
async function findAvailablePort(startPort, maxTries = 10) {
|
|
58
|
+
for (let i = 0; i < maxTries; i++) {
|
|
59
|
+
const port = startPort + i;
|
|
60
|
+
const available = await isPortAvailable(port);
|
|
61
|
+
|
|
62
|
+
if (available) {
|
|
63
|
+
if (i > 0) {
|
|
64
|
+
console.log(global.logColor.warning, `⚠️ 端口 ${startPort} 被占用,使用端口 ${port}`);
|
|
65
|
+
}
|
|
66
|
+
return port;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
throw new Error(`无法找到可用端口,已尝试从 ${startPort} 到 ${startPort + maxTries - 1}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function init(skipBuild = false) {
|
|
74
|
+
try {
|
|
75
|
+
const { connect } = require("../lib/server/connect");
|
|
76
|
+
const { serveStatic } = require("../lib/server/serve-static");
|
|
77
|
+
const app = connect();
|
|
78
|
+
const noBuild = skipBuild || rawArgv.includes("--no-build");
|
|
79
|
+
const { devServer } = projectConfig || {};
|
|
80
|
+
const { port: devServerPort } = devServer || {};
|
|
81
|
+
projectConfig.port = devServerPort || DEFAULT_CONFIG.port;
|
|
82
|
+
const { publicPath, outputDir, port } = {
|
|
83
|
+
...DEFAULT_CONFIG,
|
|
84
|
+
...projectConfig
|
|
85
|
+
};
|
|
86
|
+
const baseListenPort = port - 1000;
|
|
87
|
+
|
|
88
|
+
if (!noBuild) {
|
|
89
|
+
buildProject();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ✅ 查找可用端口
|
|
93
|
+
const listenPort = await findAvailablePort(baseListenPort);
|
|
94
|
+
|
|
95
|
+
app.use(
|
|
96
|
+
publicPath,
|
|
97
|
+
serveStatic(outputDir, {
|
|
98
|
+
index: ["index.html", "/"]
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const server = app.listen(listenPort, function () {
|
|
103
|
+
console.log(global.logColor.success, `\x1b[42m\x1b[30m DONE \x1b[0m\x1b[32m 项目构建预览,CTRL + C结束:`);
|
|
104
|
+
console.log(global.logColor.link, `http://localhost:${listenPort}${publicPath}`);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// ✅ 处理服务器启动错误
|
|
108
|
+
server.on('error', (error) => {
|
|
109
|
+
if (error.code === 'EADDRINUSE') {
|
|
110
|
+
console.log(global.logColor.error, `❌ 端口 ${listenPort} 仍然被占用`);
|
|
111
|
+
} else {
|
|
112
|
+
console.log(global.logColor.error, `❌ 服务器启动失败:${error.message}`);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
return server;
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.log(global.logColor.error, `❌ 预览项目失败:${error.message}`);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function buildProject() {
|
|
124
|
+
try {
|
|
125
|
+
execSync(`vue-cli-service build ${args}`, { stdio: "inherit" });
|
|
126
|
+
} catch (err) {
|
|
127
|
+
console.error(global.logColor.error, "❌ 构建失败:", err.message);
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
module.exports = {
|
|
133
|
+
init,
|
|
134
|
+
scriptInit
|
|
135
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// 去掉方便开发直接进入引用文件
|
|
2
|
+
declare module "infly-libs/module/Uts" {
|
|
3
|
+
const Uts: any;
|
|
4
|
+
export default Uts;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare module "infly-libs/module/Uts.js" {
|
|
8
|
+
const Uts: any;
|
|
9
|
+
export default Uts;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare module "infly-libs/dataInit/marketingActivitiesMap" {
|
|
13
|
+
const marketingActivitiesMap: any;
|
|
14
|
+
export default marketingActivitiesMap;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare module "infly-libs/dataInit/marketingActivitiesMap.js" {
|
|
18
|
+
const marketingActivitiesMap: any;
|
|
19
|
+
export default marketingActivitiesMap;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare module "infly-libs/dataInit/settlementMap" {
|
|
23
|
+
const settlementMap: any;
|
|
24
|
+
export default settlementMap;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare module "infly-libs/dataInit/settlementMap.js" {
|
|
28
|
+
const settlementMap: any;
|
|
29
|
+
export default settlementMap;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare module "infly-libs/dataInit/commonTypeMap" {
|
|
33
|
+
const commonTypeMap: any;
|
|
34
|
+
export default commonTypeMap;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
declare module "infly-libs/dataInit/commonTypeMap.js" {
|
|
38
|
+
const commonTypeMap: any;
|
|
39
|
+
export default commonTypeMap;
|
|
40
|
+
}
|
|
41
|
+
declare module "infly-libs/tools/format" {
|
|
42
|
+
const FormatTools: any;
|
|
43
|
+
export default FormatTools;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare module "infly-libs/tools/format.js" {
|
|
47
|
+
const FormatTools: any;
|
|
48
|
+
export default FormatTools;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare module "infly-libs/module/REST" {
|
|
52
|
+
const REST: any;
|
|
53
|
+
export default REST;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare module "infly-libs/module/REST.js" {
|
|
57
|
+
const REST: any;
|
|
58
|
+
export default REST;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
declare module "infly-libs/module/Permission" {
|
|
62
|
+
// 根据实际导出内容细化类型,这里先用 any
|
|
63
|
+
const Permission: any;
|
|
64
|
+
export default Permission;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare module "infly-libs/module/Permission.js" {
|
|
68
|
+
// 根据实际导出内容细化类型,这里先用 any
|
|
69
|
+
const Permission: any;
|
|
70
|
+
export default Permission;
|
|
71
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 用于将一些常用的库打包压缩成模块文件 libs/ 而不依赖node_modules
|
|
3
|
+
*/
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const nodeExternals = require("webpack-node-externals");
|
|
6
|
+
|
|
7
|
+
const libName = "connect";
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
mode: "production",
|
|
11
|
+
target: "node", // 关键配置:生成Node环境兼容代码
|
|
12
|
+
entry: "./lib/index.js",
|
|
13
|
+
output: {
|
|
14
|
+
filename: `${libName}.js`,
|
|
15
|
+
path: path.resolve(__dirname, "lib/server"),
|
|
16
|
+
libraryTarget: "commonjs2" // 符合Node模块规范
|
|
17
|
+
},
|
|
18
|
+
externals: [
|
|
19
|
+
nodeExternals({
|
|
20
|
+
allowlist: [libName], // 强制打包含路径操作的模块
|
|
21
|
+
modulesFromFile: true // 自动读取package.json的dependencies
|
|
22
|
+
})
|
|
23
|
+
],
|
|
24
|
+
module: {
|
|
25
|
+
rules: [
|
|
26
|
+
{
|
|
27
|
+
test: /\.js$/,
|
|
28
|
+
exclude: new RegExp(`/node_modules\\/(?!(${libName})\\/).*`), // 仅编译目标模块
|
|
29
|
+
use: "babel-loader" // 可选:如需语法降级
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
optimization: {
|
|
34
|
+
splitChunks: false, // 关闭代码分割
|
|
35
|
+
runtimeChunk: false, // 禁用runtime文件生成
|
|
36
|
+
minimize: false // 关闭代码压缩
|
|
37
|
+
}
|
|
38
|
+
};
|