@lcap/asl
Version:
NetEase Application Specific Language
73 lines (66 loc) • 2.41 kB
text/typescript
import { blockService } from '../assets';
import config from '../../types/config';
export interface TemplateItem {
text: string;
value: string;
screenshots?: string;
}
/**
* 页面区块
* @TODO 之后没有文件服务器了,所以后面需要改到区块接口中
* @TODO 另外 nodejs 下不支持 webpack loader,所以这里直接搞成了文件内容
*/
const pcList = [
{ text: '仪表盘布局', value: 'dashboard' },
{ text: '通用页面布局', value: 'page' },
{ text: '空白页', value: 'wrapper' },
{ text: '首页', value: 'index-page' },
{ text: '登录页', value: 'login-page' },
{ text: '404 页面', value: '404-page' },
{ text: '无权限页面', value: '401-page' },
{ text: '禁止访问页面', value: '403-page' },
{ text: '服务器错误页面', value: '500-page' },
];
export const h5List = [
{ text: '空白页', value: 'lcap-h5-blank' },
{ text: '登录页', value: 'lcap-h5-login' },
{ text: '主页', value: 'lcap-h5-navi' },
{ text: '个人中心页', value: 'lcap-h5-user' },
{ text: '404 页面', value: 'lcap-h5-404' },
{ text: '无权限页面', value: 'lcap-h5-401' },
];
export let TEMPLATE_LIST: Array<TemplateItem> = pcList;
export const TEMPLATE_MAP: { [name: string]: TemplateItem } = {};
export async function loadTemplates() {
const ifH5 = config.scope === 'h5';
const { rows } = await blockService.loadList({
query: {
keyword: ifH5 ? `template-h5` : `view-template`,
},
});
if (ifH5) {
TEMPLATE_LIST = h5List;
}
TEMPLATE_LIST.forEach((item) => TEMPLATE_MAP[item.value] = item);
const h5Real: TemplateItem[] = [];
const templates = rows.forEach((row: any) => {
const item: TemplateItem = {
text: row.title,
value: row.name.replace(/^@cloud-ui\/s-/, '').replace(/^@lcap\/mobile-ui\//, '').replace(/\.vue$/, ''),
screenshots: row.screenshots,
};
if (ifH5) {
TEMPLATE_LIST.forEach((v) => {
if (v.value === item.value) {
h5Real.push(item);
}
});
} else {
if (!TEMPLATE_MAP[item.value]) {
TEMPLATE_LIST.push(item);
TEMPLATE_MAP[item.value] = item;
}
}
});
return ifH5 ? h5Real : TEMPLATE_LIST;
}