diff --git a/components.d.ts b/components.d.ts index 256150c..853e3e0 100644 --- a/components.d.ts +++ b/components.d.ts @@ -15,6 +15,8 @@ declare module 'vue' { ElTabPane: typeof import('element-plus/es/el-tab-pane')['default'] ElTabs: typeof import('element-plus/es/el-tabs')['default'] ElDialog: typeof import('element-plus/es/el-dialog')['default'] + ElCollapseItem: typeof import('element-plus/es/el-collapse-item')['default'] + ElCollapse: typeof import('element-plus/es/el-collapse')['default'] ElTag: typeof import('element-plus/es/el-tag')['default'] ElDropdownItem: typeof import('element-plus/es/el-dropdown-item')['default'] ElDropdownMenu: typeof import('element-plus/es/el-dropdown-menu')['default'] diff --git a/package.json b/package.json index de0e387..3785b61 100644 --- a/package.json +++ b/package.json @@ -27,12 +27,13 @@ "axios": "^0.21.1", "dayjs": "^1.10.5", "dexie": "^3.0.3", - "element-plus": "1.0.2-beta.51", + "element-plus": "1.0.2-beta.53", "lodash": "^4.17.21", "monaco-editor": "^0.25.2", "normalize.css": "^8.0.1", "nprogress": "^1.0.0-1", "qrcode": "^1.4.4", + "qs": "^6.10.1", "vant": "^3.1.0", "vue": "3.1.2", "vue-router": "^4.0.10", @@ -57,7 +58,7 @@ "eslint-config-prettier": "^8.3.0", "eslint-plugin-import": "^2.23.4", "eslint-plugin-prettier": "^3.4.0", - "eslint-plugin-vue": "^7.11.1", + "eslint-plugin-vue": "^7.12.1", "gh-pages": "^3.2.3", "husky": "^6.0.0", "lint-staged": "^11.0.0", diff --git a/preview/router.ts b/preview/router.ts index c2b789c..840324c 100644 --- a/preview/router.ts +++ b/preview/router.ts @@ -1,5 +1,13 @@ +/* + * @Author: 卜启缘 + * @Date: 2021-06-01 09:45:21 + * @LastEditTime: 2021-06-25 08:47:07 + * @LastEditors: 卜启缘 + * @Description: 路由表 + * @FilePath: \vite-vue3-lowcode\preview\router.ts + */ import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router' -import { VisualEditorModelValue } from '@/visual-editor/visual-editor.utils' +import type { VisualEditorModelValue } from '@/visual-editor/visual-editor.utils' import { CacheEnum } from '@/enums' const routes: Array = [ diff --git a/preview/utils/http/httpEnum.ts b/preview/utils/http/httpEnum.ts new file mode 100644 index 0000000..38e905a --- /dev/null +++ b/preview/utils/http/httpEnum.ts @@ -0,0 +1,34 @@ +/** + * @description: 请求结果集 + */ +export enum ResultEnum { + SUCCESS = 0, + ERROR = -1, + TIMEOUT = 10042, + TYPE = 'success' +} + +/** + * @description: 请求方法 + */ +export enum RequestEnum { + GET = 'GET', + POST = 'POST', + PATCH = 'PATCH', + PUT = 'PUT', + DELETE = 'DELETE' +} + +/** + * @description: 常用的contentTyp类型 + */ +export enum ContentTypeEnum { + // json + JSON = 'application/json;charset=UTF-8', + // json + TEXT = 'text/plain;charset=UTF-8', + // form-data 一般配合qs + FORM_URLENCODED = 'application/x-www-form-urlencoded;charset=UTF-8', + // form-data 上传 + FORM_DATA = 'multipart/form-data;charset=UTF-8' +} diff --git a/preview/utils/http/request.ts b/preview/utils/http/request.ts new file mode 100644 index 0000000..11a0662 --- /dev/null +++ b/preview/utils/http/request.ts @@ -0,0 +1,103 @@ +/* + * @Author: 卜启缘 + * @Date: 2021-06-24 23:19:48 + * @LastEditTime: 2021-06-24 23:35:57 + * @LastEditors: 卜启缘 + * @Description: axios简单的封装 + * @FilePath: \vite-vue3-lowcode\src\utils\http\request.ts + */ +import axios, { AxiosRequestConfig } from 'axios' +import qs from 'qs' +import store from '@/store' +import { Toast } from 'vant' +import router from '@/router' +import { ContentTypeEnum } from './httpEnum' + +// create an axios instance +const service = axios.create({ + baseURL: import.meta.env.VITE_API_URL as string, // url = base api url + request url + withCredentials: true, // send cookies when cross-domain requests + timeout: 10000 // request timeout +}) +interface CustomAxiosRequestConfig extends AxiosRequestConfig { + hideLoading?: boolean +} + +interface BaseResponse { + code: number + data: T + msg: string +} + +// request拦截器 request interceptor +service.interceptors.request.use( + (config: CustomAxiosRequestConfig) => { + // 不传递默认开启loading + if (!config.hideLoading) { + // loading + Toast.loading({ + forbidClick: true + }) + } + console.log(store.getters, "store.getters['user']") + if (store.getters['user/token']) { + config.headers['X-Token'] = store.getters['user/token'] + } + const contentType = config.headers['content-type'] || config.headers['Content-Type'] + const data = config.data + if (config.method?.toLocaleUpperCase() == 'POST' && data) { + if (ContentTypeEnum.FORM_DATA == contentType) { + const fd = new FormData() + Object.keys(data).forEach((key) => fd.append(key, data[key])) + config.data = fd + } else if (ContentTypeEnum.FORM_URLENCODED == contentType) { + config.data = qs.stringify(config.data) + } + } + return config + }, + (error) => { + // do something with request error + console.log(error) // for debug + return Promise.reject(error) + } +) +// respone拦截器 +service.interceptors.response.use( + (response) => { + Toast.clear() + const res = response.data + if (res.code && res.code !== 0) { + // 登录超时,重新登录 + if (res.code === 401) { + // store.dispatch('FedLogOut').then(() => { + // location.reload() + // }) + router.replace('/error') + } else { + Toast(res.msg || '服务器访问出错了~') + } + return Promise.reject(res || 'error') + } else { + return Promise.resolve(response) + } + }, + (error: Error) => { + if (error.message?.includes('timeout')) { + Toast('请求超时!') + } + console.log('err' + error) // for debug + return Promise.reject(error) + } +) + +const request = (config: CustomAxiosRequestConfig): Promise> => { + return new Promise((resolve, reject) => { + service + .request>(config) + .then((res) => resolve(res.data)) + .catch((err) => reject(err)) + }) +} + +export default request diff --git a/preview/views/comp-render.tsx b/preview/views/comp-render.tsx index 328a3d5..b2af262 100644 --- a/preview/views/comp-render.tsx +++ b/preview/views/comp-render.tsx @@ -1,13 +1,13 @@ /* * @Author: 卜启缘 * @Date: 2021-05-04 05:36:58 - * @LastEditTime: 2021-06-24 00:36:24 + * @LastEditTime: 2021-06-25 08:47:18 * @LastEditors: 卜启缘 * @Description: - * @FilePath: \vite-vue3-lowcode\src\visual-editor\components\simulator-editor\comp-render.tsx + * @FilePath: \vite-vue3-lowcode\preview\views\comp-render.tsx */ import { defineComponent, PropType } from 'vue' -import { VisualEditorBlockData, VisualEditorConfig } from '@/visual-editor/visual-editor.utils' +import type { VisualEditorBlockData, VisualEditorConfig } from '@/visual-editor/visual-editor.utils' export default defineComponent({ name: 'CompRender', diff --git a/preview/views/preview.vue b/preview/views/preview.vue index bfca528..2203e32 100644 --- a/preview/views/preview.vue +++ b/preview/views/preview.vue @@ -1,7 +1,7 @@ + + diff --git a/src/visual-editor/components/left-aside/components/index.ts b/src/visual-editor/components/left-aside/components/index.ts index 0339dff..d9061df 100644 --- a/src/visual-editor/components/left-aside/components/index.ts +++ b/src/visual-editor/components/left-aside/components/index.ts @@ -6,7 +6,7 @@ console.log(modules, '起航') for (const path in modules) { const comp = modules[path].default - components[comp.name] = comp + components[comp.name || path.split('/')[1]] = comp } console.log('left-aside components:', components) diff --git a/src/visual-editor/components/left-aside/index.vue b/src/visual-editor/components/left-aside/index.vue index 9b05995..3f1370b 100644 --- a/src/visual-editor/components/left-aside/index.vue +++ b/src/visual-editor/components/left-aside/index.vue @@ -1,8 +1,15 @@ - +