refactor: use setup refactor

This commit is contained in:
xiaoxian521 2021-09-19 01:12:46 +08:00
parent 85f4917f26
commit afff1d677b
18 changed files with 128 additions and 106 deletions

View File

@ -1,4 +1,4 @@
public public
dist dist
*.d.ts *.d.ts
package.json package.json

View File

@ -24,6 +24,7 @@ module.exports = {
ElRef: "readonly", ElRef: "readonly",
global: "readonly", global: "readonly",
ForDataType: "readonly", ForDataType: "readonly",
ComponentRoutes: "readonly",
// script setup // script setup
defineProps: "readonly", defineProps: "readonly",

View File

@ -14,7 +14,7 @@
"lint:stylelint": "stylelint --cache --fix \"**/*.{vue,css,scss,postcss,less}\" --cache --cache-location node_modules/.cache/stylelint/", "lint:stylelint": "stylelint --cache --fix \"**/*.{vue,css,scss,postcss,less}\" --cache --cache-location node_modules/.cache/stylelint/",
"lint:lint-staged": "lint-staged -c ./.husky/lintstagedrc.js", "lint:lint-staged": "lint-staged -c ./.husky/lintstagedrc.js",
"lint:pretty": "pretty-quick --staged", "lint:pretty": "pretty-quick --staged",
"lint:all": "yarn lint:eslint && yarn lint:prettier && yarn lint:stylelint && yarn lint:pretty", "lint": "yarn lint:eslint && yarn lint:prettier && yarn lint:stylelint && yarn lint:pretty",
"prepare": "husky install" "prepare": "husky install"
}, },
"dependencies": { "dependencies": {

View File

@ -1,5 +1,4 @@
import type { CSSProperties } from "vue"; import type { CSSProperties } from "vue";
import { import {
defineComponent, defineComponent,
onBeforeMount, onBeforeMount,
@ -40,46 +39,48 @@ const defaultOptions: Cropper.Options = {
rotatable: true rotatable: true
}; };
export default defineComponent({ const props = {
name: "Cropper", src: {
props: { type: String,
src: { required: true
type: String, },
required: true alt: {
}, type: String
alt: { },
type: String width: {
}, type: [String, Number],
width: { default: ""
type: [String, Number], },
default: "" height: {
}, type: [String, Number],
height: { default: "360px"
type: [String, Number], },
default: "360px" crossorigin: {
}, type: String || Object,
crossorigin: { default: undefined
type: String || Object, },
default: undefined imageStyle: {
}, type: Object as PropType<CSSProperties>,
imageStyle: { default() {
type: Object as PropType<CSSProperties>, return {};
default() {
return {};
}
},
options: {
type: Object as PropType<Options>,
default() {
return {};
}
} }
}, },
options: {
type: Object as PropType<Options>,
default() {
return {};
}
}
};
export default defineComponent({
name: "Cropper",
props,
setup(props) { setup(props) {
const cropper: any = ref<Nullable<Cropper>>(null); const cropper: any = ref<Nullable<Cropper>>(null);
const imgElRef = templateRef<HTMLImageElement | null>("imgElRef", null); const imgElRef = templateRef<HTMLImageElement | null>("imgElRef", null);
const isReady = ref(false); const isReady = ref<boolean>(false);
const getImageStyle = computed((): CSSProperties => { const getImageStyle = computed((): CSSProperties => {
return { return {

View File

@ -2,19 +2,21 @@ import { defineComponent, ref } from "vue";
import { propTypes } from "/@/utils/propTypes"; import { propTypes } from "/@/utils/propTypes";
import "./filpper.css"; import "./filpper.css";
const props = {
// front paper text
// 前牌文字
frontText: propTypes.number.def(0),
// back paper text
// 后牌文字
backText: propTypes.number.def(1),
// flipping duration, please be consistent with the CSS animation-duration value.
// 翻牌动画时间与CSS中设置的animation-duration保持一致
duration: propTypes.number.def(600)
};
export default defineComponent({ export default defineComponent({
name: "Filpper", name: "Filpper",
props: { props,
// front paper text
// 前牌文字
frontText: propTypes.number.def(0),
// back paper text
// 后牌文字
backText: propTypes.number.def(1),
// flipping duration, please be consistent with the CSS animation-duration value.
// 翻牌动画时间与CSS中设置的animation-duration保持一致
duration: propTypes.number.def(600)
},
setup(props) { setup(props) {
// eslint-disable-next-line vue/no-setup-props-destructure // eslint-disable-next-line vue/no-setup-props-destructure
const { frontText, backText, duration } = props; const { frontText, backText, duration } = props;

View File

@ -58,6 +58,7 @@ const rules: Object = ref({
// //
const onBehavior = (evt: Object): void => { const onBehavior = (evt: Object): void => {
// @ts-expect-error
instance.refs.ruleForm.validate((valid: boolean) => { instance.refs.ruleForm.validate((valid: boolean) => {
if (valid) { if (valid) {
emit("onBehavior", evt); emit("onBehavior", evt);
@ -74,6 +75,7 @@ const refreshVerify = (): void => {
// //
const resetForm = (): void => { const resetForm = (): void => {
// @ts-expect-error
instance.refs.ruleForm.resetFields(); instance.refs.ruleForm.resetFields();
}; };

View File

@ -21,35 +21,37 @@ let overList = [];
// 存放第一个选中的元素和最后一个选中元素,只能存放这两个元素 // 存放第一个选中的元素和最后一个选中元素,只能存放这两个元素
let selectedList = []; let selectedList = [];
export default defineComponent({ const props = {
name: "Selector", HsKey: {
props: { type: Number || String,
HsKey: { default: 0
type: Number || String, },
default: 0 disabled: {
}, type: Boolean,
disabled: { default: false
type: Boolean, },
default: false value: {
}, type: Number,
value: { default: 0
type: Number, },
default: 0 max: {
}, type: Array,
max: { default() {
type: Array, return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
default() {
return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
}
},
// 回显数据的索引长度必须是2
echo: {
type: Array,
default() {
return [];
}
} }
}, },
// 回显数据的索引长度必须是2
echo: {
type: Array,
default() {
return [];
}
}
};
export default defineComponent({
name: "Selector",
props,
emits: ["selectedVal"], emits: ["selectedVal"],
setup(props, { emit }) { setup(props, { emit }) {
const instance = getCurrentInstance(); const instance = getCurrentInstance();

View File

@ -1,6 +1,6 @@
let config: object = {}; let config: object = {};
const setConfig = (cfg?: any) => { const setConfig = (cfg?: unknown) => {
config = Object.assign(config, cfg); config = Object.assign(config, cfg);
}; };

View File

@ -1,19 +1,17 @@
import { createApp, Directive } from "vue";
import App from "./App.vue"; import App from "./App.vue";
import router from "./router"; import router from "./router";
import { setupStore } from "/@/store"; import { setupStore } from "/@/store";
import { createApp, Directive } from "vue";
import { useElementPlus } from "../src/plugins/element-plus";
import { useTable } from "../src/plugins/vxe-table";
import { usI18n } from "../src/plugins/i18n"; import { usI18n } from "../src/plugins/i18n";
import { useTable } from "../src/plugins/vxe-table";
import { useElementPlus } from "../src/plugins/element-plus";
import "animate.css";
// 导入公共样式 // 导入公共样式
import "./style/index.scss"; import "./style/index.scss";
// 导入字体图标 // 导入字体图标
import "./assets/iconfont/iconfont.js"; import "./assets/iconfont/iconfont.js";
import "./assets/iconfont/iconfont.css"; import "./assets/iconfont/iconfont.css";
import "animate.css";
import "v-contextmenu/dist/themes/default.css"; import "v-contextmenu/dist/themes/default.css";
import { setConfig, getConfig } from "./config"; import { setConfig, getConfig } from "./config";
@ -25,7 +23,7 @@ app.config.globalProperties.$config = getConfig();
// 响应式storage // 响应式storage
import Storage from "responsive-storage"; import Storage from "responsive-storage";
// @ts-ignore
app.use(Storage, { app.use(Storage, {
// 默认显示首页tag // 默认显示首页tag
routesInStorage: { routesInStorage: {
@ -58,7 +56,7 @@ Object.keys(directives).forEach(key => {
}); });
// 获取项目动态全局配置 // 获取项目动态全局配置
export const getServerConfig = async (): Promise<any> => { export const getServerConfig = async (): Promise<undefined> => {
return axios({ return axios({
baseURL: "", baseURL: "",
method: "get", method: "get",
@ -87,10 +85,7 @@ export const getServerConfig = async (): Promise<any> => {
getServerConfig().then(async () => { getServerConfig().then(async () => {
setupStore(app); setupStore(app);
app.use(router).use(useElementPlus).use(useTable).use(usI18n); app.use(router).use(useElementPlus).use(useTable).use(usI18n);
await router.isReady(); await router.isReady();
app.mount("#app"); app.mount("#app");
}); });

View File

@ -7,6 +7,7 @@ import enVxeTable from "vxe-table/lib/locale/lang/en-US";
import enLocale from "element-plus/lib/locale/lang/en"; import enLocale from "element-plus/lib/locale/lang/en";
import zhLocale from "element-plus/lib/locale/lang/zh-cn"; import zhLocale from "element-plus/lib/locale/lang/zh-cn";
// 导航菜单配置
export const menusConfig = { export const menusConfig = {
zh: { zh: {
message: { message: {

View File

@ -1,7 +1,7 @@
import "xe-utils";
import { App } from "vue"; import { App } from "vue";
import { i18n } from "../i18n/index"; import { i18n } from "../i18n/index";
import "font-awesome/css/font-awesome.css"; import "font-awesome/css/font-awesome.css";
import "xe-utils";
import { import {
// 核心 // 核心
VXETable, VXETable,
@ -62,6 +62,7 @@ VXETable.setup({
clearable: true clearable: true
}, },
// 对组件内置的提示语进行国际化翻译 // 对组件内置的提示语进行国际化翻译
// @ts-ignore
i18n: (key, args) => i18n.global.t(key, args), i18n: (key, args) => i18n.global.t(key, args),
// 可选,对参数中的列头、校验提示..等进行自动翻译(只对支持国际化的有效) // 可选,对参数中的列头、校验提示..等进行自动翻译(只对支持国际化的有效)
translate(key, args) { translate(key, args) {

View File

@ -1,5 +1,11 @@
import { createRouter, createWebHashHistory, Router } from "vue-router"; import {
createRouter,
createWebHashHistory,
Router,
RouteComponent
} from "vue-router";
import Layout from "/@/layout/index.vue";
import homeRouter from "./modules/home"; import homeRouter from "./modules/home";
import flowChartRouter from "./modules/flowchart"; import flowChartRouter from "./modules/flowchart";
import editorRouter from "./modules/editor"; import editorRouter from "./modules/editor";
@ -9,17 +15,15 @@ import errorRouter from "./modules/error";
import externalLink from "./modules/externalLink"; import externalLink from "./modules/externalLink";
import remainingRouter from "./modules/remaining"; //静态路由 import remainingRouter from "./modules/remaining"; //静态路由
import { storageSession } from "../utils/storage";
import { i18n } from "/@/plugins/i18n"; import { i18n } from "/@/plugins/i18n";
import { getAsyncRoutes } from "/@/api/routes";
import { storageSession } from "../utils/storage";
import { usePermissionStoreHook } from "/@/store/modules/permission"; import { usePermissionStoreHook } from "/@/store/modules/permission";
import { getAsyncRoutes } from "/@/api/routes";
import Layout from "/@/layout/index.vue";
// https://cn.vitejs.dev/guide/features.html#glob-import // https://cn.vitejs.dev/guide/features.html#glob-import
const modulesRoutes = import.meta.glob("/src/views/*/*/*.vue"); const modulesRoutes = import.meta.glob("/src/views/*/*/*.vue");
const constantRoutes: Array<any> = [ const constantRoutes: Array<RouteComponent> = [
homeRouter, homeRouter,
flowChartRouter, flowChartRouter,
editorRouter, editorRouter,
@ -125,8 +129,10 @@ const whiteList = ["/login", "/register"];
router.beforeEach((to, _from, next) => { router.beforeEach((to, _from, next) => {
const name = storageSession.getItem("info"); const name = storageSession.getItem("info");
NProgress.start(); NProgress.start();
// @ts-ignore
const { t } = i18n.global; const { t } = i18n.global;
to.meta.title ? (document.title = t(to.meta.title)) : ""; // 动态title // @ts-ignore
to.meta.title ? (document.title = t(to.meta.title)) : "";
if (name) { if (name) {
if (_from?.name) { if (_from?.name) {
next(); next();

View File

@ -10,7 +10,6 @@ class algorithmProxy implements ProxyAlgorithm {
return Object.keys(val) return Object.keys(val)
.map(v => { .map(v => {
return { return {
// @ts-ignore
...val[v], ...val[v],
key: v key: v
}; };

View File

@ -5,7 +5,8 @@ import { excludeProps } from "./utils";
*/ */
export const defaultConfig: AxiosRequestConfig = { export const defaultConfig: AxiosRequestConfig = {
baseURL: "", baseURL: "",
timeout: 10000, //10秒超时 //10秒超时
timeout: 10000,
headers: { headers: {
Accept: "application/json, text/plain, */*", Accept: "application/json, text/plain, */*",
"Content-Type": "application/json", "Content-Type": "application/json",

View File

@ -1,8 +1,12 @@
export const hasClass = (ele: Element, cls: string): any => { export const hasClass = (ele: RefType<any>, cls: string): any => {
return !!ele.className.match(new RegExp("(\\s|^)" + cls + "(\\s|$)")); return !!ele.className.match(new RegExp("(\\s|^)" + cls + "(\\s|$)"));
}; };
export const addClass = (ele: Element, cls: string, extracls?: string): any => { export const addClass = (
ele: RefType<any>,
cls: string,
extracls?: string
): any => {
if (!hasClass(ele, cls)) ele.className += " " + cls; if (!hasClass(ele, cls)) ele.className += " " + cls;
if (extracls) { if (extracls) {
if (!hasClass(ele, extracls)) ele.className += " " + extracls; if (!hasClass(ele, extracls)) ele.className += " " + extracls;
@ -10,7 +14,7 @@ export const addClass = (ele: Element, cls: string, extracls?: string): any => {
}; };
export const removeClass = ( export const removeClass = (
ele: Element, ele: RefType<any>,
cls: string, cls: string,
extracls?: string extracls?: string
): any => { ): any => {

View File

@ -2,11 +2,16 @@ import NProgress from "nprogress";
import "nprogress/nprogress.css"; import "nprogress/nprogress.css";
NProgress.configure({ NProgress.configure({
easing: "ease", // 动画方式 // 动画方式
speed: 500, // 递增进度条的速度 easing: "ease",
showSpinner: true, // 是否显示加载ico // 递增进度条的速度
trickleSpeed: 200, // 自动递增间隔 speed: 500,
minimum: 0.3 // 初始化时的最小百分比 // 是否显示加载ico
showSpinner: true,
// 自动递增间隔
trickleSpeed: 200,
// 初始化时的最小百分比
minimum: 0.3
}); });
export default NProgress; export default NProgress;

View File

@ -9,11 +9,13 @@ let cropperImg = ref<string>("");
const onCropper = (): void => { const onCropper = (): void => {
nextTick(() => { nextTick(() => {
// @ts-expect-error
instance.refs.refCropper.cropper.getCroppedCanvas().toBlob(blob => { instance.refs.refCropper.cropper.getCroppedCanvas().toBlob(blob => {
let fileReader: FileReader = new FileReader(); let fileReader: FileReader = new FileReader();
fileReader.onloadend = (e: ProgressEvent) => { fileReader.onloadend = (e: ProgressEvent) => {
// @ts-ignore // @ts-ignore
cropperImg.value = e.target.result; cropperImg.value = e.target.result;
// @ts-expect-error
info.value = instance.refs.refCropper.cropper.getData(); info.value = instance.refs.refCropper.cropper.getData();
}; };
fileReader.readAsDataURL(blob); fileReader.readAsDataURL(blob);

View File

@ -24,7 +24,7 @@
"/#/*": ["types/*"] "/#/*": ["types/*"]
}, },
"types": ["node", "vite/client"], "types": ["node", "vite/client"],
"typeRoots": ["./node_modules/@types/", "./types", "./vue-types"] "typeRoots": ["./node_modules/@types/", "./types"]
}, },
"include": [ "include": [
"src/**/*.ts", "src/**/*.ts",