mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-05 19:41:40 +08:00
parent
e3b7f587ee
commit
e2d784176b
30
packages/design/.npmignore
Normal file
30
packages/design/.npmignore
Normal file
@ -0,0 +1,30 @@
|
||||
.babelrc
|
||||
.eslintrc
|
||||
.editorconfig
|
||||
node_modules
|
||||
.DS_Store
|
||||
examples
|
||||
tests
|
||||
.code.yml
|
||||
reports
|
||||
tsconfig.json
|
||||
vite.config.ts
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Log files
|
||||
npm-debug.log*
|
||||
pnpm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Editor directories and files
|
||||
.idea
|
||||
.vscode
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
53
packages/design/package.json
Normal file
53
packages/design/package.json
Normal file
@ -0,0 +1,53 @@
|
||||
{
|
||||
"version": "1.2.0-beta.2",
|
||||
"name": "@tmagic/design",
|
||||
"sideEffects": [
|
||||
"dist/*"
|
||||
],
|
||||
"main": "dist/tmagic-design.umd.js",
|
||||
"module": "dist/tmagic-design.mjs",
|
||||
"types": "types/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/tmagic-design.mjs",
|
||||
"require": "./dist/tmagic-design.umd.js"
|
||||
},
|
||||
"./*": "./*"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"scripts": {
|
||||
"build": "npm run build:type && vite build",
|
||||
"build:type": "npm run clear:type && vue-tsc --declaration --emitDeclarationOnly --project tsconfig.build.json",
|
||||
"clear:type": "rimraf ./types"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Tencent/tmagic-editor.git"
|
||||
},
|
||||
"homepage": "https://tencent.github.io/tmagic-editor/docs/",
|
||||
"keywords": [
|
||||
"design",
|
||||
"vue",
|
||||
"vue3",
|
||||
"typescript"
|
||||
],
|
||||
"dependencies": {
|
||||
"vue": "^3.2.37"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vue": "^3.2.37"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^15.12.4",
|
||||
"@vitejs/plugin-vue": "^3.1.0",
|
||||
"@vue/compiler-sfc": "^3.2.37",
|
||||
"@vue/test-utils": "^2.0.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.7.4",
|
||||
"vite": "^3.1.3",
|
||||
"vue-tsc": "^0.39.4"
|
||||
}
|
||||
}
|
28
packages/design/src/Button.vue
Normal file
28
packages/design/src/Button.vue
Normal file
@ -0,0 +1,28 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps" @click="clickHandler">
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
type?: string;
|
||||
size?: string;
|
||||
text?: boolean;
|
||||
icon?: any;
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').button;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const emit = defineEmits(['click']);
|
||||
|
||||
const clickHandler = (...args: any[]) => {
|
||||
emit('click', ...args);
|
||||
};
|
||||
</script>
|
23
packages/design/src/Card.vue
Normal file
23
packages/design/src/Card.vue
Normal file
@ -0,0 +1,23 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps">
|
||||
<template #header>
|
||||
<slot name="header"></slot>
|
||||
</template>
|
||||
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
bodyStyle?: Record<string, any>;
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').card;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
</script>
|
61
packages/design/src/Cascader.vue
Normal file
61
packages/design/src/Cascader.vue
Normal file
@ -0,0 +1,61 @@
|
||||
<template>
|
||||
<component
|
||||
ref="cascader"
|
||||
:is="uiComponent.component"
|
||||
v-bind="uiProps"
|
||||
@update:modelValue="updateModelValue"
|
||||
@change="changeHandler"
|
||||
></component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
import { CascaderOption } from './type';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue?: any;
|
||||
placeholder?: string;
|
||||
disabled?: boolean;
|
||||
clearable?: boolean;
|
||||
filterable?: boolean;
|
||||
options?: CascaderOption[];
|
||||
size?: 'mini' | 'small' | 'medium';
|
||||
props: {
|
||||
expandTrigger?: 'click' | 'hover';
|
||||
multiple?: boolean;
|
||||
checkStrictly?: boolean;
|
||||
emitPath?: boolean;
|
||||
lazy?: boolean;
|
||||
};
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').cascader;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const cascader = ref<any>();
|
||||
|
||||
const emit = defineEmits(['change', 'update:modelValue']);
|
||||
|
||||
const changeHandler = (v: any) => {
|
||||
emit('change', v);
|
||||
};
|
||||
|
||||
const updateModelValue = (v: any) => {
|
||||
emit('update:modelValue', v);
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
setQuery(v: any) {
|
||||
if (!cascader.value) return;
|
||||
cascader.value.query = v;
|
||||
},
|
||||
|
||||
setPreviousQuery(v: any) {
|
||||
if (!cascader.value) return;
|
||||
cascader.value.previousQuery = v;
|
||||
},
|
||||
});
|
||||
</script>
|
42
packages/design/src/Checkbox.vue
Normal file
42
packages/design/src/Checkbox.vue
Normal file
@ -0,0 +1,42 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps" @update:modelValue="updateModelValue" @change="changeHandler">
|
||||
<template #default>
|
||||
<slot></slot>
|
||||
</template>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue?: string | number | boolean;
|
||||
label?: any;
|
||||
trueLabel?: string | number | boolean;
|
||||
falseLabel?: string | number | boolean;
|
||||
disabled?: boolean;
|
||||
size?: 'mini' | 'small' | 'medium';
|
||||
}>(),
|
||||
{
|
||||
trueLabel: undefined,
|
||||
falseLabel: undefined,
|
||||
},
|
||||
);
|
||||
|
||||
const uiComponent = getConfig('components').checkbox;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const emit = defineEmits(['change', 'update:modelValue']);
|
||||
|
||||
const changeHandler = (v: any) => {
|
||||
emit('change', v);
|
||||
};
|
||||
|
||||
const updateModelValue = (v: any) => {
|
||||
emit('update:modelValue', v);
|
||||
};
|
||||
</script>
|
32
packages/design/src/CheckboxGroup.vue
Normal file
32
packages/design/src/CheckboxGroup.vue
Normal file
@ -0,0 +1,32 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps" @change="changeHandler" @update:modelValue="updateModelValue">
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue?: any[];
|
||||
label?: string;
|
||||
disabled?: boolean;
|
||||
size?: 'mini' | 'small' | 'medium';
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').checkboxGroup;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const emit = defineEmits(['change', 'update:modelValue']);
|
||||
|
||||
const changeHandler = (v: any) => {
|
||||
emit('change', v);
|
||||
};
|
||||
|
||||
const updateModelValue = (v: any) => {
|
||||
emit('update:modelValue', v);
|
||||
};
|
||||
</script>
|
19
packages/design/src/Col.vue
Normal file
19
packages/design/src/Col.vue
Normal file
@ -0,0 +1,19 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps">
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
span?: number;
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').col;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
</script>
|
37
packages/design/src/ColorPicker.vue
Normal file
37
packages/design/src/ColorPicker.vue
Normal file
@ -0,0 +1,37 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps" @change="changeHandler" @update:modelValue="updateModelValue">
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue?: string;
|
||||
disabled?: boolean;
|
||||
showAlpha?: boolean;
|
||||
size?: 'mini' | 'small' | 'medium';
|
||||
}>(),
|
||||
{
|
||||
showAlpha: false,
|
||||
disabled: false,
|
||||
},
|
||||
);
|
||||
|
||||
const uiComponent = getConfig('components').colorPicker;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const emit = defineEmits(['change', 'update:modelValue']);
|
||||
|
||||
const changeHandler = (v: any) => {
|
||||
emit('change', v);
|
||||
};
|
||||
|
||||
const updateModelValue = (v: any) => {
|
||||
emit('update:modelValue', v);
|
||||
};
|
||||
</script>
|
46
packages/design/src/DatePicker.vue
Normal file
46
packages/design/src/DatePicker.vue
Normal file
@ -0,0 +1,46 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps" @change="changeHandler" @update:modelValue="updateModelValue">
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
type?: string;
|
||||
modelValue?: any;
|
||||
disabled?: boolean;
|
||||
placeholder?: string;
|
||||
rangeSeparator?: string;
|
||||
startPlaceholder?: string;
|
||||
endPlaceholder?: string;
|
||||
format?: string;
|
||||
/** 可选,绑定值的格式。 不指定则绑定值为 Date 对象 */
|
||||
valueFormat?: string;
|
||||
/** 在范围选择器里取消两个日期面板之间的联动 */
|
||||
unlinkPanels?: boolean;
|
||||
defaultTime?: any;
|
||||
size?: 'mini' | 'small' | 'medium';
|
||||
}>(),
|
||||
{
|
||||
type: 'date',
|
||||
},
|
||||
);
|
||||
|
||||
const uiComponent = getConfig('components').datePicker;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const emit = defineEmits(['change', 'update:modelValue']);
|
||||
|
||||
const changeHandler = (v: any) => {
|
||||
emit('change', v);
|
||||
};
|
||||
|
||||
const updateModelValue = (v: any) => {
|
||||
emit('update:modelValue', v);
|
||||
};
|
||||
</script>
|
39
packages/design/src/Dialog.vue
Normal file
39
packages/design/src/Dialog.vue
Normal file
@ -0,0 +1,39 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps" @close="closeHandler" @update:modelValue="updateModelValue">
|
||||
<slot></slot>
|
||||
|
||||
<template #footer>
|
||||
<slot name="footer"></slot>
|
||||
</template>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue?: boolean;
|
||||
appendToBody?: boolean;
|
||||
title?: string;
|
||||
width?: string | number;
|
||||
fullscreen?: boolean;
|
||||
closeOnClickModal?: boolean;
|
||||
labelPosition?: string;
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').dialog;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const emit = defineEmits(['close', 'update:modelValue']);
|
||||
|
||||
const closeHandler = (...args: any[]) => {
|
||||
emit('close', ...args);
|
||||
};
|
||||
|
||||
const updateModelValue = (v: any) => {
|
||||
emit('update:modelValue', v);
|
||||
};
|
||||
</script>
|
35
packages/design/src/Form.vue
Normal file
35
packages/design/src/Form.vue
Normal file
@ -0,0 +1,35 @@
|
||||
<template>
|
||||
<component ref="form" :is="uiComponent.component" v-bind="uiProps">
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const form = ref<any>();
|
||||
|
||||
const props = defineProps<{
|
||||
model?: any;
|
||||
labelWidth?: string;
|
||||
disabled?: boolean;
|
||||
inline?: boolean;
|
||||
labelPosition?: string;
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').form;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
defineExpose({
|
||||
validate() {
|
||||
form.value?.validate();
|
||||
},
|
||||
|
||||
resetFields() {
|
||||
form.value?.resetFields();
|
||||
},
|
||||
});
|
||||
</script>
|
23
packages/design/src/FormItem.vue
Normal file
23
packages/design/src/FormItem.vue
Normal file
@ -0,0 +1,23 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps">
|
||||
<template #label>
|
||||
<slot name="label"></slot>
|
||||
</template>
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
const props = defineProps<{
|
||||
prop?: string;
|
||||
labelWidth?: string;
|
||||
rules?: any;
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').formItem;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
</script>
|
11
packages/design/src/Icon.vue
Normal file
11
packages/design/src/Icon.vue
Normal file
@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component">
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { getConfig } from './config';
|
||||
|
||||
const uiComponent = getConfig('components').icon;
|
||||
</script>
|
46
packages/design/src/Input.vue
Normal file
46
packages/design/src/Input.vue
Normal file
@ -0,0 +1,46 @@
|
||||
<template>
|
||||
<component
|
||||
:is="uiComponent.component"
|
||||
v-bind="uiProps"
|
||||
@change="changeHandler"
|
||||
@input="inputHandler"
|
||||
@update:modelValue="updateModelValue"
|
||||
>
|
||||
<template #append v-if="$slots.prepend">
|
||||
<slot name="append"></slot>
|
||||
</template>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue?: string | number | boolean;
|
||||
clearable?: boolean;
|
||||
disabled?: boolean;
|
||||
placeholder?: string;
|
||||
type?: string;
|
||||
size?: 'mini' | 'small' | 'medium';
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').input;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const emit = defineEmits(['change', 'input', 'update:modelValue']);
|
||||
|
||||
const changeHandler = (...args: any[]) => {
|
||||
emit('change', ...args);
|
||||
};
|
||||
|
||||
const inputHandler = (...args: any[]) => {
|
||||
emit('input', ...args);
|
||||
};
|
||||
|
||||
const updateModelValue = (...args: any[]) => {
|
||||
emit('update:modelValue', ...args);
|
||||
};
|
||||
</script>
|
45
packages/design/src/InputNumber.vue
Normal file
45
packages/design/src/InputNumber.vue
Normal file
@ -0,0 +1,45 @@
|
||||
<template>
|
||||
<component
|
||||
:is="uiComponent.component"
|
||||
v-bind="uiProps"
|
||||
@change="changeHandler"
|
||||
@input="inputHandler"
|
||||
@update:modelValue="updateModelValue"
|
||||
></component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue?: string | number | boolean;
|
||||
clearable?: boolean;
|
||||
controlsPosition?: string;
|
||||
disabled?: boolean;
|
||||
placeholder?: string;
|
||||
step?: number;
|
||||
min?: number;
|
||||
max?: number;
|
||||
size?: 'mini' | 'small' | 'medium';
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').inputNumber;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const emit = defineEmits(['change', 'input', 'update:modelValue']);
|
||||
|
||||
const changeHandler = (...args: any[]) => {
|
||||
emit('change', ...args);
|
||||
};
|
||||
|
||||
const inputHandler = (...args: any[]) => {
|
||||
emit('input', ...args);
|
||||
};
|
||||
|
||||
const updateModelValue = (...args: any[]) => {
|
||||
emit('update:modelValue', ...args);
|
||||
};
|
||||
</script>
|
21
packages/design/src/Option.vue
Normal file
21
packages/design/src/Option.vue
Normal file
@ -0,0 +1,21 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps">
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
value?: any;
|
||||
label?: string;
|
||||
disabled?: boolean;
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').option;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
</script>
|
20
packages/design/src/OptionGroup.vue
Normal file
20
packages/design/src/OptionGroup.vue
Normal file
@ -0,0 +1,20 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps">
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
label?: string;
|
||||
disabled?: boolean;
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').optionGroup;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
</script>
|
36
packages/design/src/Pagination.vue
Normal file
36
packages/design/src/Pagination.vue
Normal file
@ -0,0 +1,36 @@
|
||||
<template>
|
||||
<component
|
||||
:is="uiComponent.component"
|
||||
v-bind="uiProps"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
></component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
layout?: string;
|
||||
hideOnSinglePage?: boolean;
|
||||
curPage?: number;
|
||||
pageSizes?: number[];
|
||||
pagesize?: number;
|
||||
total?: number;
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').pagination;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const emit = defineEmits(['size-change', 'current-change']);
|
||||
|
||||
const handleSizeChange = (args: any[]) => {
|
||||
emit('size-change', ...args);
|
||||
};
|
||||
const handleCurrentChange = (args: any[]) => {
|
||||
emit('current-change', ...args);
|
||||
};
|
||||
</script>
|
19
packages/design/src/Radio.vue
Normal file
19
packages/design/src/Radio.vue
Normal file
@ -0,0 +1,19 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps">
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
label?: string | number | boolean;
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').radio;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
</script>
|
31
packages/design/src/RadioGroup.vue
Normal file
31
packages/design/src/RadioGroup.vue
Normal file
@ -0,0 +1,31 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps" @change="changeHandler" @update:modelValue="updateModelValue">
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue?: string | number | boolean;
|
||||
disabled?: boolean;
|
||||
size?: 'mini' | 'small' | 'medium';
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').radioGroup;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const emit = defineEmits(['change', 'update:modelValue']);
|
||||
|
||||
const changeHandler = (v: any) => {
|
||||
emit('change', v);
|
||||
};
|
||||
|
||||
const updateModelValue = (v: any) => {
|
||||
emit('update:modelValue', v);
|
||||
};
|
||||
</script>
|
11
packages/design/src/Row.vue
Normal file
11
packages/design/src/Row.vue
Normal file
@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component">
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { getConfig } from './config';
|
||||
|
||||
const uiComponent = getConfig('components').row;
|
||||
</script>
|
83
packages/design/src/Select.vue
Normal file
83
packages/design/src/Select.vue
Normal file
@ -0,0 +1,83 @@
|
||||
<template>
|
||||
<component
|
||||
ref="select"
|
||||
:is="uiComponent.component"
|
||||
v-bind="uiProps"
|
||||
@change="changeHandler"
|
||||
@visible-change="visibleHandler"
|
||||
@update:modelValue="updateModelValue"
|
||||
>
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const select = ref<any>();
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue?: any;
|
||||
clearable?: boolean;
|
||||
filterable?: boolean;
|
||||
popperClass?: string;
|
||||
disabled?: boolean;
|
||||
placeholder?: string;
|
||||
remote?: boolean;
|
||||
multiple?: boolean;
|
||||
allowCreate?: boolean;
|
||||
valueKey?: string;
|
||||
remoteMethod?: any;
|
||||
size?: 'mini' | 'small' | 'medium';
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').select;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const emit = defineEmits(['change', 'update:modelValue', 'visibleHandler']);
|
||||
|
||||
const changeHandler = (v: any) => {
|
||||
emit('change', v);
|
||||
};
|
||||
|
||||
const updateModelValue = (v: any) => {
|
||||
emit('update:modelValue', v);
|
||||
};
|
||||
|
||||
const visibleHandler = (v: any) => {
|
||||
emit('visibleHandler', v);
|
||||
};
|
||||
|
||||
const scrollbarWrap = ref<HTMLDivElement | undefined>();
|
||||
|
||||
onMounted(() => {
|
||||
scrollbarWrap.value = select.value?.scrollbar.wrap$;
|
||||
});
|
||||
|
||||
defineExpose({
|
||||
scrollbarWrap,
|
||||
|
||||
setQuery(v: string) {
|
||||
if (!select.value) return;
|
||||
select.value.query = v;
|
||||
},
|
||||
|
||||
setPreviousQuery(v: string) {
|
||||
if (!select.value) return;
|
||||
select.value.previousQuery = v;
|
||||
},
|
||||
|
||||
setSelectedLabel(v: string) {
|
||||
if (!select.value) return;
|
||||
select.value.selectedLabel = v;
|
||||
},
|
||||
|
||||
setSelected() {
|
||||
if (!select.value) return;
|
||||
select.value.setSelected();
|
||||
},
|
||||
});
|
||||
</script>
|
26
packages/design/src/Step.vue
Normal file
26
packages/design/src/Step.vue
Normal file
@ -0,0 +1,26 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps" @click="clickHandler">
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
title?: string;
|
||||
active?: number;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits(['click']);
|
||||
|
||||
const clickHandler = (...args: any[]) => {
|
||||
emit('click', ...args);
|
||||
};
|
||||
|
||||
const uiComponent = getConfig('components').step;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
</script>
|
20
packages/design/src/Steps.vue
Normal file
20
packages/design/src/Steps.vue
Normal file
@ -0,0 +1,20 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps">
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
active?: number;
|
||||
space?: number | string;
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').steps;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
</script>
|
36
packages/design/src/Switch.vue
Normal file
36
packages/design/src/Switch.vue
Normal file
@ -0,0 +1,36 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps" @update:modelValue="updateModelValue" @change="changeHandler">
|
||||
<template #default>
|
||||
<slot></slot>
|
||||
</template>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue?: string | number | boolean;
|
||||
label?: any;
|
||||
activeValue?: string | number | boolean;
|
||||
inactiveValue?: string | number | boolean;
|
||||
disabled?: boolean;
|
||||
size?: 'mini' | 'small' | 'medium';
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').switch;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const emit = defineEmits(['change', 'update:modelValue']);
|
||||
|
||||
const changeHandler = (v: any) => {
|
||||
emit('change', v);
|
||||
};
|
||||
|
||||
const updateModelValue = (v: any) => {
|
||||
emit('update:modelValue', v);
|
||||
};
|
||||
</script>
|
22
packages/design/src/TabPane.vue
Normal file
22
packages/design/src/TabPane.vue
Normal file
@ -0,0 +1,22 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps">
|
||||
<template #default>
|
||||
<slot></slot>
|
||||
</template>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
name?: string;
|
||||
label?: string;
|
||||
lazy?: boolean;
|
||||
}>();
|
||||
const uiComponent = getConfig('components').tabPane;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
</script>
|
57
packages/design/src/Table.vue
Normal file
57
packages/design/src/Table.vue
Normal file
@ -0,0 +1,57 @@
|
||||
<template>
|
||||
<component
|
||||
ref="table"
|
||||
:is="uiComponent.component"
|
||||
v-bind="uiProps"
|
||||
@select="selectHandler"
|
||||
@sort-change="sortChangeHandler"
|
||||
>
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
data?: any[];
|
||||
border?: boolean;
|
||||
maxHeight?: number | string;
|
||||
defaultExpandAll?: boolean;
|
||||
}>(),
|
||||
{
|
||||
data: () => [],
|
||||
},
|
||||
);
|
||||
|
||||
const uiComponent = getConfig('components').table;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const emit = defineEmits(['select', 'sort-change']);
|
||||
|
||||
const table = ref<any>();
|
||||
|
||||
const selectHandler = (...args: any[]) => {
|
||||
emit('select', ...args);
|
||||
};
|
||||
|
||||
const sortChangeHandler = (...args: any[]) => {
|
||||
emit('sort-change', ...args);
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
$el: table.value?.$el,
|
||||
|
||||
clearSelection(...args: any[]) {
|
||||
table.value?.clearSelection(...args);
|
||||
},
|
||||
|
||||
toggleRowSelection(...args: any[]) {
|
||||
table.value?.toggleRowSelection(...args);
|
||||
},
|
||||
});
|
||||
</script>
|
24
packages/design/src/TableColumn.vue
Normal file
24
packages/design/src/TableColumn.vue
Normal file
@ -0,0 +1,24 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps">
|
||||
<template #default="{ $index, row }">
|
||||
<slot :$index="$index" :row="row"></slot>
|
||||
</template>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
label?: string;
|
||||
align?: string;
|
||||
fixed?: string | boolean;
|
||||
width?: string | number;
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').tableColumn;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
</script>
|
43
packages/design/src/Tabs.vue
Normal file
43
packages/design/src/Tabs.vue
Normal file
@ -0,0 +1,43 @@
|
||||
<template>
|
||||
<component
|
||||
:is="uiComponent.component"
|
||||
v-bind="uiProps"
|
||||
@tab-click="tabClickHandler"
|
||||
@tab-add="onTabAdd"
|
||||
@tab-remove="onTabRemove"
|
||||
>
|
||||
<template #default>
|
||||
<slot></slot>
|
||||
</template>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
type?: string;
|
||||
editable?: boolean;
|
||||
tabPosition?: string;
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').tabs;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const emit = defineEmits(['tab-click', 'tab-add', 'tab-remove']);
|
||||
|
||||
const tabClickHandler = (...args: any[]) => {
|
||||
emit('tab-click', ...args);
|
||||
};
|
||||
|
||||
const onTabAdd = (...args: any[]) => {
|
||||
emit('tab-add', ...args);
|
||||
};
|
||||
|
||||
const onTabRemove = (...args: any[]) => {
|
||||
emit('tab-remove', ...args);
|
||||
};
|
||||
</script>
|
31
packages/design/src/TimePicker.vue
Normal file
31
packages/design/src/TimePicker.vue
Normal file
@ -0,0 +1,31 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps" @change="changeHandler" @update:modelValue="updateModelValue">
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue?: any;
|
||||
disabled?: boolean;
|
||||
placeholder?: string;
|
||||
size?: 'mini' | 'small' | 'medium';
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').timePicker;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const emit = defineEmits(['change', 'update:modelValue']);
|
||||
|
||||
const changeHandler = (v: any) => {
|
||||
emit('change', v);
|
||||
};
|
||||
|
||||
const updateModelValue = (v: any) => {
|
||||
emit('update:modelValue', v);
|
||||
};
|
||||
</script>
|
24
packages/design/src/Tooltip.vue
Normal file
24
packages/design/src/Tooltip.vue
Normal file
@ -0,0 +1,24 @@
|
||||
<template>
|
||||
<component :is="uiComponent.component" v-bind="uiProps">
|
||||
<template #content>
|
||||
<slot name="content"></slot>
|
||||
</template>
|
||||
<slot></slot>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
placement?: string;
|
||||
disabled?: boolean;
|
||||
content?: string;
|
||||
}>();
|
||||
|
||||
const uiComponent = getConfig('components').tooltip;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
</script>
|
31
packages/design/src/Upload.vue
Normal file
31
packages/design/src/Upload.vue
Normal file
@ -0,0 +1,31 @@
|
||||
<template>
|
||||
<component ref="upload" :is="uiComponent.component" v-bind="uiProps" @change="changeHandler"></component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { getConfig } from './config';
|
||||
|
||||
const props = defineProps<{
|
||||
action?: string;
|
||||
autoUpload?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits(['change']);
|
||||
|
||||
const changeHandler = (...args: any[]) => {
|
||||
emit('change', ...args);
|
||||
};
|
||||
const uiComponent = getConfig('components').upload;
|
||||
|
||||
const uiProps = computed(() => uiComponent.props(props));
|
||||
|
||||
const upload = ref<any>();
|
||||
|
||||
defineExpose({
|
||||
clearFiles(...args: any[]) {
|
||||
upload.value?.clearFiles(...args);
|
||||
},
|
||||
});
|
||||
</script>
|
29
packages/design/src/config.ts
Normal file
29
packages/design/src/config.ts
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
||||
*
|
||||
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { PluginOptions } from './type';
|
||||
|
||||
let $MAGIC_DESIGN: PluginOptions = {};
|
||||
|
||||
const setConfig = (options: PluginOptions): void => {
|
||||
$MAGIC_DESIGN = options;
|
||||
};
|
||||
|
||||
const getConfig = (key: keyof PluginOptions): any => $MAGIC_DESIGN[key];
|
||||
|
||||
export { getConfig, setConfig };
|
48
packages/design/src/index.ts
Normal file
48
packages/design/src/index.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { App } from 'vue';
|
||||
|
||||
import { getConfig, setConfig } from './config';
|
||||
import { PluginOptions, TMagicMessage } from './type';
|
||||
|
||||
export * from './type';
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
export { default as TMagicButton } from './Button.vue';
|
||||
export { default as TMagicCard } from './Card.vue';
|
||||
export { default as TMagicCascader } from './Cascader.vue';
|
||||
export { default as TMagicCheckbox } from './Checkbox.vue';
|
||||
export { default as TMagicCheckboxGroup } from './CheckboxGroup.vue';
|
||||
export { default as TMagicCol } from './Col.vue';
|
||||
export { default as TMagicColorPicker } from './ColorPicker.vue';
|
||||
export { default as TMagicDatePicker } from './DatePicker.vue';
|
||||
export { default as TMagicDialog } from './Dialog.vue';
|
||||
export { default as TMagicForm } from './Form.vue';
|
||||
export { default as TMagicFormItem } from './FormItem.vue';
|
||||
export { default as TMagicIcon } from './Icon.vue';
|
||||
export { default as TMagicInput } from './Input.vue';
|
||||
export { default as TMagicInputNumber } from './InputNumber.vue';
|
||||
export { default as TMagicOption } from './Option.vue';
|
||||
export { default as TMagicOptionGroup } from './OptionGroup.vue';
|
||||
export { default as TMagicPagination } from './Pagination.vue';
|
||||
export { default as TMagicRadio } from './Radio.vue';
|
||||
export { default as TMagicRadioGroup } from './RadioGroup.vue';
|
||||
export { default as TMagicRow } from './Row.vue';
|
||||
export { default as TMagicSelect } from './Select.vue';
|
||||
export { default as TMagicStep } from './Step.vue';
|
||||
export { default as TMagicSteps } from './Steps.vue';
|
||||
export { default as TMagicSwitch } from './Switch.vue';
|
||||
export { default as TMagicTable } from './Table.vue';
|
||||
export { default as TMagicTableColumn } from './TableColumn.vue';
|
||||
export { default as TMagicTabPane } from './TabPane.vue';
|
||||
export { default as TMagicTabs } from './Tabs.vue';
|
||||
export { default as TMagicTimePicker } from './TimePicker.vue';
|
||||
export { default as TMagicTooltip } from './Tooltip.vue';
|
||||
export { default as TMagicUpload } from './Upload.vue';
|
||||
|
||||
export const tMagicMessage: TMagicMessage = getConfig('message') as TMagicMessage;
|
||||
|
||||
export default {
|
||||
install(app: App, options: PluginOptions) {
|
||||
app.config.globalProperties.$MAGIC_FORM = options;
|
||||
setConfig(options);
|
||||
},
|
||||
};
|
6
packages/design/src/shims-vue.d.ts
vendored
Normal file
6
packages/design/src/shims-vue.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
declare module '*.vue' {
|
||||
import { DefineComponent } from 'vue';
|
||||
|
||||
const component: DefineComponent<{}, {}, any>;
|
||||
export default component;
|
||||
}
|
20
packages/design/src/type.ts
Normal file
20
packages/design/src/type.ts
Normal file
@ -0,0 +1,20 @@
|
||||
export interface CascaderOption {
|
||||
/** 指定选项的值为选项对象的某个属性值 */
|
||||
value: any;
|
||||
/** 指定选项标签为选项对象的某个属性值 */
|
||||
label: string;
|
||||
/** 指定选项的子选项为选项对象的某个属性值 */
|
||||
children?: CascaderOption[];
|
||||
}
|
||||
|
||||
export interface TMagicMessage {
|
||||
success: (msg: string) => void;
|
||||
warning: (msg: string) => void;
|
||||
info: (msg: string) => void;
|
||||
error: (msg: string) => void;
|
||||
}
|
||||
|
||||
export interface PluginOptions {
|
||||
message?: TMagicMessage;
|
||||
components?: Record<string, any>;
|
||||
}
|
13
packages/design/tsconfig.build.json
Normal file
13
packages/design/tsconfig.build.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"declaration": true,
|
||||
"declarationDir": "types",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {},
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
}
|
6
packages/design/tsconfig.json
Normal file
6
packages/design/tsconfig.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "../..",
|
||||
},
|
||||
}
|
61
packages/design/vite.config.ts
Normal file
61
packages/design/vite.config.ts
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
||||
*
|
||||
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { defineConfig } from 'vite';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
|
||||
import pkg from './package.json';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
|
||||
optimizeDeps: {
|
||||
esbuildOptions: {
|
||||
define: {
|
||||
global: 'globalThis',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
build: {
|
||||
cssCodeSplit: false,
|
||||
sourcemap: true,
|
||||
minify: false,
|
||||
target: 'esnext',
|
||||
|
||||
lib: {
|
||||
entry: 'src/index.ts',
|
||||
name: 'TMagicDesign',
|
||||
fileName: 'tmagic-design',
|
||||
},
|
||||
|
||||
rollupOptions: {
|
||||
// 确保外部化处理那些你不想打包进库的依赖
|
||||
external(id: string) {
|
||||
return Object.keys(pkg.dependencies).some((k) => new RegExp(`^${k}`).test(id));
|
||||
},
|
||||
|
||||
output: {
|
||||
// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
|
||||
globals: {
|
||||
vue: 'Vue',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user