[add] 動態讀json

This commit is contained in:
建喵 2024-08-30 15:54:25 +08:00
parent 84bba89e7e
commit f8528713e6
3 changed files with 11 additions and 4 deletions

View File

@ -20,7 +20,13 @@
], ],
"directories": { "directories": {
"output": "release" "output": "release"
} },
"extraFiles": [
{
"from": "shared",
"to": "resources/shared"
}
]
}, },
"dependencies": { "dependencies": {
"dayjs": "^1.11.13", "dayjs": "^1.11.13",

View File

@ -1,4 +1,3 @@
import { app } from 'electron';
import path from 'path'; import path from 'path';
export function getExternalJsonPath(filename: string): string { export function getExternalJsonPath(filename: string): string {
@ -7,6 +6,8 @@ export function getExternalJsonPath(filename: string): string {
return path.join(__dirname, '../../shared/jsons', filename); return path.join(__dirname, '../../shared/jsons', filename);
} else { } else {
// 生产模式下使用外部路径 // 生产模式下使用外部路径
return path.join(app.getPath('userData'), 'jsons', filename); const filepath = path.join(__dirname, `../../../shared/jsons/${filename}`);
// console.log('filepath', filepath);
return filepath;
} }
} }

View File

@ -110,7 +110,7 @@ export default abstract class SlotSpinBase {
protected async GetTemps(): Promise<any> { protected async GetTemps(): Promise<any> {
const filePath = getExternalJsonPath(`slot${this.ID}.json`); const filePath = getExternalJsonPath(`slot${this.ID}.json`);
console.log('filePath', filePath); // console.log('filePath', filePath);
const data = await fs.promises.readFile(filePath, 'utf-8'); const data = await fs.promises.readFile(filePath, 'utf-8');
const jsonData = JSON.parse(data); const jsonData = JSON.parse(data);
return jsonData; return jsonData;