211 lines
9.1 KiB
JavaScript
211 lines
9.1 KiB
JavaScript
define(['angular', 'angularAMD', 'app', 'text!config/config.json', 'moment', 'd3'],
|
|
function (angular, angularAMD, app, config) {
|
|
'use strict';
|
|
config = JSON.parse(config);
|
|
config.menu = [];
|
|
config.program = [];
|
|
config.cache = config.cache || {};
|
|
|
|
//20201005 雋辰,確保客製module在最後一個
|
|
var index = config.module.indexOf("moduleCustomer");
|
|
if (index >= 0) {
|
|
var tmpItems = config.module.splice(index, 1);
|
|
config.module.splice(config.module.length, 0, tmpItems[0]);
|
|
}
|
|
|
|
var mergeConfig = function(menus, module_menus){
|
|
if(module_menus.length>0){
|
|
module_menus.forEach(function(module_menu){
|
|
var isMerge = false;
|
|
if(menus.length>0){
|
|
for(var i in menus){
|
|
if(menus[i].name === module_menu.name){
|
|
menus[i] = module_menu;
|
|
isMerge = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if(!isMerge){
|
|
menus.push(module_menu);
|
|
}
|
|
});
|
|
}
|
|
return menus;
|
|
}
|
|
|
|
//20201005 雋辰,處理客製menu、program
|
|
var mergeConfigMenu = function (menus, module_menus) {
|
|
//module - moduleItem - page
|
|
if (module_menus.length > 0) {
|
|
module_menus.forEach(function (module_menu) {
|
|
if (menus.length > 0) {
|
|
for (var i in menus) {
|
|
//如果無相同module不進行動作 , 禁止客製新模組 只可新item、page
|
|
if (menus[i].name === module_menu.name) {
|
|
var subFlag = false;
|
|
//存在childs即為menu 否則為 program
|
|
if (menus[i].childs && module_menu.childs) {
|
|
module_menu.childs.forEach(moduleItem => {
|
|
var child = menus[i].childs.filter(item=> {
|
|
return moduleItem.name == item.name;
|
|
});
|
|
//在此module下 不存在相同 item
|
|
if (child.length <= 0) {
|
|
menus[i].childs.push(moduleItem);
|
|
menus[i].childs[menus[i].childs.length - 1].isCustom = true;
|
|
}
|
|
else {
|
|
//在此module下 存在相同 item , 須將 成員(欄位) 等於 客製的成員(欄位)值
|
|
child[0].isCustom = true;
|
|
child[0].title = moduleItem.title;
|
|
child[0].icon = moduleItem.icon;
|
|
child[0].enTitle = moduleItem.enTitle;
|
|
child[0].color = moduleItem.color;
|
|
child[0].isShow = moduleItem.isShow;
|
|
child[0].order = moduleItem.order;
|
|
child[0].default = moduleItem.default;
|
|
|
|
//處理page
|
|
moduleItem.childs.forEach(itemPage=> {
|
|
var index = -1;
|
|
var page = child[0].childs.filter(function (orgItemPage, pageIndex) {
|
|
if (itemPage.name == orgItemPage.name) index = pageIndex;
|
|
return itemPage.name == orgItemPage.name;
|
|
});
|
|
if (page.length <= 0) {
|
|
child[0].childs.push(itemPage);
|
|
child[0].childs[child[0].childs.length - 1].isCustom = true;
|
|
}
|
|
else {
|
|
child[0].childs[index] = itemPage;
|
|
child[0].childs[index].isCustom = true;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
return menus;
|
|
}
|
|
var mergeConfigProgram = function (programs, module_programs) {
|
|
if (module_programs.length > 0) {
|
|
module_programs.forEach(function (module_program) {
|
|
var isMerge = false;
|
|
module_program.isCustom = true;
|
|
if (programs.length > 0) {
|
|
for (var i in programs) {
|
|
if (programs[i].name === module_program.name) {
|
|
programs[i] = module_program;
|
|
isMerge = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (!isMerge) {
|
|
programs.push(module_program);
|
|
}
|
|
});
|
|
}
|
|
return programs;
|
|
},
|
|
loadSetting = function(i, callback){
|
|
var menuPath = 'text!module/'+config.module[i]+'/config/menu.json';
|
|
var programPath = 'text!module/'+config.module[i]+'/config/program.json';
|
|
require([menuPath, programPath], function (module_menu, module_program) {
|
|
//20210531 13871,客製為特殊的取代方式
|
|
if (config.module[i] == "moduleCustomer") {
|
|
if (module_menu !== '')
|
|
config.menu = mergeConfigMenu(config.menu, JSON.parse(module_menu));
|
|
if (module_program !== '')
|
|
config.program = mergeConfigProgram(config.program, JSON.parse(module_program));
|
|
}
|
|
else {
|
|
if (module_menu !== '')
|
|
config.menu = mergeConfig(config.menu, JSON.parse(module_menu));
|
|
if (module_program !== '')
|
|
config.program = mergeConfig(config.program, JSON.parse(module_program));
|
|
}
|
|
|
|
i = i+1;
|
|
if(i<config.module.length){
|
|
loadSetting(i, callback);
|
|
} else {
|
|
app.constant('config', config).constant('config_menu', config.menu);
|
|
callback();
|
|
}
|
|
}, function(e){
|
|
alert('can\'t load module ' + config.module[i] +'\r\n'+ e);
|
|
i = i+1;
|
|
if(i<config.module.length){
|
|
loadSetting(i, callback);
|
|
} else {
|
|
app.constant('config', config).constant('config_menu', config.menu);
|
|
callback();
|
|
}
|
|
});
|
|
},
|
|
onDeviceReady = function () {
|
|
angularAMD.bootstrap(app);
|
|
},
|
|
ExcuteConfig = function(i, callback){
|
|
var configPath = 'module/'+config.module[i]+'/config/config';
|
|
require([configPath], function(){
|
|
i = i+1;
|
|
if(i<config.module.length){
|
|
ExcuteConfig(i, callback);
|
|
} else {
|
|
callback();
|
|
}
|
|
}, function(){
|
|
//console.error('module '+config.module[i]+' didn\'t have config.js');
|
|
i = i+1;
|
|
if(i<config.module.length){
|
|
ExcuteConfig(i, callback);
|
|
} else {
|
|
callback();
|
|
}
|
|
});
|
|
},
|
|
bootstrap = function(callback){
|
|
require(['sys-config','sys-common','sys-menu', 'module/system/service/MMWService', 'cus-common',
|
|
'module/system/program/mms03_system_home/RouterExtendProvider'], callback);
|
|
};
|
|
|
|
loadSetting(0, function(){
|
|
bootstrap(function(){
|
|
ExcuteConfig(0, function(){
|
|
if (typeof cordova === 'undefined') {
|
|
//非APP的啟動
|
|
angular.element().ready(function () {
|
|
try {
|
|
onDeviceReady();
|
|
} catch (e) {
|
|
console.error(e.stack || e.message || e);
|
|
}
|
|
});
|
|
} else {
|
|
//裝置上運行時的啟動
|
|
//因為已經運行了startup.js, 所以已經deviceready了
|
|
//document.addEventListener('deviceready', onDeviceReady, false);
|
|
//進行裝置方向的鎖定
|
|
if(config.cache.device!='phone'){
|
|
var orientation = screen.msOrientation || (screen.orientation || screen.mozOrientation || {}).type;
|
|
if(screen.lockOrientation!=undefined)
|
|
screen.lockOrientation(orientation);
|
|
else if(screen.orientation.lock)
|
|
screen.orientation.lock(orientation);
|
|
//screen.orientation.lock(screen.orientation.type);
|
|
}
|
|
onDeviceReady();
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|