tor-univer-sheet 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +2 -0
  2. package/dist/App.vue.d.ts +2 -0
  3. package/dist/components/ContentWrap/index.d.ts +2 -0
  4. package/dist/components/ContentWrap/src/ContentWrap.vue.d.ts +57 -0
  5. package/dist/components/Form/src/componentMap.d.ts +4 -0
  6. package/dist/components/Form/src/components/InputNumberWrapper.vue.d.ts +2 -0
  7. package/dist/components/Form/src/types.d.ts +16 -0
  8. package/dist/components/GlobalLoading/GlobalLoading.vue.d.ts +8 -0
  9. package/dist/components/GlobalLoading/index.d.ts +7 -0
  10. package/dist/components/IndicatorPointSelect/IndicatorPointSelect.vue.d.ts +2 -0
  11. package/dist/components/UniverSheet/UniverSheet.data.d.ts +23 -0
  12. package/dist/components/UniverSheet/UniverSheet.vue.d.ts +515 -0
  13. package/dist/components/UniverSheet/data.d.ts +9 -0
  14. package/dist/components/UniverSheet/plugins/Plugins.d.ts +29 -0
  15. package/dist/components/UniverSheet/plugins/importFile/ImportFileIcon.vue.d.ts +2 -0
  16. package/dist/components/UniverSheet/plugins/importFile/ImportFilePlugin.d.ts +14 -0
  17. package/dist/components/UniverSheet/plugins/index.d.ts +2 -0
  18. package/dist/components/UniverSheet/plugins/indicatorsContextMenu/IndicatorsContextMenuPlugin.d.ts +16 -0
  19. package/dist/components/UniverSheet/plugins/indicatorsContextMenu/components/IndicatorsMenu.vue.d.ts +2 -0
  20. package/dist/components/UniverSheet/plugins/indicatorsContextMenu/components/IndicatorsUniverSheetConfigDialog.vue.d.ts +234 -0
  21. package/dist/components/UniverSheet/plugins/saveButton/ButtonIcon.vue.d.ts +2 -0
  22. package/dist/components/UniverSheet/plugins/saveButton/SaveButton.d.ts +14 -0
  23. package/dist/components/UniverSheet/plugins/syncContextMenu/SyncContextMenu.vue.d.ts +2 -0
  24. package/dist/components/UniverSheet/plugins/syncContextMenu/SyncContextMenuPlugin.d.ts +14 -0
  25. package/dist/components/UniverSheet/plugins/timeConfigContextMenu/TimeConfigContextMenuPlugin.d.ts +16 -0
  26. package/dist/components/UniverSheet/plugins/timeConfigContextMenu/components/TimeConfigMenu.vue.d.ts +2 -0
  27. package/dist/components/UniverSheet/plugins/timeConfigContextMenu/components/TimeConfigUniverSheetConfigDialog.vue.d.ts +234 -0
  28. package/dist/favicon.ico +0 -0
  29. package/dist/hooks/useMessage.d.ts +18 -0
  30. package/dist/index.d.ts +2 -0
  31. package/dist/main.d.ts +0 -0
  32. package/dist/tor-univer-sheet.es.js +213 -0
  33. package/dist/tor-univer-sheet.umd.js +1 -0
  34. package/dist/types/components.d.ts +52 -0
  35. package/dist/types/external-components.d.ts +14 -0
  36. package/dist/types/form.d.ts +51 -0
  37. package/dist/utils/decimal.d.ts +59 -0
  38. package/dist/utils/fileHelp.d.ts +8 -0
  39. package/dist/utils/index.d.ts +2 -0
  40. package/dist/utils/is.d.ts +33 -0
  41. package/dist/utils/propTypes.d.ts +10 -0
  42. package/package.json +88 -0
  43. package/src/App.vue +16 -0
  44. package/src/components/ContentWrap/index.ts +3 -0
  45. package/src/components/ContentWrap/src/ContentWrap.vue +50 -0
  46. package/src/components/Form/src/componentMap.ts +51 -0
  47. package/src/components/Form/src/components/InputNumberWrapper.vue +12 -0
  48. package/src/components/Form/src/types.ts +18 -0
  49. package/src/components/GlobalLoading/GlobalLoading.vue +89 -0
  50. package/src/components/GlobalLoading/index.ts +45 -0
  51. package/src/components/IndicatorPointSelect/IndicatorPointSelect.vue +9 -0
  52. package/src/components/UniverSheet/UniverSheet.data.ts +521 -0
  53. package/src/components/UniverSheet/UniverSheet.vue +339 -0
  54. package/src/components/UniverSheet/data.ts +18 -0
  55. package/src/components/UniverSheet/plugins/Plugins.ts +246 -0
  56. package/src/components/UniverSheet/plugins/importFile/ImportFileIcon.vue +26 -0
  57. package/src/components/UniverSheet/plugins/importFile/ImportFilePlugin.ts +109 -0
  58. package/src/components/UniverSheet/plugins/index.ts +10 -0
  59. package/src/components/UniverSheet/plugins/indicatorsContextMenu/IndicatorsContextMenuPlugin.ts +134 -0
  60. package/src/components/UniverSheet/plugins/indicatorsContextMenu/components/IndicatorsMenu.vue +49 -0
  61. package/src/components/UniverSheet/plugins/indicatorsContextMenu/components/IndicatorsUniverSheetConfigDialog.vue +153 -0
  62. package/src/components/UniverSheet/plugins/saveButton/ButtonIcon.vue +19 -0
  63. package/src/components/UniverSheet/plugins/saveButton/SaveButton.ts +68 -0
  64. package/src/components/UniverSheet/plugins/syncContextMenu/SyncContextMenu.vue +24 -0
  65. package/src/components/UniverSheet/plugins/syncContextMenu/SyncContextMenuPlugin.ts +65 -0
  66. package/src/components/UniverSheet/plugins/timeConfigContextMenu/TimeConfigContextMenuPlugin.ts +133 -0
  67. package/src/components/UniverSheet/plugins/timeConfigContextMenu/components/TimeConfigMenu.vue +10 -0
  68. package/src/components/UniverSheet/plugins/timeConfigContextMenu/components/TimeConfigUniverSheetConfigDialog.vue +152 -0
  69. package/src/hooks/useMessage.ts +93 -0
  70. package/src/index.ts +10 -0
  71. package/src/main.ts +14 -0
  72. package/src/types/components.d.ts +52 -0
  73. package/src/types/external-components.d.ts +16 -0
  74. package/src/types/form.d.ts +52 -0
  75. package/src/utils/decimal.ts +98 -0
  76. package/src/utils/fileHelp.ts +71 -0
  77. package/src/utils/index.ts +32 -0
  78. package/src/utils/is.ts +168 -0
  79. package/src/utils/propTypes.ts +24 -0
@@ -0,0 +1,133 @@
1
+ import { Inject, Injector, Plugin, CommandType, ICommandService, touchDependencies, UniverInstanceType, IUniverInstanceService, Workbook } from '@univerjs/core'
2
+ import { ComponentManager, IMenuManagerService, MenuItemType, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup } from '@univerjs/ui'
3
+ import type { IAccessor, ICommand, Dependency } from '@univerjs/core'
4
+ import type { FWorkbook, FWorksheet, FSelection, FRange } from '@univerjs/preset-sheets-core'
5
+ import { FUniver } from '@univerjs/core/facade';
6
+ import type { ICellData } from '@univerjs/presets'
7
+ import { createVNode, render } from 'vue'
8
+ import { ElConfigProvider } from 'element-plus'
9
+ // 自定义ui
10
+ // import { FolderSingle } from '@univerjs/icons'
11
+ import TimeConfigMenu from './components/TimeConfigMenu.vue'
12
+ // import TimeConfigUniverSheetConfigDialog from './components/TimeConfigUniverSheetConfigDialog.vue'
13
+
14
+
15
+ // import saveIcon from '@/assets/icons/saveIcon.svg'
16
+
17
+ // 定义一个名为 CustomButtonPlugin 的类,继承自 Plugin 类
18
+ class TimeConfigContextMenuPlugin extends Plugin {
19
+ static override pluginName = 'TimeConfigContextMenuPlugin'
20
+ univerApi: FUniver = {} as FUniver
21
+ dialogRef: any = null
22
+
23
+ constructor(
24
+ _config: any,
25
+ // inject injector, required
26
+ @Inject(Injector) readonly _injector: Injector,
27
+ // inject menu service, to add toolbar button
28
+ @Inject(IMenuManagerService) private readonly menuManagerService: IMenuManagerService,
29
+ // inject command service, to register command handler
30
+ @Inject(ICommandService) private readonly commandService: ICommandService,
31
+ // inject component manager, to register icon component
32
+ @Inject(ComponentManager) private readonly componentManager: ComponentManager,
33
+ ) {
34
+ super()
35
+ this.univerApi = _config.univerAPI
36
+ this.dialogRef = _config.dialogRef
37
+ }
38
+
39
+ // 动态挂载 ConfigDialog 并显示弹窗
40
+ private async showConfigDialog(cellData: ICellData, title: '配置时间' | '时间配置详情') {
41
+ return this.dialogRef.open({ cellData, title })
42
+ // // 创建一个容器元素
43
+ // const container = document.createElement('div')
44
+ // document.body.appendChild(container)
45
+
46
+ // // 创建组件实例
47
+ // const vnode = createVNode(TimeConfigUniverSheetConfigDialog, {
48
+ // // 监听 success 事件
49
+ // onSuccess: (data: any) => {
50
+ // console.log('表单提交数据:', data)
51
+ // // 卸载组件
52
+ // render(null, container)
53
+ // document.body.removeChild(container)
54
+ // },
55
+ // // 监听关闭事件
56
+ // onClose: () => {
57
+ // render(null, container)
58
+ // document.body.removeChild(container)
59
+ // },
60
+ // })
61
+
62
+ // // 挂载组件
63
+ // render(vnode, container)
64
+
65
+ // // 调用 open 方法
66
+ // return vnode.component?.exposed?.open({ cellData, title })
67
+
68
+ }
69
+ onStarting(): void {
70
+ this.componentManager.register('TimeConfigMenu', TimeConfigMenu, { framework: 'vue3' })
71
+ // this.univerApi.registerComponent('TimeConfigMenu', TimeConfigMenu, { framework: 'vue3' })
72
+ const buttonId = 'time-config-context-menu-plugin'
73
+ const menuItemFactory = () => ({
74
+ id: buttonId,
75
+ title: '配置时间',
76
+ icon: 'TimeConfigMenu',
77
+ type: MenuItemType.BUTTON,
78
+ })
79
+ this.menuManagerService.mergeMenu({
80
+ [ContextMenuPosition.MAIN_AREA]: {
81
+ [ContextMenuGroup.OTHERS]: {
82
+ [buttonId]: {
83
+ order: 11,
84
+ menuItemFactory,
85
+ },
86
+ }
87
+ }
88
+ })
89
+ const command: ICommand = {
90
+ type: CommandType.OPERATION,
91
+ // command id, same as menu button id
92
+ id: buttonId,
93
+ handler: async (accessor: IAccessor) => {
94
+ const workbook: FWorkbook = this.univerApi.getActiveWorkbook() as FWorkbook;
95
+ const fWorksheet: FWorksheet = workbook.getActiveSheet() as FWorksheet
96
+ const fSelection: FSelection = fWorksheet.getSelection() as FSelection;
97
+ const activeRange: FRange = fSelection.getActiveRange() as FRange;
98
+ console.log('单元格', activeRange.getCellData())
99
+ const customData = await this.showConfigDialog(activeRange.getCellData() as ICellData, '配置时间')
100
+ console.log('customData', customData)
101
+ if (!customData || !Object.keys(customData).length) {
102
+ activeRange.setValue({
103
+ custom: null
104
+ })
105
+ activeRange.deleteNote()
106
+ return true
107
+ }
108
+ activeRange.setValue({
109
+ custom: {
110
+ ...customData,
111
+ cellType: 'time'
112
+ }
113
+ })
114
+ const rowNum = activeRange.getRow()
115
+ const colNum = activeRange.getColumn()
116
+ activeRange.createOrUpdateNote({
117
+ id: `${activeRange.getSheetId()}-${rowNum}-${colNum}`,
118
+ row: rowNum,
119
+ col: colNum,
120
+ note: `周期类型:${customData?.cycleType};时间递增量: ${customData?.timeIncrement}`,
121
+ width: 200,
122
+ height: 100,
123
+ show: false,
124
+ })
125
+ console.log('配置后的单元格', activeRange.getCellData())
126
+ return true;
127
+ }
128
+ }
129
+ this.commandService.registerCommand(command);
130
+ }
131
+ }
132
+
133
+ export default TimeConfigContextMenuPlugin
@@ -0,0 +1,10 @@
1
+ <template>
2
+ <svg t="1772013401059" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5972" width="16" height="16">
3
+ <path
4
+ d="M536.380952 469.77219c7.41181 4.266667 13.58019 10.435048 17.846858 17.846858H633.904762a24.380952 24.380952 0 0 1 0 48.761904h-79.676952A48.761905 48.761905 0 1 1 487.619048 469.77219V365.714286a24.380952 24.380952 0 0 1 48.761904 0v104.057904zM170.666667 73.142857h585.142857l146.285714 146.285714v682.666667a48.761905 48.761905 0 0 1-48.761905 48.761905H170.666667a48.761905 48.761905 0 0 1-48.761905-48.761905V121.904762a48.761905 48.761905 0 0 1 48.761905-48.761905z m560.761904 48.761905v121.904762h121.904762l-121.904762-121.904762z m-29.354666 407.015619c0.560762-5.607619 0.902095-11.215238 0.902095-16.920381 0-5.705143-0.341333-11.312762-0.902095-16.920381l44.422095-33.889524a23.747048 23.747048 0 0 0 5.948952-31.036952l-47.396571-80.018286a25.526857 25.526857 0 0 0-31.036952-10.532571l-52.077715 20.431238a188.294095 188.294095 0 0 0-29.817904-16.920381l-7.899429-54.320762c-1.852952-11.751619-12.55619-20.601905-24.844191-20.601905h-94.768761c-12.434286 0-22.918095 8.655238-24.868572 20.796953l-7.875047 54.125714a191.463619 191.463619 0 0 0-29.842286 16.920381l-52.199619-20.48c-11.239619-4.217905-24.868571 0.414476-30.866286 10.581333l-47.37219 79.993905a23.82019 23.82019 0 0 0 6.095238 31.207619l44.227047 33.743238a168.96 168.96 0 0 0-0.902095 16.920381c0 5.705143 0.341333 11.337143 0.902095 16.920381l-44.495238 33.889524a23.79581 23.79581 0 0 0-5.851428 31.012571l47.420952 80.067048c6.022095 10.142476 19.18781 15.018667 31.036952 10.483809l52.053334-20.431238a188.708571 188.708571 0 0 0 29.817904 16.896l7.899429 54.369524c1.950476 11.946667 12.385524 20.601905 24.81981 20.601905h94.744381c12.288 0 22.942476-8.850286 24.892952-20.796953l7.875048-54.125714a190.268952 190.268952 0 0 0 29.817904-16.944762l52.199619 20.528762a25.673143 25.673143 0 0 0 30.915048-10.605714l47.299048-79.969524c6.192762-10.313143 3.803429-23.405714-6.046477-31.280762l-44.227047-33.694476z"
5
+ fill="#FFB63D"
6
+ p-id="5973"
7
+ ></path>
8
+ </svg>
9
+ </template>
10
+ <script setup lang="ts" name="TimeConfigMenu"></script>
@@ -0,0 +1,152 @@
1
+ <template>
2
+ <el-dialog :model-value="visible" :title="title" width="90%" @close="handleCancel" append-to-body>
3
+ <el-form ref="formRef" :model="formData" label-width="120px">
4
+ <ContentWrap
5
+ class="cst-card"
6
+ v-for="(item, index) of formSchema"
7
+ :key="index"
8
+ :title="item.title"
9
+ >
10
+ <el-row :gutter="16">
11
+ <el-col v-for="(schema, schemaIndex) of item.schemas" :span="6" :key="schemaIndex">
12
+ <el-form-item :label="schema.label" :prop="schema.field" v-bind="schema.formItemProps">
13
+ <component
14
+ :is="componentMap[schema.component!] || componentMap.Input"
15
+ v-model="formData[schema.field]"
16
+ v-bind="
17
+ isFunction(schema.componentProps)
18
+ ? schema.componentProps(formData)
19
+ : schema.componentProps || {}
20
+ "
21
+ :placeholder="`请输入${schema.label}`"
22
+ clearable
23
+ />
24
+ </el-form-item>
25
+ </el-col>
26
+ </el-row>
27
+ </ContentWrap>
28
+ </el-form>
29
+
30
+ <template #footer>
31
+ <el-button @click="handleReset">重置</el-button>
32
+ <el-button type="primary" @click="handleSubmit">确定</el-button>
33
+ </template>
34
+ </el-dialog>
35
+ </template>
36
+
37
+ <script setup lang="ts">
38
+ import { nextTick, ref, computed } from 'vue'
39
+ import ContentWrap from '@/components/ContentWrap/src/ContentWrap.vue'
40
+ import {
41
+ ElConfigProvider,
42
+ ElDialog,
43
+ ElForm,
44
+ ElFormItem,
45
+ ElInput,
46
+ ElButton,
47
+ ElMessage,
48
+ ElRow,
49
+ ElCol,
50
+ } from 'element-plus'
51
+ import type { ICellData } from '@univerjs/presets'
52
+ import { componentMap } from '@/components/Form/src/componentMap'
53
+ import { isEmpty, isFunction, isBoolean } from '@/utils/is'
54
+ import { timeConfigFormSchemas, FormType, ExtendedFormSchema } from '../../Plugins'
55
+
56
+ defineOptions({ name: 'TimeConfigUniverSheetConfigDialog' })
57
+
58
+ let prResolve: any, prReject: any
59
+ const visible = ref(false)
60
+ const title = ref<'配置时间' | '时间详情'>('配置时间')
61
+ const formRef = ref()
62
+
63
+ const formSchema = computed<FormType[]>(() => {
64
+ return timeConfigFormSchemas.map((item) => {
65
+ const arr = item.schemas.filter((item: ExtendedFormSchema) => {
66
+ if (item.hasOwnProperty('hidden')) {
67
+ if (isFunction(item.hidden) && item.hidden(formData.value)) {
68
+ return false
69
+ }
70
+ if (isBoolean(item.hidden) && item.hidden) {
71
+ return false
72
+ }
73
+ }
74
+ return true
75
+ })
76
+ return {
77
+ ...item,
78
+ schemas: arr,
79
+ }
80
+ })
81
+ })
82
+
83
+ const formData = ref<Recordable>({})
84
+ // 动态初始化 formData 默认值
85
+ function initFormData() {
86
+ formSchema.value.forEach((group) => {
87
+ group.schemas.forEach((schema) => {
88
+ if (isEmpty(schema.value)) {
89
+ formData.value[schema.field] = null // 默认值
90
+ } else {
91
+ formData.value[schema.field] = schema.value
92
+ }
93
+ })
94
+ })
95
+ }
96
+ function close() {
97
+ if (prReject) prReject()
98
+ }
99
+
100
+ function handleCancel() {
101
+ visible.value = false
102
+ }
103
+
104
+ async function fixData(data: any) {
105
+ console.log('fixData', formRef.value)
106
+ await formRef.value?.resetFields()
107
+ initFormData() // 初始化 formData
108
+ if (!data) return
109
+ if (data && Object.keys(data).length > 0) {
110
+ for (const key of Object.keys(formData.value)) {
111
+ formData.value[key] = data[key]
112
+ }
113
+ }
114
+ }
115
+ async function open(data: { cellData: ICellData; title: '配置时间' | '时间详情' }) {
116
+ visible.value = true
117
+ await nextTick()
118
+
119
+ const custom = data?.cellData?.custom || {}
120
+ await fixData(custom)
121
+ return new Promise((resolve, reject) => {
122
+ prResolve = resolve
123
+ prReject = reject
124
+ })
125
+ }
126
+
127
+ async function handleReset() {
128
+ formRef.value?.resetFields()
129
+ }
130
+ async function handleSubmit() {
131
+ try {
132
+ await formRef.value?.validate()
133
+ // emit('success', { ...formData.value })
134
+ prResolve({ ...formData.value })
135
+ visible.value = false
136
+ } catch (error) {
137
+ ElMessage.error('请填写完整的表单信息')
138
+ }
139
+ }
140
+
141
+ defineExpose({
142
+ handleCancel,
143
+ close,
144
+ open,
145
+ })
146
+ </script>
147
+
148
+ <style scoped>
149
+ .cst-card {
150
+ border: unset !important;
151
+ }
152
+ </style>
@@ -0,0 +1,93 @@
1
+ import { ElMessage, ElMessageBox, ElNotification } from 'element-plus'
2
+ export const useMessage = () => {
3
+ return {
4
+ // 消息提示
5
+ info(content: string) {
6
+ ElMessage.info(content)
7
+ },
8
+ // 错误消息
9
+ error(content: string) {
10
+ ElMessage.error(content)
11
+ },
12
+ // 成功消息
13
+ success(content: string) {
14
+ ElMessage.success(content)
15
+ },
16
+ // 警告消息
17
+ warning(content: string) {
18
+ ElMessage.warning(content)
19
+ },
20
+ // 弹出提示
21
+ alert(content: string) {
22
+ ElMessageBox.alert(content, '系统提示')
23
+ },
24
+ // 错误提示
25
+ alertError(content: string) {
26
+ ElMessageBox.alert(content, '系统提示', { type: 'error' })
27
+ },
28
+ // 成功提示
29
+ alertSuccess(content: string) {
30
+ ElMessageBox.alert(content, '系统提示', { type: 'success' })
31
+ },
32
+ // 警告提示
33
+ alertWarning(content: string) {
34
+ ElMessageBox.alert(content, '系统提示', { type: 'warning' })
35
+ },
36
+ // 通知提示
37
+ notify(content: string) {
38
+ ElNotification.info(content)
39
+ },
40
+ // 错误通知
41
+ notifyError(content: string) {
42
+ ElNotification.error(content)
43
+ },
44
+ // 成功通知
45
+ notifySuccess(content: string) {
46
+ ElNotification.success(content)
47
+ },
48
+ // 警告通知
49
+ notifyWarning(content: string) {
50
+ ElNotification.warning(content)
51
+ },
52
+ // 确认窗体
53
+ confirm(content: string, tip?: string) {
54
+ return ElMessageBox.confirm(content, tip ? tip : '系统提示', {
55
+ confirmButtonText: '确定',
56
+ cancelButtonText: '取消',
57
+ type: 'warning'
58
+ })
59
+ },
60
+ // 删除窗体
61
+ delConfirm(content?: string, tip?: string) {
62
+ return ElMessageBox.confirm(
63
+ content ? content : '是否删除所选中数据?',
64
+ tip ? tip : '系统提示',
65
+ {
66
+ confirmButtonText: '确定',
67
+ cancelButtonText: '取消',
68
+ type: 'warning'
69
+ }
70
+ )
71
+ },
72
+ // 导出窗体
73
+ exportConfirm(content?: string, tip?: string) {
74
+ return ElMessageBox.confirm(
75
+ content ? content : '是否确认导出数据项?',
76
+ tip ? tip : '系统提示',
77
+ {
78
+ confirmButtonText: '确定',
79
+ cancelButtonText: '取消',
80
+ type: 'warning'
81
+ }
82
+ )
83
+ },
84
+ // 提交内容
85
+ prompt(content: string, tip: string) {
86
+ return ElMessageBox.prompt(content, tip, {
87
+ confirmButtonText: '确定',
88
+ cancelButtonText: '取消',
89
+ type: 'warning'
90
+ })
91
+ }
92
+ }
93
+ }
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ // src/index.ts
2
+ export {
3
+ registerExternalComponents,
4
+ indicatorsFormSchemas,
5
+ timeConfigFormSchemas,
6
+ type ExternalComponents,
7
+ } from './components/UniverSheet/plugins'
8
+
9
+ // 导出类型声明
10
+ export type { IndicatorPointSelectProps } from './types/external-components'
package/src/main.ts ADDED
@@ -0,0 +1,14 @@
1
+
2
+ import { createApp } from 'vue'
3
+ import App from './App.vue'
4
+ import { registerExternalComponents } from './index'
5
+ import IndicatorPointSelect from './components/IndicatorPointSelect/IndicatorPointSelect.vue'
6
+
7
+ // 开发环境引入 element-plus 样式
8
+ import 'element-plus/dist/index.css'
9
+
10
+ registerExternalComponents({
11
+ IndicatorPointSelect,
12
+ })
13
+
14
+ createApp(App).mount('#app')
@@ -0,0 +1,52 @@
1
+ export type ComponentName =
2
+ | 'Radio'
3
+ | 'RadioButton'
4
+ | 'Checkbox'
5
+ | 'ElCheckbox'
6
+ | 'CheckboxButton'
7
+ | 'Input'
8
+ | 'Autocomplete'
9
+ | 'InputNumber'
10
+ | 'Select'
11
+ | 'Cascader'
12
+ | 'Switch'
13
+ | 'Slider'
14
+ | 'TimePicker'
15
+ | 'DatePicker'
16
+ | 'Rate'
17
+ | 'ColorPicker'
18
+ | 'Transfer'
19
+ | 'Divider'
20
+ | 'TimeSelect'
21
+ | 'SelectV2'
22
+ | 'TreeSelect'
23
+
24
+ export type ColProps = {
25
+ span?: number
26
+ xs?: number
27
+ sm?: number
28
+ md?: number
29
+ lg?: number
30
+ xl?: number
31
+ tag?: string
32
+ }
33
+
34
+ export type ComponentOptions = {
35
+ label?: string
36
+ value?: FormValueType
37
+ disabled?: boolean
38
+ key?: string | number
39
+ children?: ComponentOptions[]
40
+ options?: ComponentOptions[]
41
+ } & Recordable
42
+
43
+ export type ComponentOptionsAlias = {
44
+ labelField?: string
45
+ valueField?: string
46
+ }
47
+
48
+ export type ComponentProps = {
49
+ optionsAlias?: ComponentOptionsAlias
50
+ options?: ComponentOptions[]
51
+ optionsSlot?: boolean
52
+ } & Recordable
@@ -0,0 +1,16 @@
1
+ // src/types/external-components.d.ts
2
+ import type { Component } from 'vue'
3
+
4
+ export interface IndicatorPointSelectProps {
5
+ modelValue?: string | number
6
+ type?: 'radio' | 'checkbox'
7
+ callback?: () => boolean
8
+ extra?: Record<string, any>
9
+ onSelect?: (data: Recordable) => void
10
+ onClear?: () => void
11
+ 'onUpdate:modelValue'?: (value: string | number) => void
12
+ }
13
+
14
+ export interface ExternalComponents {
15
+ IndicatorPointSelect?: Component
16
+ }
@@ -0,0 +1,52 @@
1
+ import type { CSSProperties } from 'vue'
2
+ import { ColProps, ComponentProps, ComponentName } from '@/types/components'
3
+ import type { FormItemProps as ELementFormItemProps } from 'element-plus'
4
+
5
+ export type FormSetPropsType = {
6
+ field: string
7
+ path: string
8
+ value: any
9
+ }
10
+
11
+ export type FormValueType = string | number | string[] | number[] | boolean | undefined | null
12
+
13
+ export type FormItemProps = {
14
+ labelWidth?: string | number
15
+ required?: boolean
16
+ rules?: Recordable
17
+ error?: string
18
+ showMessage?: boolean
19
+ inlineMessage?: boolean
20
+ style?: CSSProperties
21
+ labelPosition?: 'left' | 'right' | 'top'
22
+ }
23
+
24
+ type FormItemPropsFnParams = {
25
+ schema: FormItemProps
26
+ formModel: Recordable
27
+ }
28
+
29
+ export type FormSchema = {
30
+ // 唯一值
31
+ field: string
32
+ // 标题
33
+ label?: string
34
+ // 提示
35
+ labelMessage?: string
36
+ // col组件属性
37
+ colProps?: ColProps
38
+ // 表单组件属性,slots对应的是表单组件的插槽,规则:${field}-xxx,具体可以查看element-plus文档
39
+ componentProps?: { slots?: Recordable } & ComponentProps | ((formModel: Recordable) => Recordable)
40
+ // formItem组件属性
41
+ formItemProps?: FormItemProps | ((params: FormItemPropsFnParams) => FormItemProps)
42
+ // 渲染的组件
43
+ component?: ComponentName
44
+ // 初始值
45
+ value?: FormValueType
46
+ // 是否隐藏
47
+ hidden?: boolean | ((formModel: Recordable) => boolean)
48
+ // 远程加载下拉项
49
+ api?: <T = any>() => Promise<T>
50
+ // 自定义渲染
51
+ render?: ({ schema, formModel }: { schema: FormSchema; formModel: Recordable }) => VNode
52
+ }
@@ -0,0 +1,98 @@
1
+ import Decimal from 'decimal.js'
2
+
3
+ class DecimalChain {
4
+ private value: Decimal
5
+
6
+ constructor(value: string | number | Decimal) {
7
+ this.value = new Decimal(value)
8
+ }
9
+
10
+ /**
11
+ * 加法运算
12
+ * @param num 要加的数
13
+ * @returns DecimalChain 实例,支持链式调用
14
+ */
15
+ add(num: string | number | Decimal): DecimalChain {
16
+ this.value = this.value.add(num || 0)
17
+ return this
18
+ }
19
+
20
+ /**
21
+ * 减法运算
22
+ * @param num 要减的数
23
+ * @returns DecimalChain 实例,支持链式调用
24
+ */
25
+ subtract(num: string | number | Decimal): DecimalChain {
26
+ this.value = this.value.sub(num || 0)
27
+ return this
28
+ }
29
+
30
+ /**
31
+ * 乘法运算
32
+ * @param num 要乘的数
33
+ * @returns DecimalChain 实例,支持链式调用
34
+ */
35
+ multiply(num: string | number | Decimal): DecimalChain {
36
+ this.value = this.value.mul(num || 0)
37
+ return this
38
+ }
39
+
40
+ /**
41
+ * 除法运算
42
+ * @param num 要除的数
43
+ * @returns DecimalChain 实例,支持链式调用
44
+ * @throws 当除数为0时抛出错误
45
+ */
46
+ divide(num: string | number | Decimal): DecimalChain {
47
+ const divisor = new Decimal(num)
48
+ if (divisor.isZero()) {
49
+ throw new Error('除数是0')
50
+ }
51
+ this.value = this.value.div(divisor)
52
+ return this
53
+ }
54
+
55
+ /**
56
+ * 保留小数位数
57
+ * @param dp 保留的小数位数
58
+ * @param rounding 舍入模式,默认为四舍五入
59
+ * @returns DecimalChain 实例,支持链式调用
60
+ */
61
+ toFixed(dp: number, rounding?: Decimal.Rounding): DecimalChain {
62
+ this.value = new Decimal(this.value.toFixed(dp, rounding!))
63
+ return this
64
+ }
65
+
66
+ /**
67
+ * 返回当前值
68
+ * @returns Decimal 实例
69
+ */
70
+ valueOf(): Decimal {
71
+ return this.value
72
+ }
73
+
74
+ /**
75
+ * 转换为字符串
76
+ * @returns 字符串表示
77
+ */
78
+ toString(): string {
79
+ return this.value.toString()
80
+ }
81
+
82
+ /**
83
+ * 转换为数字
84
+ * @returns 数字表示
85
+ */
86
+ toNumber(): number {
87
+ return this.value.toNumber()
88
+ }
89
+ }
90
+
91
+ /**
92
+ * 创建一个支持链式调用的 Decimal 实例
93
+ * @param value 初始值
94
+ * * @returns DecimalChain 实例
95
+ */
96
+ export function decimal(value: string | number | Decimal = 0): DecimalChain {
97
+ return new DecimalChain(value)
98
+ }