UNPKG

@antmove/alipay-wx

Version:

transform alipay miniprogram to wx miniprogram tool.

61 lines (54 loc) 1.51 kB
const appJson = require('../config/jsonInfo/globalconfig'); /** * app config process */ const tabbarConfigMap = {}; const windowConfigMap = {}; const windowProps = appJson.window.props; const tabBarProps = appJson.tabBar.props; mkJsonMap(windowProps, windowConfigMap); mkJsonMap(tabBarProps, tabbarConfigMap); mkJsonMap(tabBarProps.items.props, tabbarConfigMap); function mkJsonMap (props, targetJson) { Object.keys(props) .forEach(function (prop) { let value = props[prop]; if (value.type === 1) { targetJson[prop] = value.msg; } }); } module.exports = function (str) { let tabBar; let json = JSON.parse(str); tabBar = json.tabBar; if (tabBar) { replaceTheKey(tabBar, tabbarConfigMap); let list = tabBar.list || []; list.forEach(el => { for ( let key in el) { if (tabbarConfigMap[key]) { el[tabbarConfigMap[key]] = el[key]; delete el[key]; } } }); } replaceTheKey(json.window, windowConfigMap); return JSON.stringify(json); }; /** * replace key of object */ function replaceTheKey (obj, configMap) { if (!obj) return false; Object.keys(obj) .forEach(function (key) { let _key = configMap[key]; if (_key) { obj[_key] = obj[key]; delete obj[key]; } }); return obj; }