2022-06-17 15:10:02 +08:00
|
|
|
import fs from "fs";
|
|
|
|
import lodash from "lodash";
|
|
|
|
|
|
|
|
const _path = process.cwd();
|
2022-06-23 23:06:30 +08:00
|
|
|
const _cfgPath = `${_path}/plugins/xiaoyao-cvs-plugin/components/`;
|
2022-06-17 15:10:02 +08:00
|
|
|
let cfg = {};
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (fs.existsSync(_cfgPath + "cfg.json")) {
|
|
|
|
cfg = JSON.parse(fs.readFileSync(_cfgPath + "cfg.json", "utf8")) || {};
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// do nth
|
|
|
|
}
|
|
|
|
|
|
|
|
let Cfg = {
|
|
|
|
get(rote, def = '') {
|
|
|
|
return lodash.get(cfg, rote, def);
|
|
|
|
},
|
|
|
|
set(rote, val) {
|
|
|
|
lodash.set(cfg, rote, val);
|
|
|
|
fs.writeFileSync(_cfgPath + "cfg.json", JSON.stringify(cfg, null, "\t"));
|
|
|
|
},
|
|
|
|
scale(pct = 1) {
|
|
|
|
let scale = Cfg.get("sys.scale", 100);
|
|
|
|
scale = Math.min(2, Math.max(0.5, scale / 100));
|
|
|
|
pct = pct * scale;
|
|
|
|
return `style=transform:scale(${pct})`;
|
|
|
|
},
|
|
|
|
isDisable(e, rote) {
|
|
|
|
if (Cfg.get(rote, true)) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-06-23 23:06:30 +08:00
|
|
|
if (/^#*图鉴/.test(e.msg || "")) {
|
2022-06-17 15:10:02 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2022-09-04 22:34:33 +08:00
|
|
|
},
|
|
|
|
/** 合并默认配置和用户配置 */
|
|
|
|
merged() {
|
|
|
|
return lodash.merge({}, cfg)
|
2022-06-17 15:10:02 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Cfg;
|