提交 8fa6015b 编写于 作者: V vben

chore: change to setup syntax

上级 91cbe0a0
...@@ -26,22 +26,20 @@ jobs: ...@@ -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
......
...@@ -7,12 +7,12 @@ ...@@ -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,31 +29,22 @@ ...@@ -29,31 +29,22 @@
* 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');
// get component class const { prefixCls } = useDesign('basic-arrow');
const getClass = computed(() => {
const { expand, up, down, inset } = props;
return [
prefixCls,
{
[`${prefixCls}--active`]: expand,
up,
inset,
down,
},
];
});
return { getClass }; // get component class
}, const getClass = computed(() => {
const { expand, up, down, inset } = props;
return [
prefixCls,
{
[`${prefixCls}--active`]: expand,
up,
inset,
down,
},
];
}); });
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
......
...@@ -4,13 +4,13 @@ ...@@ -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 @@ ...@@ -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 getClass = computed(() => [
prefixCls,
{ [`${prefixCls}-show-span`]: props.span && slots.default },
{ [`${prefixCls}-normal`]: props.normal },
]);
return { prefixCls, getClass };
},
}); });
const { prefixCls } = useDesign('basic-title');
const slots = useSlots();
const getClass = computed(() => [
prefixCls,
{ [`${prefixCls}-show-span`]: props.span && slots.default },
{ [`${prefixCls}-normal`]: props.normal },
]);
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
@prefix-cls: ~'@{namespace}-basic-title'; @prefix-cls: ~'@{namespace}-basic-title';
......
<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', // get component class
components: { Button, Icon }, const attrs = useAttrs({ excludeDefaultKeys: false });
inheritAttrs: false, const getButtonClass = computed(() => {
props: buttonProps, const { color, disabled } = props;
setup(props) { return [
// get component class {
const attrs = useAttrs({ excludeDefaultKeys: false }); [`ant-btn-${color}`]: !!color,
const getButtonClass = computed(() => { [`is-disabled`]: disabled,
const { color, disabled } = props; },
return [ ];
{
[`ant-btn-${color}`]: !!color,
[`is-disabled`]: disabled,
},
];
});
// get inherit binding value
const getBindValue = computed(() => ({ ...unref(attrs), ...props }));
return { getBindValue, getButtonClass };
},
}); });
// get inherit binding value
const getBindValue = computed(() => ({ ...unref(attrs), ...props }));
</script> </script>
...@@ -20,7 +20,6 @@ ...@@ -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 @@ ...@@ -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));
......
...@@ -3,24 +3,17 @@ ...@@ -3,24 +3,17 @@
<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', const wrap = ref<ElRef>(null);
emits: ['mounted', 'clickOutside'],
setup(_, { emit }) {
const wrap = ref<ElRef>(null);
onClickOutside(wrap, () => { onClickOutside(wrap, () => {
emit('clickOutside'); emit('clickOutside');
}); });
onMounted(() => {
emit('mounted');
});
return { wrap }; onMounted(() => {
}, emit('mounted');
}); });
</script> </script>
...@@ -8,45 +8,39 @@ ...@@ -8,45 +8,39 @@
/> />
</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 },
}; });
export default defineComponent({
name: 'CodeEditor',
components: { CodeMirrorEditor },
props,
emits: ['change', 'update:value'],
setup(props, { emit }) {
const getValue = computed(() => {
const { value, mode } = props;
if (mode !== MODE.JSON) {
return value as string;
}
return isString(value)
? JSON.stringify(JSON.parse(value), null, 2)
: JSON.stringify(value, null, 2);
});
function handleValueChange(v) { const emit = defineEmits(['change', 'update:value']);
emit('update:value', v);
emit('change', v);
}
return { handleValueChange, getValue }; const getValue = computed(() => {
}, const { value, mode } = props;
if (mode !== MODE.JSON) {
return value as string;
}
return isString(value)
? JSON.stringify(JSON.parse(value), null, 2)
: JSON.stringify(value, null, 2);
}); });
function handleValueChange(v) {
emit('update:value', v);
emit('change', v);
}
</script> </script>
...@@ -2,17 +2,8 @@ ...@@ -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,95 +17,89 @@ ...@@ -26,95 +17,89 @@
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 },
}; });
export default defineComponent({ const emit = defineEmits(['change']);
props,
emits: ['change'],
setup(props, { emit }) {
const el = ref();
let editor: Nullable<CodeMirror.Editor>;
const debounceRefresh = useDebounceFn(refresh, 100); const el = ref();
const appStore = useAppStore(); let editor: Nullable<CodeMirror.Editor>;
watch( const debounceRefresh = useDebounceFn(refresh, 100);
() => props.value, const appStore = useAppStore();
async (value) => {
await nextTick();
const oldValue = editor?.getValue();
if (value !== oldValue) {
editor?.setValue(value ? value : '');
}
},
{ flush: 'post' }
);
watchEffect(() => { watch(
editor?.setOption('mode', props.mode); () => props.value,
}); async (value) => {
await nextTick();
const oldValue = editor?.getValue();
if (value !== oldValue) {
editor?.setValue(value ? value : '');
}
},
{ flush: 'post' }
);
watch( watchEffect(() => {
() => appStore.getDarkMode, editor?.setOption('mode', props.mode);
async () => { });
setTheme();
},
{
immediate: true,
}
);
function setTheme() { watch(
unref(editor)?.setOption( () => appStore.getDarkMode,
'theme', async () => {
appStore.getDarkMode === 'light' ? 'idea' : 'material-palenight' setTheme();
); },
} {
immediate: true,
}
);
function refresh() { function setTheme() {
editor?.refresh(); unref(editor)?.setOption(
} 'theme',
appStore.getDarkMode === 'light' ? 'idea' : 'material-palenight'
);
}
async function init() { function refresh() {
const addonOptions = { editor?.refresh();
autoCloseBrackets: true, }
autoCloseTags: true,
foldGutter: true,
gutters: ['CodeMirror-linenumbers'],
};
editor = CodeMirror(el.value!, { async function init() {
value: '', const addonOptions = {
mode: props.mode, autoCloseBrackets: true,
readOnly: props.readonly, autoCloseTags: true,
tabSize: 2, foldGutter: true,
theme: 'material-palenight', gutters: ['CodeMirror-linenumbers'],
lineWrapping: true, };
lineNumbers: true,
...addonOptions,
});
editor?.setValue(props.value);
setTheme();
editor?.on('change', () => {
emit('change', editor?.getValue());
});
}
onMounted(async () => { editor = CodeMirror(el.value!, {
await nextTick(); value: '',
init(); mode: props.mode,
useWindowSizeFn(debounceRefresh); readOnly: props.readonly,
}); tabSize: 2,
theme: 'material-palenight',
lineWrapping: true,
lineNumbers: true,
...addonOptions,
});
editor?.setValue(props.value);
setTheme();
editor?.on('change', () => {
emit('change', editor?.getValue());
});
}
onUnmounted(() => { onMounted(async () => {
editor = null; await nextTick();
}); init();
useWindowSizeFn(debounceRefresh);
});
return { el }; onUnmounted(() => {
}, editor = null;
}); });
</script> </script>
...@@ -2,13 +2,11 @@ ...@@ -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>
...@@ -22,9 +22,9 @@ ...@@ -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 @@ ...@@ -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,39 +57,22 @@ ...@@ -57,39 +57,22 @@
* 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 { prefixCls } = useDesign('collapse-container'); const show = ref(true);
/** const { prefixCls } = useDesign('collapse-container');
* @description: Handling development events
*/
function handleExpand() {
show.value = !show.value;
if (props.triggerWindowResize) {
// 200 milliseconds here is because the expansion has animation,
useTimeoutFn(triggerWindowResize, 200);
}
}
return { /**
show, * @description: Handling development events
handleExpand, */
prefixCls, function handleExpand() {
}; show.value = !show.value;
}, if (props.triggerWindowResize) {
}); // 200 milliseconds here is because the expansion has animation,
useTimeoutFn(triggerWindowResize, 200);
}
}
</script> </script>
<style lang="less"> <style lang="less">
@prefix-cls: ~'@{namespace}-collapse-container'; @prefix-cls: ~'@{namespace}-collapse-container';
......
...@@ -11249,10 +11249,10 @@ vite-plugin-windicss@^1.2.7: ...@@ -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"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册