|
@@ -33,102 +33,102 @@ let INTERFACE_EXPORT = {};
|
|
|
let INTERFACE_IMPORT = {};
|
|
let INTERFACE_IMPORT = {};
|
|
|
|
|
|
|
|
const STD_INTERFACE = (() => {
|
|
const STD_INTERFACE = (() => {
|
|
|
- 'use strict';
|
|
|
|
|
|
|
+ 'use strict';
|
|
|
|
|
|
|
|
- // 根据地区配置,初始化地区选项
|
|
|
|
|
- function initExportAreas($parentAreas, $subAreas) {
|
|
|
|
|
- const connectedAreas = Object.keys(INTERFACE_CONFIG);
|
|
|
|
|
- const parentMap = {};
|
|
|
|
|
- connectedAreas.forEach(connectedArea => {
|
|
|
|
|
- const areas = connectedArea.split('@');
|
|
|
|
|
- (parentMap[areas[0]] || (parentMap[areas[0]] = [])).push(areas[1]);
|
|
|
|
|
- });
|
|
|
|
|
- const parentAreasHtml = Object
|
|
|
|
|
- .keys(parentMap)
|
|
|
|
|
- .reduce((acc, area) => acc += `<option value="${area}">${area}</option>`, '');
|
|
|
|
|
- $parentAreas.html(parentAreasHtml);
|
|
|
|
|
- const subAreasHtml = parentMap[Object.keys(parentMap)[0]].reduce((acc, area) => acc += `<option value="${area}">${area}</option>`, '');
|
|
|
|
|
- $subAreas.html(subAreasHtml);
|
|
|
|
|
- // 父级地区变更,子地区选项更新
|
|
|
|
|
- $parentAreas.change(function () {
|
|
|
|
|
- EXPORT_VIEW.resetState(); // 清空接口缓存
|
|
|
|
|
- const curArea = $(this).val();
|
|
|
|
|
- const subAreasHtml = parentMap[curArea].reduce((acc, area) => acc += `<option value="${area}">${area}</option>`, '');
|
|
|
|
|
- $subAreas.html(subAreasHtml);
|
|
|
|
|
- });
|
|
|
|
|
- $subAreas.change(function() {
|
|
|
|
|
- EXPORT_VIEW.resetState();
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 根据地区配置,初始化地区选项
|
|
|
|
|
+ function initExportAreas($parentAreas, $subAreas) {
|
|
|
|
|
+ const connectedAreas = Object.keys(INTERFACE_CONFIG);
|
|
|
|
|
+ const parentMap = {};
|
|
|
|
|
+ connectedAreas.forEach(connectedArea => {
|
|
|
|
|
+ const areas = connectedArea.split('@');
|
|
|
|
|
+ (parentMap[areas[0]] || (parentMap[areas[0]] = [])).push(areas[1]);
|
|
|
|
|
+ });
|
|
|
|
|
+ const parentAreasHtml = Object
|
|
|
|
|
+ .keys(parentMap)
|
|
|
|
|
+ .reduce((acc, area) => acc += `<option value="${area}">${area}</option>`, '');
|
|
|
|
|
+ $parentAreas.html(parentAreasHtml);
|
|
|
|
|
+ const subAreasHtml = parentMap[Object.keys(parentMap)[0]].reduce((acc, area) => acc += `<option value="${area}">${area}</option>`, '');
|
|
|
|
|
+ $subAreas.html(subAreasHtml);
|
|
|
|
|
+ // 父级地区变更,子地区选项更新
|
|
|
|
|
+ $parentAreas.change(function () {
|
|
|
|
|
+ EXPORT_VIEW.resetState(); // 清空接口缓存
|
|
|
|
|
+ const curArea = $(this).val();
|
|
|
|
|
+ const subAreasHtml = parentMap[curArea].reduce((acc, area) => acc += `<option value="${area}">${area}</option>`, '');
|
|
|
|
|
+ $subAreas.html(subAreasHtml);
|
|
|
|
|
+ });
|
|
|
|
|
+ $subAreas.change(function () {
|
|
|
|
|
+ EXPORT_VIEW.resetState();
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 动态加载script
|
|
|
|
|
- * 由于后续的接口可能会非常多,一次性加载所有的接口文件完全没必要,而且不可控,很容易导致初次加载速度变慢。
|
|
|
|
|
- * 在选定相关地区后,再根据地区对应的script路径,动态加载script
|
|
|
|
|
- * 不需要缓存,缓存可能会影响正常操作的性能。而且导入导出时动态获取接口文件的需要的时间,客户是不可感知的。
|
|
|
|
|
- * @param {String} path - 需要加载的scipt路径
|
|
|
|
|
- * @return {Promise}
|
|
|
|
|
- */
|
|
|
|
|
- function loadScript(path) {
|
|
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
|
- const scriptID = 'interface-script';
|
|
|
|
|
- const body = document.getElementsByTagName('body')[0];
|
|
|
|
|
- // 移除原来的
|
|
|
|
|
- const orgScript = document.getElementById(scriptID);
|
|
|
|
|
- if (orgScript) {
|
|
|
|
|
- body.removeChild(orgScript);
|
|
|
|
|
- }
|
|
|
|
|
- // 增加新的
|
|
|
|
|
- const script = document.createElement('script');
|
|
|
|
|
- script.src = path;
|
|
|
|
|
- script.type = 'text/javascript';
|
|
|
|
|
- script.id = scriptID;
|
|
|
|
|
- body.appendChild(script);
|
|
|
|
|
- script.onload = script.onreadystatechange = function () { // ie、ff触发事件不同,都写上
|
|
|
|
|
- if (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete') {
|
|
|
|
|
- script.onload = script.onreadystatechange = null;
|
|
|
|
|
- resolve();
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
- script.onerror = function () {
|
|
|
|
|
- reject('script加载失败。');
|
|
|
|
|
- };
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 动态加载script
|
|
|
|
|
+ * 由于后续的接口可能会非常多,一次性加载所有的接口文件完全没必要,而且不可控,很容易导致初次加载速度变慢。
|
|
|
|
|
+ * 在选定相关地区后,再根据地区对应的script路径,动态加载script
|
|
|
|
|
+ * 不需要缓存,缓存可能会影响正常操作的性能。而且导入导出时动态获取接口文件的需要的时间,客户是不可感知的。
|
|
|
|
|
+ * @param {String} path - 需要加载的scipt路径
|
|
|
|
|
+ * @return {Promise}
|
|
|
|
|
+ */
|
|
|
|
|
+ function loadScript(path) {
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
|
+ const scriptID = 'interface-script';
|
|
|
|
|
+ const body = document.getElementsByTagName('body')[0];
|
|
|
|
|
+ // 移除原来的
|
|
|
|
|
+ const orgScript = document.getElementById(scriptID);
|
|
|
|
|
+ if (orgScript) {
|
|
|
|
|
+ body.removeChild(orgScript);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 增加新的
|
|
|
|
|
+ const script = document.createElement('script');
|
|
|
|
|
+ script.src = path;
|
|
|
|
|
+ script.type = 'text/javascript';
|
|
|
|
|
+ script.id = scriptID;
|
|
|
|
|
+ body.appendChild(script);
|
|
|
|
|
+ script.onload = script.onreadystatechange = function () { // ie、ff触发事件不同,都写上
|
|
|
|
|
+ if (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete') {
|
|
|
|
|
+ script.onload = script.onreadystatechange = null;
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ script.onerror = function () {
|
|
|
|
|
+ reject('script加载失败。');
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- const ScriptType = {
|
|
|
|
|
- EXPORT: 'export',
|
|
|
|
|
- IMPORT: 'import',
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ const ScriptType = {
|
|
|
|
|
+ EXPORT: 'export',
|
|
|
|
|
+ IMPORT: 'import',
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- let curArea = '';
|
|
|
|
|
- /**
|
|
|
|
|
- * 根据地区和脚本类型加载脚本
|
|
|
|
|
- * @param {String} area - 地区选项 eg: '安徽省@马鞍山'
|
|
|
|
|
- * @param {Number} scriptType - 脚本类型
|
|
|
|
|
- * @return {Void}
|
|
|
|
|
- */
|
|
|
|
|
- async function loadScriptByArea(area, scriptType) {
|
|
|
|
|
- if (area === curArea) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- curArea = area;
|
|
|
|
|
- const configItem = INTERFACE_CONFIG[area];
|
|
|
|
|
- if (!configItem) {
|
|
|
|
|
- throw new Error(`[${area}]不存在有效配置。`);
|
|
|
|
|
- }
|
|
|
|
|
- const scriptName = configItem.scriptName;
|
|
|
|
|
- if (!scriptName) {
|
|
|
|
|
- throw new Error(`[${area}]不存在有效脚本。`);
|
|
|
|
|
- }
|
|
|
|
|
- const fullPath = `/web/building_saas/standard_interface/${scriptType}/${scriptName}`;
|
|
|
|
|
- await loadScript(fullPath);
|
|
|
|
|
|
|
+ let curArea = '';
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据地区和脚本类型加载脚本
|
|
|
|
|
+ * @param {String} area - 地区选项 eg: '安徽省@马鞍山'
|
|
|
|
|
+ * @param {Number} scriptType - 脚本类型
|
|
|
|
|
+ * @return {Void}
|
|
|
|
|
+ */
|
|
|
|
|
+ async function loadScriptByArea(area, scriptType) {
|
|
|
|
|
+ if (area === curArea) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ curArea = area;
|
|
|
|
|
+ const configItem = INTERFACE_CONFIG[area];
|
|
|
|
|
+ if (!configItem) {
|
|
|
|
|
+ throw new Error(`[${area}]不存在有效配置。`);
|
|
|
|
|
+ }
|
|
|
|
|
+ const scriptName = configItem.scriptName;
|
|
|
|
|
+ if (!scriptName) {
|
|
|
|
|
+ throw new Error(`[${area}]不存在有效脚本。`);
|
|
|
}
|
|
}
|
|
|
|
|
+ const fullPath = `/web/building_saas/standard_interface/${scriptType}/${scriptName}`;
|
|
|
|
|
+ await loadScript(fullPath);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- return {
|
|
|
|
|
- initExportAreas,
|
|
|
|
|
- ScriptType,
|
|
|
|
|
- loadScriptByArea,
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ return {
|
|
|
|
|
+ initExportAreas,
|
|
|
|
|
+ ScriptType,
|
|
|
|
|
+ loadScriptByArea,
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
})();
|
|
})();
|