Skip to content

Commit

Permalink
feat: just for mock
Browse files Browse the repository at this point in the history
  • Loading branch information
贾志伟 committed Apr 6, 2024
1 parent a3445b2 commit 2a80310
Show file tree
Hide file tree
Showing 18 changed files with 14 additions and 570 deletions.
116 changes: 8 additions & 108 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ const { t } = useI18n();
const store = useGlobalStore();
const needSettingPages = ['mock', 'assets'];
const isShow = ref<boolean>(false);
const settingFor = ref<string>('mock');
const lang = Intl.DateTimeFormat().resolvedOptions().locale;
const locale = lang.toLocaleLowerCase().includes('zh') ? zhCn : en;
Expand Down Expand Up @@ -51,92 +48,14 @@ const mockConf = ref({
authValuePartten: 'Bearer ${token}',
});
// 静态资源页面的配置数据
const assetsConf = ref({
username: '',
password: '',
token: '',
apiPath: '',
authType: 'header',
method: 'POST',
passwordEncryptType: 'MD5',
salt: '',
conf: `{
"auth": {
"Authorization": "Bearer \${token}",
},
"logInfoMap": {
"username": "username",
"password": "password",
},
"token": "data.token",
}`,
list: {
url: '',
method: 'POST',
conf: `{
"req": {
"map": {
"current": "current",
"size": "size",
}
},
"res": {
"map": {
"total": "total",
"list": "data",
},
"itemMap": {
"url": "imgUrl",
"time": "date",
"name": "name",
"extension": "extension"
}
}
}`,
},
upload: {
url: '',
method: 'POST',
conf: `{
"res": {
"map": {
"id": "id",
"url": "data",
"name": "name",
"extension": "extension",
"time": "date",
}
}
}`,
},
delete: {
url: '',
method: 'GET',
conf: `{
"res": {
"result": "data"
}
}`,
},
update: {
url: '',
method: 'POST',
conf: `{
"res": {
"result": "data"
}
}`,
}
});
const handleMenuItemClick = (menuItem: MenuItem) => {
const { path } = menuItem;
router.push(path)
}
const handleLogin = async () => {
const info = settingFor.value === 'mock' ? mockConf.value : assetsConf.value;
const info = mockConf.value;
await handleSaveSetting(true);
const loginFunc = getRequestFormConf({
passwordEncryptType: info.passwordEncryptType,
Expand All @@ -160,13 +79,7 @@ const handleLogin = async () => {
// 保存配置 如果有token的话,保存的效果就等同登录了
const handleSaveSetting = async (isLogin: boolean = false) => {
try {
const info = settingFor.value === 'mock' ? mockConf.value : assetsConf.value;
store.setSetting(settingFor.value, info);
const res = await setPageSetting({
settingFor: settingFor.value,
...info,
});
const res = await setPageSetting(mockConf.value);
if(isLogin !== true) {
if(res.code === 200) {
Expand All @@ -187,13 +100,9 @@ const handleGetSetting = async () => {
const res = await getPageSetting();
if(res.code === 200) {
const { data } = res;
if(Object.keys(data.mock ?? {}).length) {
mockConf.value = data.mock;
store.setSetting('mock', data.mock);
}
if(Object.keys(data.assets ?? {}).length) {
assetsConf.value = data.assets;
store.setSetting('assets', data.assets);
if(Object.keys(data ?? {}).length) {
mockConf.value = data;
store.setSetting(data);
}
}
} catch (error) {
Expand Down Expand Up @@ -224,25 +133,16 @@ onMounted(handleGetSetting);
@click="isShow = true"
>
<SvgIcon class="text-gray-200 scale-125" icon-name="setting" />
设置
{{ t('global.systemSetting') }}
</div>
</div>
</div>
<div class="ml-36 min-h-[600px] h-screen bg-gray-100">
<RouterView />
</div>
</div>
<el-dialog v-model="isShow" title="系统配置" width="960px">
<div class="flex max-h-[60vh]">
<div v-for="item in needSettingPages" :key="item"
:class="{'flex-1 box-border text-center cursor-pointer p-2': true, 'border': item !== settingFor, 'bg-primary-light text-white': item===settingFor}"
@click="settingFor = item"
>
{{ item }} Setting
</div>
</div>
<Setting v-if="settingFor === 'mock'" v-model="mockConf" setting-for="mock" @login="handleLogin" @save="handleSaveSetting" />
<Setting v-else setting-for="assets" v-model="assetsConf" @login="handleLogin" @save="handleSaveSetting" />
<el-dialog v-model="isShow" :title="t('global.systemSetting')" width="960px">
<Setting v-model="mockConf" setting-for="mock" @login="handleLogin" @save="handleSaveSetting" />
</el-dialog>
</el-config-provider>
</template>
Expand Down
Binary file removed src/assets/pngIcons/doc.png
Binary file not shown.
Binary file removed src/assets/pngIcons/file.png
Binary file not shown.
Binary file removed src/assets/pngIcons/image.png
Binary file not shown.
Binary file removed src/assets/pngIcons/mp3.png
Binary file not shown.
Binary file removed src/assets/pngIcons/pdf.png
Binary file not shown.
Binary file removed src/assets/pngIcons/ppt.png
Binary file not shown.
Binary file removed src/assets/pngIcons/txt.png
Binary file not shown.
Binary file removed src/assets/pngIcons/video.png
Binary file not shown.
Binary file removed src/assets/pngIcons/xls.png
Binary file not shown.
Binary file removed src/assets/pngIcons/zip.png
Binary file not shown.
66 changes: 0 additions & 66 deletions src/components/ImageItem.vue

This file was deleted.

1 change: 1 addition & 0 deletions src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@ export default {
responseConfig: 'responseConfig',
sceneName: 'scene name',
iteration: 'Iteration',
systemSetting: 'System Setting',
},
}
1 change: 1 addition & 0 deletions src/i18n/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@ export default {
responseConfig: '返回值配置',
sceneName: '场景名',
iteration: '迭代期',
systemSetting: '系统设置',
},
}
8 changes: 2 additions & 6 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import { defineStore } from "pinia";
export const useGlobalStore = defineStore('globalData', () => {
const mockSetting = ref({} as any);
const assetsSetting = ref({list: {}, upload: {}, delete: {}, update: {}} as any);
const setSetting = (settingFor: string, setting: any) => {
if(settingFor === 'mock') {
mockSetting.value = setting;
} else if(settingFor === 'assets') {
assetsSetting.value = setting;
}
const setSetting = (setting: any) => {
mockSetting.value = setting;
};

return {
Expand Down
32 changes: 2 additions & 30 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
import type { MenuItem } from '@/types/common.d.ts'
import docIcon from '@/assets/pngIcons/doc.png';
import fileIcon from '@/assets/pngIcons/file.png';
import imageIcon from '@/assets/pngIcons/image.png';
import mp3Icon from '@/assets/pngIcons/mp3.png';
import pdfIcon from '@/assets/pngIcons/pdf.png';
import pptIcon from '@/assets/pngIcons/ppt.png';
import textIcon from '@/assets/pngIcons/txt.png';
import videoIcon from '@/assets/pngIcons/video.png';
import xlsIcon from '@/assets/pngIcons/xls.png';
import zipIcon from '@/assets/pngIcons/zip.png';
const envLanguage = Intl.DateTimeFormat().resolvedOptions().locale

// 菜单项
export const menuItems: MenuItem[] = [
{
path: '/',
name: '数据模拟',
name: envLanguage.includes('zh') ? '数据模拟' : 'Mock',
icon: 'mock',
component: () => import('@/views/HomeView.vue'),
},
{
path: '/assetsManage',
name: '静态资源',
icon: 'assetsManagement',
component: () => import('@/views/AssetsManage.vue'),
},
];

// 处理请求的方式
Expand All @@ -36,16 +21,3 @@ export const requestMethodList = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'] as co
export const apiTypeList = ['HTTP', 'JSON-RPC'] as const;

export const wsMessageTypeList = ['param', 'refresh:mockList'] as const;

export {
docIcon,
fileIcon,
imageIcon,
mp3Icon,
pdfIcon,
pptIcon,
textIcon,
videoIcon,
xlsIcon,
zipIcon,
}
30 changes: 0 additions & 30 deletions src/utils/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@ import get from 'lodash/get';
import set from 'lodash/set';
import crypto from 'crypto-js';

import {
docIcon,
fileIcon,
mp3Icon,
pdfIcon,
pptIcon,
textIcon,
videoIcon,
xlsIcon,
zipIcon,
} from '@/utils/constants';


export const getRequestFormConf = (conf: {
api: string,
Expand All @@ -36,7 +24,6 @@ export const getRequestFormConf = (conf: {
requestData[logInfoMap.password ?? 'password'] = crypto?.[conf.passwordEncryptType](param.password, conf.salt).toString();
return await defineRequest(conf.api, conf.method)(requestData);
} else {
console.log('some11111-----', confObj, conf, formattedApi);
const paramMap: Record<string, string> = confObj?.req?.map ?? {};
const resultMap: Record<string, string> = confObj?.res?.map ?? {};
const requestData = {} as Record<string, string>;
Expand Down Expand Up @@ -74,20 +61,3 @@ export const getRequestFormConf = (conf: {
return resultData;
}
}


export const extension2IconMap = {
'png,jpg,jpeg,gif': 'image',
'doc,docx': docIcon,
'xls,xlsx': xlsIcon,
'ppt,pptx': pptIcon,
'pdf': pdfIcon,
'zip,rar': zipIcon,
'txt,text': textIcon,
'mp3': mp3Icon,
'mp4, rmvb, avi, wmv, 3gp, mkv': videoIcon,
};
export const getAssetsIcon = (extension: string) => {
const entry = Object.entries(extension2IconMap).find(([key]) => key.includes(extension));
return entry ? entry[1] : fileIcon;
};
Loading

0 comments on commit 2a80310

Please sign in to comment.