215 lines
6.5 KiB
TypeScript
215 lines
6.5 KiB
TypeScript
//@ts-check
|
||
// 默认为生产
|
||
let nodeEnv = process.env.NODE_ENV || 'production';
|
||
nodeEnv = nodeEnv === 'staging' ? 'production' : nodeEnv;
|
||
|
||
/**
|
||
* - 员工数据 门店 部门 员工 姓名
|
||
* - staffData.firstStore.firstSector.employee_1.name
|
||
* - 员工数据 门店 部门 员工 手机号
|
||
* - staffData.firstStore.firstSector.employee_1.phone
|
||
* - 员工数据 门店 部门 员工 ID
|
||
* - staffData.firstStore.firstSector.employee_1.id
|
||
*/
|
||
let staffData = {
|
||
firstStore: {
|
||
firstSector: {
|
||
name: '美容部',
|
||
employee_1: {
|
||
name: '张伟',
|
||
phone: '13812345678',
|
||
id: { production: 3, test: 1 },
|
||
},
|
||
employee_2: {
|
||
name: '李娜',
|
||
phone: '13987654321',
|
||
id: { production: 4, test: 2 },
|
||
},
|
||
employee_3: {
|
||
name: '王芳',
|
||
phone: '13723456789',
|
||
id: { production: 5, test: 3 },
|
||
},
|
||
employee_4: {
|
||
name: '陈刚',
|
||
phone: '13698765432',
|
||
id: { production: 6, test: 4 },
|
||
},
|
||
employee_5: {
|
||
name: '赵军',
|
||
phone: '13512349876',
|
||
id: { production: 7, test: 5 },
|
||
},
|
||
employee_6: {
|
||
name: '刘强',
|
||
phone: '13498761234',
|
||
id: { production: 8, test: 6 },
|
||
},
|
||
employee_7: {
|
||
name: '周萍',
|
||
phone: '13365432109',
|
||
id: { production: 9, test: 7 },
|
||
},
|
||
employee_8: {
|
||
name: '吴浩',
|
||
phone: '13287654329',
|
||
id: { production: 10, test: 8 },
|
||
},
|
||
employee_9: {
|
||
name: '徐亮',
|
||
phone: '13123459876',
|
||
id: { production: 11, test: 9 },
|
||
},
|
||
employee_10: {
|
||
name: '杨雪',
|
||
phone: '13098761234',
|
||
id: { production: 12, test: 10 },
|
||
},
|
||
},
|
||
secondSector: {
|
||
name: '医美部',
|
||
employee_1: {
|
||
name: '赵伟',
|
||
phone: '13923456789',
|
||
id: { production: 13, test: 11 },
|
||
},
|
||
employee_2: {
|
||
name: '钱丽',
|
||
phone: '13898765432',
|
||
id: { production: 14, test: 12 },
|
||
},
|
||
employee_3: {
|
||
name: '孙峰',
|
||
phone: '13712349876',
|
||
id: { production: 15, test: 13 },
|
||
},
|
||
employee_4: {
|
||
name: '李涛',
|
||
phone: '13687654321',
|
||
id: { production: 16, test: 14 },
|
||
},
|
||
employee_5: {
|
||
name: '周慧',
|
||
phone: '13598761234',
|
||
id: { production: 17, test: 15 },
|
||
},
|
||
employee_6: {
|
||
name: '吴凯',
|
||
phone: '13465432109',
|
||
id: { production: 18, test: 16 },
|
||
},
|
||
employee_7: {
|
||
name: '郑翔',
|
||
phone: '13387654329',
|
||
id: { production: 19, test: 17 },
|
||
},
|
||
employee_8: {
|
||
name: '冯敏',
|
||
phone: '13223459876',
|
||
id: { production: 20, test: 18 },
|
||
},
|
||
employee_9: {
|
||
name: '朱强',
|
||
phone: '13198761234',
|
||
id: { production: 21, test: 19 },
|
||
},
|
||
employee_10: {
|
||
name: '何平',
|
||
phone: '13065432198',
|
||
id: { production: 22, test: 20 },
|
||
},
|
||
},
|
||
},
|
||
secondStore: {
|
||
name: '美容部',
|
||
firstSector: {
|
||
employee_1: {
|
||
name: '张凯',
|
||
phone: '13865432198',
|
||
id: { production: 1, test: 1 },
|
||
},
|
||
employee_2: {
|
||
name: '李军',
|
||
phone: '13923459876',
|
||
id: { production: 2, test: 2 },
|
||
},
|
||
employee_3: {
|
||
name: '王涛',
|
||
phone: '13798761234',
|
||
id: { production: 3, test: 3 },
|
||
},
|
||
employee_4: {
|
||
name: '陈敏',
|
||
phone: '13654321987',
|
||
id: { production: 4, test: 4 },
|
||
},
|
||
employee_5: {
|
||
name: '赵峰',
|
||
phone: '13523456789',
|
||
id: { production: 5, test: 5 },
|
||
},
|
||
employee_6: {
|
||
name: '刘丽',
|
||
phone: '13487654321',
|
||
id: { production: 6, test: 6 },
|
||
},
|
||
employee_7: {
|
||
name: '周亮',
|
||
phone: '13398765432',
|
||
id: { production: 7, test: 7 },
|
||
},
|
||
employee_8: {
|
||
name: '吴平',
|
||
phone: '13212349876',
|
||
id: { production: 8, test: 8 },
|
||
},
|
||
employee_9: {
|
||
name: '徐浩',
|
||
phone: '13165432109',
|
||
id: { production: 9, test: 9 },
|
||
},
|
||
employee_10: {
|
||
name: '孙杰',
|
||
phone: '13087654329',
|
||
id: { production: 10, test: 10 },
|
||
},
|
||
},
|
||
},
|
||
};
|
||
|
||
/**
|
||
*
|
||
* @param {Object} staffData
|
||
* @param {string} nodeEnv
|
||
* @returns
|
||
*/
|
||
function init(staffData, nodeEnv) {
|
||
const updatedData = JSON.parse(JSON.stringify(staffData)); // 深拷贝对象,避免修改原数据
|
||
|
||
function updateIds(sector) {
|
||
Object.keys(sector).forEach(key => {
|
||
const employee = sector[key];
|
||
if (employee && employee.id && employee.id[nodeEnv] !== undefined) {
|
||
employee.id = employee.id[nodeEnv]; // 将 id 替换为 production 或 test 的值
|
||
}
|
||
});
|
||
}
|
||
|
||
// 遍历 firstStore 和 secondStore 下的各个 sector,更新员工的 id
|
||
Object.keys(updatedData).forEach(storeKey => {
|
||
const store = updatedData[storeKey];
|
||
Object.keys(store).forEach(sectorKey => {
|
||
const sector = store[sectorKey];
|
||
if (typeof sector === 'object' && sector !== null && sector.name) {
|
||
updateIds(sector); // 更新每个 sector 的员工 id
|
||
}
|
||
});
|
||
});
|
||
|
||
return updatedData; // 返回更新后的数据
|
||
}
|
||
|
||
staffData = init(staffData, nodeEnv);
|
||
|
||
export { staffData };
|