[add] 動態讀json
This commit is contained in:
parent
84bba89e7e
commit
f8528713e6
@ -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",
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user