chore: change to setup syntax

This commit is contained in:
vben 2021-08-16 23:43:09 +08:00
parent 91cbe0a03b
commit 8fa6015b1a
12 changed files with 200 additions and 270 deletions

View File

@ -26,22 +26,20 @@ jobs:
with: with:
node-version: '16.x' node-version: '16.x'
# - name: Get yarn cache - name: Get yarn cache
# id: yarn-cache id: yarn-cache
# run: echo "::set-output name=dir::$(yarn cache dir)" run: echo "::set-output name=dir::$(yarn cache dir)"
# - name: Cache dependencies - name: Cache dependencies
# uses: actions/cache@v2 uses: actions/cache@v2
# with: with:
# path: ${{ steps.yarn-cache.outputs.dir }} path: ${{ steps.yarn-cache.outputs.dir }}
# key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
# restore-keys: | restore-keys: |
# ${{ runner.os }}-yarn- ${{ runner.os }}-yarn-
- name: Build - name: Build
run: | run: |
yarn cache clean
rm -rf ./node_modules yarn.lock
yarn install yarn install
yarn run build yarn run build

View File

@ -122,7 +122,7 @@
"ts-jest": "^27.0.4", "ts-jest": "^27.0.4",
"ts-node": "^10.2.0", "ts-node": "^10.2.0",
"typescript": "4.3.5", "typescript": "4.3.5",
"vite": "2.5.0-beta.2", "vite": "2.5.0",
"vite-plugin-compression": "^0.3.3", "vite-plugin-compression": "^0.3.3",
"vite-plugin-html": "^2.0.7", "vite-plugin-html": "^2.0.7",
"vite-plugin-imagemin": "^0.4.3", "vite-plugin-imagemin": "^0.4.3",

View File

@ -7,12 +7,12 @@
<Icon icon="ion:chevron-forward" :style="$attrs.iconStyle" /> <Icon icon="ion:chevron-forward" :style="$attrs.iconStyle" />
</span> </span>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent, computed } from 'vue'; import { computed } from 'vue';
import { Icon } from '/@/components/Icon'; import { Icon } from '/@/components/Icon';
import { useDesign } from '/@/hooks/web/useDesign'; import { useDesign } from '/@/hooks/web/useDesign';
const props = { const props = defineProps({
/** /**
* Arrow expand state * Arrow expand state
*/ */
@ -29,13 +29,8 @@
* Cancel padding/margin for inline * Cancel padding/margin for inline
*/ */
inset: { type: Boolean }, inset: { type: Boolean },
}; });
export default defineComponent({
name: 'BasicArrow',
components: { Icon },
props,
setup(props) {
const { prefixCls } = useDesign('basic-arrow'); const { prefixCls } = useDesign('basic-arrow');
// get component class // get component class
@ -51,10 +46,6 @@
}, },
]; ];
}); });
return { getClass };
},
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
@prefix-cls: ~'@{namespace}-basic-arrow'; @prefix-cls: ~'@{namespace}-basic-arrow';

View File

@ -4,13 +4,13 @@
<BasicHelp :class="`${prefixCls}-help`" v-if="helpMessage" :text="helpMessage" /> <BasicHelp :class="`${prefixCls}-help`" v-if="helpMessage" :text="helpMessage" />
</span> </span>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import type { PropType } from 'vue'; import type { PropType } from 'vue';
import { defineComponent, computed } from 'vue'; import { useSlots, computed } from 'vue';
import BasicHelp from './BasicHelp.vue'; import BasicHelp from './BasicHelp.vue';
import { useDesign } from '/@/hooks/web/useDesign'; import { useDesign } from '/@/hooks/web/useDesign';
const props = { const props = defineProps({
/** /**
* Help text list or string * Help text list or string
* @default: '' * @default: ''
@ -29,24 +29,15 @@
* @default: false * @default: false
*/ */
normal: { type: Boolean }, normal: { type: Boolean },
}; });
export default defineComponent({
name: 'BasicTitle',
components: { BasicHelp },
props,
setup(props, { slots }) {
const { prefixCls } = useDesign('basic-title'); const { prefixCls } = useDesign('basic-title');
const slots = useSlots();
const getClass = computed(() => [ const getClass = computed(() => [
prefixCls, prefixCls,
{ [`${prefixCls}-show-span`]: props.span && slots.default }, { [`${prefixCls}-show-span`]: props.span && slots.default },
{ [`${prefixCls}-normal`]: props.normal }, { [`${prefixCls}-normal`]: props.normal },
]); ]);
return { prefixCls, getClass };
},
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
@prefix-cls: ~'@{namespace}-basic-title'; @prefix-cls: ~'@{namespace}-basic-title';

View File

@ -1,25 +1,27 @@
<template> <template>
<Button v-bind="getBindValue" :class="getButtonClass" @click="onClick"> <Button v-bind="getBindValue" :class="getButtonClass" @click="onClick">
<template #default> <template #default="data">
<Icon :icon="preIcon" v-if="preIcon" :size="iconSize" /> <Icon :icon="preIcon" v-if="preIcon" :size="iconSize" />
<slot></slot> <slot v-bind="data || {}"></slot>
<Icon :icon="postIcon" v-if="postIcon" :size="iconSize" /> <Icon :icon="postIcon" v-if="postIcon" :size="iconSize" />
</template> </template>
</Button> </Button>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, computed, unref } from 'vue'; export default {
name: 'AButton',
inheritAttrs: false,
};
</script>
<script lang="ts" setup>
import { computed, unref } from 'vue';
import { Button } from 'ant-design-vue'; import { Button } from 'ant-design-vue';
import Icon from '/@/components/Icon/src/Icon.vue'; import Icon from '/@/components/Icon/src/Icon.vue';
import { buttonProps } from './props'; import { buttonProps } from './props';
import { useAttrs } from '/@/hooks/core/useAttrs'; import { useAttrs } from '/@/hooks/core/useAttrs';
export default defineComponent({ const props = defineProps(buttonProps);
name: 'AButton',
components: { Button, Icon },
inheritAttrs: false,
props: buttonProps,
setup(props) {
// get component class // get component class
const attrs = useAttrs({ excludeDefaultKeys: false }); const attrs = useAttrs({ excludeDefaultKeys: false });
const getButtonClass = computed(() => { const getButtonClass = computed(() => {
@ -34,8 +36,4 @@
// get inherit binding value // get inherit binding value
const getBindValue = computed(() => ({ ...unref(attrs), ...props })); const getBindValue = computed(() => ({ ...unref(attrs), ...props }));
return { getBindValue, getButtonClass };
},
});
</script> </script>

View File

@ -20,7 +20,6 @@
export default defineComponent({ export default defineComponent({
name: 'PopButton', name: 'PopButton',
components: { Popconfirm, BasicButton },
inheritAttrs: false, inheritAttrs: false,
props, props,
setup(props, { slots }) { setup(props, { slots }) {
@ -40,7 +39,7 @@
return () => { return () => {
const bindValues = omit(unref(getBindValues), 'icon'); const bindValues = omit(unref(getBindValues), 'icon');
const btnBind = omit(bindValues, 'title'); const btnBind = omit(bindValues, 'title') as Recordable;
if (btnBind.disabled) btnBind.color = ''; if (btnBind.disabled) btnBind.color = '';
const Button = h(BasicButton, btnBind, extendSlots(slots)); const Button = h(BasicButton, btnBind, extendSlots(slots));

View File

@ -3,13 +3,10 @@
<slot></slot> <slot></slot>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent, ref, onMounted } from 'vue'; import { ref, onMounted } from 'vue';
import { onClickOutside } from '@vueuse/core'; import { onClickOutside } from '@vueuse/core';
export default defineComponent({ const emit = defineEmits(['mounted', 'clickOutside']);
name: 'ClickOutSide',
emits: ['mounted', 'clickOutside'],
setup(_, { emit }) {
const wrap = ref<ElRef>(null); const wrap = ref<ElRef>(null);
onClickOutside(wrap, () => { onClickOutside(wrap, () => {
@ -19,8 +16,4 @@
onMounted(() => { onMounted(() => {
emit('mounted'); emit('mounted');
}); });
return { wrap };
},
});
</script> </script>

View File

@ -8,29 +8,27 @@
/> />
</div> </div>
</template> </template>
<script lang="ts">
import { defineComponent, computed } from 'vue';
import CodeMirrorEditor from './codemirror/CodeMirror.vue';
import { isString } from '/@/utils/is';
<script lang="ts">
const MODE = { const MODE = {
JSON: 'application/json', JSON: 'application/json',
html: 'htmlmixed', html: 'htmlmixed',
js: 'javascript', js: 'javascript',
}; };
</script>
<script lang="ts" setup>
import { computed } from 'vue';
import CodeMirrorEditor from './codemirror/CodeMirror.vue';
import { isString } from '/@/utils/is';
const props = { const props = defineProps({
value: { type: [Object, String] as PropType<Record<string, any> | string> }, value: { type: [Object, String] as PropType<Record<string, any> | string> },
mode: { type: String, default: MODE.JSON }, mode: { type: String, default: MODE.JSON },
readonly: { type: Boolean }, readonly: { type: Boolean },
}; });
const emit = defineEmits(['change', 'update:value']);
export default defineComponent({
name: 'CodeEditor',
components: { CodeMirrorEditor },
props,
emits: ['change', 'update:value'],
setup(props, { emit }) {
const getValue = computed(() => { const getValue = computed(() => {
const { value, mode } = props; const { value, mode } = props;
if (mode !== MODE.JSON) { if (mode !== MODE.JSON) {
@ -45,8 +43,4 @@
emit('update:value', v); emit('update:value', v);
emit('change', v); emit('change', v);
} }
return { handleValueChange, getValue };
},
});
</script> </script>

View File

@ -2,17 +2,8 @@
<div class="relative !h-full w-full overflow-hidden" ref="el"> </div> <div class="relative !h-full w-full overflow-hidden" ref="el"> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { import { ref, onMounted, onUnmounted, watchEffect, watch, unref, nextTick } from 'vue';
ref,
onMounted,
onUnmounted,
watchEffect,
watch,
defineComponent,
unref,
nextTick,
} from 'vue';
import { useDebounceFn } from '@vueuse/core'; import { useDebounceFn } from '@vueuse/core';
import { useAppStore } from '/@/store/modules/app'; import { useAppStore } from '/@/store/modules/app';
import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn'; import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn';
@ -26,16 +17,14 @@
import 'codemirror/mode/css/css'; import 'codemirror/mode/css/css';
import 'codemirror/mode/htmlmixed/htmlmixed'; import 'codemirror/mode/htmlmixed/htmlmixed';
const props = { const props = defineProps({
mode: { type: String, default: 'application/json' }, mode: { type: String, default: 'application/json' },
value: { type: String, default: '' }, value: { type: String, default: '' },
readonly: { type: Boolean, default: false }, readonly: { type: Boolean, default: false },
}; });
const emit = defineEmits(['change']);
export default defineComponent({
props,
emits: ['change'],
setup(props, { emit }) {
const el = ref(); const el = ref();
let editor: Nullable<CodeMirror.Editor>; let editor: Nullable<CodeMirror.Editor>;
@ -113,8 +102,4 @@
onUnmounted(() => { onUnmounted(() => {
editor = null; editor = null;
}); });
return { el };
},
});
</script> </script>

View File

@ -2,13 +2,11 @@
<vue-json-pretty :path="'res'" :deep="3" :showLength="true" :data="data" /> <vue-json-pretty :path="'res'" :deep="3" :showLength="true" :data="data" />
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import VueJsonPretty from 'vue-json-pretty'; import VueJsonPretty from 'vue-json-pretty';
import 'vue-json-pretty/lib/styles.css'; import 'vue-json-pretty/lib/styles.css';
import { defineComponent } from 'vue';
export default defineComponent({ defineProps({
name: 'JsonPreview', data: Object,
components: { VueJsonPretty },
props: { data: Object },
}); });
</script> </script>

View File

@ -22,9 +22,9 @@
</div> </div>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import type { PropType } from 'vue'; import type { PropType } from 'vue';
import { defineComponent, ref } from 'vue'; import { ref } from 'vue';
// component // component
import { Skeleton } from 'ant-design-vue'; import { Skeleton } from 'ant-design-vue';
import { CollapseTransition } from '/@/components/Transition'; import { CollapseTransition } from '/@/components/Transition';
@ -34,7 +34,7 @@
import { useTimeoutFn } from '/@/hooks/core/useTimeout'; import { useTimeoutFn } from '/@/hooks/core/useTimeout';
import { useDesign } from '/@/hooks/web/useDesign'; import { useDesign } from '/@/hooks/web/useDesign';
const props = { const props = defineProps({
title: { type: String, default: '' }, title: { type: String, default: '' },
loading: { type: Boolean }, loading: { type: Boolean },
/** /**
@ -57,17 +57,8 @@
* Delayed loading time * Delayed loading time
*/ */
lazyTime: { type: Number, default: 0 }, lazyTime: { type: Number, default: 0 },
}; });
export default defineComponent({
name: 'CollapseContainer',
components: {
Skeleton,
CollapseHeader,
CollapseTransition,
},
props,
setup(props) {
const show = ref(true); const show = ref(true);
const { prefixCls } = useDesign('collapse-container'); const { prefixCls } = useDesign('collapse-container');
@ -82,14 +73,6 @@
useTimeoutFn(triggerWindowResize, 200); useTimeoutFn(triggerWindowResize, 200);
} }
} }
return {
show,
handleExpand,
prefixCls,
};
},
});
</script> </script>
<style lang="less"> <style lang="less">
@prefix-cls: ~'@{namespace}-collapse-container'; @prefix-cls: ~'@{namespace}-collapse-container';

View File

@ -11249,10 +11249,10 @@ vite-plugin-windicss@^1.2.7:
debug "^4.3.2" debug "^4.3.2"
windicss "^3.1.6" windicss "^3.1.6"
vite@2.5.0-beta.2: vite@2.5.0:
version "2.5.0-beta.2" version "2.5.0"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.5.0-beta.2.tgz#3b71eecb17b7e62869366a91e92bd26578bb4f7f" resolved "https://registry.yarnpkg.com/vite/-/vite-2.5.0.tgz#111ba3679432d426e44566acf480005a7914cbd6"
integrity sha512-PgPOlTg7w6VGDx1HCUHfDoXeQ6cWKCO2tHz3om27VLjfu/92T1kyhuJf/VM6sa+orPOkTLUZWaHI9bPQjgtLrA== integrity sha512-Dn4B+g54PJsMG5WCc4QeFy1ygMXRdTtFrUPegqfk4+vzVQcbF/DqqmI/1bxezArzbujBJg/67QeT5wz8edfJVQ==
dependencies: dependencies:
esbuild "^0.12.17" esbuild "^0.12.17"
postcss "^8.3.6" postcss "^8.3.6"