From c543fe894ad7167658923a4d9129e31a1555c970 Mon Sep 17 00:00:00 2001 From: bqy_fe <1743369777@qq.com> Date: Fri, 25 Jun 2021 21:44:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=95=B0=E6=8D=AE=E6=BA=90=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 2 + package.json | 5 +- preview/router.ts | 10 +- preview/utils/http/httpEnum.ts | 34 +++ preview/utils/http/request.ts | 103 +++++++ preview/views/comp-render.tsx | 6 +- preview/views/preview.vue | 20 +- preview/views/slot-item.vue | 17 +- src/hooks/useAnimate.ts | 4 +- src/packages/base-widgets/button/index.tsx | 2 +- src/packages/base-widgets/checkbox/index.tsx | 2 +- .../base-widgets/datetimePicker/index.tsx | 2 +- src/packages/base-widgets/divider/index.tsx | 4 +- src/packages/base-widgets/image/index.tsx | 4 +- src/packages/base-widgets/input/index.tsx | 10 +- src/packages/base-widgets/nav-bar/index.tsx | 4 +- .../base-widgets/notice-bar/index.tsx | 4 +- src/packages/base-widgets/picker/index.tsx | 2 +- src/packages/base-widgets/process/index.tsx | 4 +- src/packages/base-widgets/radio/index.tsx | 2 +- src/packages/base-widgets/rate/index.tsx | 10 +- src/packages/base-widgets/slider/index.tsx | 10 +- src/packages/base-widgets/stepper/index.tsx | 4 +- src/packages/base-widgets/swipe/index.tsx | 2 +- src/packages/base-widgets/switch/index.tsx | 4 +- src/packages/base-widgets/text/index.tsx | 4 +- .../container-component/form/index.tsx | 2 +- .../container-component/layout/index.tsx | 2 +- .../components/container-component/index.tsx | 5 +- .../components/data-source/index.vue | 255 ++++++++++++++++++ .../components/left-aside/components/index.ts | 2 +- .../components/left-aside/index.vue | 15 +- .../components/left-aside/tabs.ts | 17 +- .../components/animate/Animate.tsx | 4 +- .../components/animate/animateConfig.ts | 2 +- .../components/attr-editor/AttrEditor.tsx | 4 +- .../cross-sortable-options-editor.tsx | 6 +- .../attr-editor/components/index.ts | 11 + .../table-prop-edit.service.tsx | 4 +- .../table-prop-editor/table-prop-editor.tsx | 0 .../components/event-action/index.tsx | 19 ++ .../right-attribute-panel/components/index.ts | 7 +- .../components/page-setting/pageSetting.tsx | 4 +- .../right-attribute-panel/index.module.scss | 2 +- .../right-attribute-panel/index.tsx | 18 +- .../simulator-editor/comp-render.tsx | 4 +- .../simulator-editor/simulator-editor.vue | 2 +- src/visual-editor/hooks/useModal.tsx | 8 +- src/visual-editor/hooks/useVisualData.ts | 112 +++++++- src/visual-editor/utils/index.ts | 32 ++- src/visual-editor/visual-editor.utils.ts | 69 ++++- yarn.lock | 34 ++- 52 files changed, 794 insertions(+), 121 deletions(-) create mode 100644 preview/utils/http/httpEnum.ts create mode 100644 preview/utils/http/request.ts create mode 100644 src/visual-editor/components/left-aside/components/data-source/index.vue rename src/visual-editor/components/right-attribute-panel/components/{ => attr-editor/components}/cross-sortable-options-editor/cross-sortable-options-editor.tsx (91%) create mode 100644 src/visual-editor/components/right-attribute-panel/components/attr-editor/components/index.ts rename src/visual-editor/components/right-attribute-panel/components/{ => attr-editor/components}/table-prop-editor/table-prop-edit.service.tsx (96%) rename src/visual-editor/components/right-attribute-panel/components/{ => attr-editor/components}/table-prop-editor/table-prop-editor.tsx (100%) create mode 100644 src/visual-editor/components/right-attribute-panel/components/event-action/index.tsx 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 @@ - +