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,109 @@
1
+ import {
2
+ Inject,
3
+ Injector,
4
+ Plugin,
5
+ CommandType,
6
+ ICommandService,
7
+ touchDependencies,
8
+ UniverInstanceType,
9
+ IUniverInstanceService,
10
+ Workbook,
11
+ IWorkbookData
12
+ } from '@univerjs/core'
13
+ import { ComponentManager, IMenuManagerService, MenuItemType, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup } from '@univerjs/ui'
14
+ import type { IAccessor, ICommand, Dependency } from '@univerjs/core'
15
+ import { SetRangeValuesCommand } from '@univerjs/sheets'
16
+ import { FUniver } from '@univerjs/core/facade'
17
+ import { downloadBlobRes, openMultipleFileSelector } from '@/utils/fileHelp'
18
+
19
+ // 自定义ui
20
+ import ImportFileIcon from './ImportFileIcon.vue'
21
+
22
+ import { read, utils, readFile } from 'xlsx'
23
+
24
+ function waitUserSelectXlSXFile(onSelect: (data: { data: string[][]; colsCount: number; rowsCount: number }) => void) {
25
+ const input = document.createElement('input')
26
+ input.type = 'file'
27
+ input.accept = '.xlsx'
28
+ input.multiple = false
29
+ input.click()
30
+ input.onchange = () => {
31
+ const file = input.files?.[0]
32
+ if (!file) return
33
+ console.log('file', file)
34
+ const reader = new FileReader()
35
+ reader.onload = (e: any) => {
36
+ const data = new Uint8Array(e.target.result)
37
+ const workbook = read(data, { type: 'array' })
38
+ console.log('workbook', workbook)
39
+ const sheets: any = {}
40
+ workbook.SheetNames.forEach((sheetName) => {
41
+ const worksheet = workbook.Sheets[sheetName]
42
+ sheets[sheetName] = utils.sheet_to_json(worksheet, { header: 1 })
43
+ })
44
+ console.log('sheets', sheets)
45
+ }
46
+ reader.readAsArrayBuffer(file)
47
+ }
48
+ }
49
+
50
+ class ImportFilePlugin extends Plugin {
51
+ static override pluginName = 'rt-import-file-button'
52
+ univerApi: FUniver = {} as FUniver
53
+
54
+ constructor(
55
+ _config: any,
56
+ // inject injector, required
57
+ @Inject(Injector) readonly _injector: Injector,
58
+ // inject menu service, to add toolbar button
59
+ @Inject(IMenuManagerService) private readonly menuManagerService: IMenuManagerService,
60
+ // inject command service, to register command handler
61
+ @Inject(ICommandService) private readonly commandService: ICommandService,
62
+ // inject component manager, to register icon component
63
+ @Inject(ComponentManager) private readonly componentManager: ComponentManager
64
+ ) {
65
+ super()
66
+ this.univerApi = _config.univerAPI
67
+ }
68
+ onStarting(): void {
69
+ console.log('onStarting', this.componentManager)
70
+ this.componentManager.register('rt-import-file-icon', ImportFileIcon, { framework: 'vue3' })
71
+ const buttonId = 'rt-import-file-button'
72
+ const menuItemFactory = () => ({
73
+ id: buttonId,
74
+ title: '导入',
75
+ tooltip: '导入xlsx文件',
76
+ icon: 'rt-import-file-icon',
77
+ type: MenuItemType.BUTTON
78
+ })
79
+ this.menuManagerService.mergeMenu({
80
+ [RibbonStartGroup.LAYOUT]: {
81
+ [buttonId]: {
82
+ order: 2,
83
+ menuItemFactory
84
+ }
85
+ }
86
+ })
87
+ const command: ICommand = {
88
+ type: CommandType.OPERATION,
89
+ // command id, same as menu button id
90
+ id: buttonId,
91
+ handler: async (accessor: IAccessor) => {
92
+ console.log('点击了导入')
93
+ const univer = accessor.get(IUniverInstanceService)
94
+ const commandService = accessor.get(ICommandService)
95
+ const file: any = await openMultipleFileSelector('.xlsx')
96
+ const snapshot = await this.univerApi.importXLSXToSnapshotAsync(file[0])
97
+ if (snapshot) {
98
+ this.univerApi.createWorkbook(snapshot as IWorkbookData)
99
+ } else {
100
+ console.error('Failed to import XLSX file: returned undefined')
101
+ }
102
+ return true
103
+ }
104
+ }
105
+ this.commandService.registerCommand(command)
106
+ }
107
+ }
108
+
109
+ export default ImportFilePlugin
@@ -0,0 +1,10 @@
1
+ // src/components/UniverSheet/plugins/index.ts
2
+ import { registerExternalComponents, ExternalComponents } from './Plugins'
3
+ import { indicatorsFormSchemas, timeConfigFormSchemas } from './Plugins'
4
+
5
+ export {
6
+ registerExternalComponents,
7
+ indicatorsFormSchemas,
8
+ timeConfigFormSchemas,
9
+ type ExternalComponents
10
+ }
@@ -0,0 +1,134 @@
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 IndicatorsMenu from './components/IndicatorsMenu.vue'
12
+ // import IndicatorsUniverSheetConfigDialog from './components/IndicatorsUniverSheetConfigDialog.vue'
13
+
14
+
15
+ // import saveIcon from '@/assets/icons/saveIcon.svg'
16
+
17
+ // 定义一个名为 CustomButtonPlugin 的类,继承自 Plugin 类
18
+ class IndicatorsContextMenuPlugin extends Plugin {
19
+ static override pluginName = 'IndicatorsContextMenuPlugin'
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(IndicatorsUniverSheetConfigDialog, {
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('IndicatorsMenu', IndicatorsMenu, { framework: 'vue3' })
71
+ // this.univerApi.registerComponent('IndicatorsMenu', IndicatorsMenu, { framework: 'vue3' })
72
+ const buttonId = 'indicators-context-menu-plugin'
73
+ const menuItemFactory = () => ({
74
+ id: buttonId,
75
+ title: '配置指标',
76
+ icon: 'IndicatorsMenu',
77
+ type: MenuItemType.BUTTON,
78
+ })
79
+ this.menuManagerService.mergeMenu({
80
+ [ContextMenuPosition.MAIN_AREA]: {
81
+ [ContextMenuGroup.OTHERS]: {
82
+ [buttonId]: {
83
+ order: 12,
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
+ console.log('点击了配置指标');
95
+ const workbook: FWorkbook = this.univerApi.getActiveWorkbook() as FWorkbook;
96
+ const fWorksheet: FWorksheet = workbook.getActiveSheet() as FWorksheet
97
+ const fSelection: FSelection = fWorksheet.getSelection() as FSelection;
98
+ const activeRange: FRange = fSelection.getActiveRange() as FRange;
99
+ console.log('单元格', activeRange.getCellData())
100
+ const customData = await this.showConfigDialog(activeRange.getCellData() as ICellData, '配置指标')
101
+ console.log('customData', customData)
102
+ if (!customData || !Object.keys(customData).length) {
103
+ activeRange.setValue({
104
+ custom: null
105
+ })
106
+ activeRange.deleteNote()
107
+ return true
108
+ }
109
+ activeRange.setValue({
110
+ custom: {
111
+ ...customData,
112
+ cellType: 'indicator'
113
+ }
114
+ })
115
+ const rowNum = activeRange.getRow()
116
+ const colNum = activeRange.getColumn()
117
+ activeRange.createOrUpdateNote({
118
+ id: `${activeRange.getSheetId()}-${rowNum}-${colNum}`,
119
+ row: rowNum,
120
+ col: colNum,
121
+ note: `指标名称:${customData?.indicatorName};指标编码: ${customData?.indicatorCode};指标ID: ${customData?.indicatorId};`,
122
+ width: 200,
123
+ height: 100,
124
+ show: false,
125
+ })
126
+ console.log('配置后的单元格', activeRange.getCellData())
127
+ return true;
128
+ }
129
+ }
130
+ this.commandService.registerCommand(command);
131
+ }
132
+ }
133
+
134
+ export default IndicatorsContextMenuPlugin
@@ -0,0 +1,49 @@
1
+ <template>
2
+ <svg
3
+ t="1741243303947"
4
+ class="icon"
5
+ viewBox="0 0 1024 1024"
6
+ version="1.1"
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ p-id="5288"
9
+ width="16"
10
+ height="16"
11
+ >
12
+ <path
13
+ d="M526.628571 468.114286m-87.771428 0a87.771429 87.771429 0 1 0 175.542857 0 87.771429 87.771429 0 1 0-175.542857 0Z"
14
+ fill="#41CB8F"
15
+ p-id="5289"
16
+ ></path>
17
+ <path
18
+ d="M292.571429 336.457143m-29.257143 0a29.257143 29.257143 0 1 0 58.514285 0 29.257143 29.257143 0 1 0-58.514285 0Z"
19
+ fill="#41CB8F"
20
+ p-id="5290"
21
+ ></path>
22
+ <path
23
+ d="M672.914286 731.428571m-29.257143 0a29.257143 29.257143 0 1 0 58.514286 0 29.257143 29.257143 0 1 0-58.514286 0Z"
24
+ fill="#41CB8F"
25
+ p-id="5291"
26
+ ></path>
27
+ <path
28
+ d="M263.314286 746.057143m-29.257143 0a29.257143 29.257143 0 1 0 58.514286 0 29.257143 29.257143 0 1 0-58.514286 0Z"
29
+ fill="#41CB8F"
30
+ p-id="5292"
31
+ ></path>
32
+ <path
33
+ d="M950.857143 0H73.142857C32.182857 0 0 32.182857 0 73.142857v877.714286c0 40.96 32.182857 73.142857 73.142857 73.142857h877.714286c40.96 0 73.142857-32.182857 73.142857-73.142857V73.142857c0-40.96-32.182857-73.142857-73.142857-73.142857zM263.314286 804.571429c-32.182857 0-58.514286-26.331429-58.514286-58.514286s26.331429-58.514286 58.514286-58.514286 58.514286 26.331429 58.514285 58.514286-26.331429 58.514286-58.514285 58.514286z m380.342857-336.457143c0 5.851429 0 10.24-1.462857 16.091428l90.697143 10.24c7.314286 1.462857 13.165714 8.777143 13.165714 16.091429-1.462857 7.314286-7.314286 13.165714-14.628572 13.165714h-1.462857l-95.085714-11.702857c-7.314286 17.554286-19.017143 32.182857-32.182857 43.885714l61.44 117.028572c2.925714 0 5.851429-1.462857 8.777143-1.462857 32.182857 0 58.514286 26.331429 58.514285 58.514285s-26.331429 58.514286-58.514285 58.514286-58.514286-26.331429-58.514286-58.514286c0-19.017143 8.777143-35.108571 21.942857-45.348571l-58.514286-112.64c-16.091429 8.777143-32.182857 13.165714-51.2 13.165714-24.868571 0-46.811429-7.314286-65.828571-20.48l-112.64 112.64c-2.925714 2.925714-7.314286 4.388571-10.24 4.388572-4.388571 0-7.314286-1.462857-10.24-4.388572-5.851429-5.851429-5.851429-14.628571 0-20.48l111.177143-111.177143c-17.554286-20.48-29.257143-46.811429-29.257143-76.068571 0-14.628571 2.925714-29.257143 8.777143-42.422857L332.068571 380.342857c-10.24 8.777143-24.868571 14.628571-39.497142 14.628572-32.182857 0-58.514286-26.331429-58.514286-58.514286s26.331429-58.514286 58.514286-58.514286 58.514286 26.331429 58.514285 58.514286c0 5.851429-1.462857 13.165714-2.925714 19.017143l83.382857 45.348571c21.942857-29.257143 55.588571-48.274286 95.085714-48.274286 21.942857 0 43.885714 5.851429 61.44 17.554286l52.662858-57.051428c-7.314286-11.702857-11.702857-21.942857-11.702858-35.108572 0-32.182857 26.331429-58.514286 58.514286-58.514286s58.514286 26.331429 58.514286 58.514286-26.331429 58.514286-58.514286 58.514286c-8.777143 0-17.554286-2.925714-24.868571-5.851429l-51.2 55.588572c19.017143 21.942857 32.182857 49.737143 32.182857 81.92z m175.542857 117.028571c-32.182857 0-58.514286-26.331429-58.514286-58.514286s26.331429-58.514286 58.514286-58.514285 58.514286 26.331429 58.514286 58.514285-26.331429 58.514286-58.514286 58.514286z"
34
+ fill="#41CB8F"
35
+ p-id="5293"
36
+ ></path>
37
+ <path
38
+ d="M819.2 526.628571m-29.257143 0a29.257143 29.257143 0 1 0 58.514286 0 29.257143 29.257143 0 1 0-58.514286 0Z"
39
+ fill="#41CB8F"
40
+ p-id="5294"
41
+ ></path>
42
+ <path
43
+ d="M687.542857 277.942857m-29.257143 0a29.257143 29.257143 0 1 0 58.514286 0 29.257143 29.257143 0 1 0-58.514286 0Z"
44
+ fill="#41CB8F"
45
+ p-id="5295"
46
+ ></path>
47
+ </svg>
48
+ </template>
49
+ <script setup lang="ts" name="IndicatorsMenu"></script>
@@ -0,0 +1,153 @@
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="
15
+ schema.render
16
+ ? schema.render({ formModel: formData, schema })
17
+ : componentMap[schema.component!] || componentMap.Input
18
+ "
19
+ v-model="formData[schema.field]"
20
+ v-bind="
21
+ isFunction(schema.componentProps)
22
+ ? schema.componentProps(formData)
23
+ : schema.componentProps || {}
24
+ "
25
+ :placeholder="`请输入${schema.label}`"
26
+ clearable
27
+ />
28
+ </el-form-item>
29
+ </el-col>
30
+ </el-row>
31
+ </ContentWrap>
32
+ </el-form>
33
+
34
+ <template #footer>
35
+ <el-button @click="handleReset">重置</el-button>
36
+ <el-button type="primary" @click="handleSubmit">确定</el-button>
37
+ </template>
38
+ </el-dialog>
39
+ </template>
40
+
41
+ <script setup lang="ts">
42
+ import { nextTick, ref, computed } from 'vue'
43
+ import ContentWrap from '@/components/ContentWrap/src/ContentWrap.vue'
44
+ import {
45
+ ElConfigProvider,
46
+ ElDialog,
47
+ ElForm,
48
+ ElFormItem,
49
+ ElInput,
50
+ ElButton,
51
+ ElMessage,
52
+ ElRow,
53
+ ElCol,
54
+ } from 'element-plus'
55
+ import type { ICellData } from '@univerjs/presets'
56
+ import { componentMap } from '@/components/Form/src/componentMap'
57
+ import { isEmpty, isFunction, isBoolean } from '@/utils/is'
58
+ import { indicatorsFormSchemas, FormType, ExtendedFormSchema } from '../../Plugins'
59
+
60
+ defineOptions({ name: 'IndicatorsUniverSheetConfigDialog' })
61
+
62
+ let prResolve: any, prReject: any
63
+ const visible = ref(false)
64
+ const title = ref<'配置指标' | '指标详情'>('配置指标')
65
+ const formRef = ref()
66
+
67
+ const formSchema = computed<FormType[]>(() => {
68
+ return indicatorsFormSchemas.map((item) => {
69
+ const arr = item.schemas.filter((item: ExtendedFormSchema) => {
70
+ if (item.hasOwnProperty('hidden')) {
71
+ if (isFunction(item.hidden) && item.hidden(formData.value)) {
72
+ return false
73
+ }
74
+ if (isBoolean(item.hidden) && item.hidden) {
75
+ return false
76
+ }
77
+ }
78
+ return true
79
+ })
80
+ return {
81
+ ...item,
82
+ schemas: arr,
83
+ }
84
+ })
85
+ })
86
+
87
+ const formData = ref<Recordable>({})
88
+
89
+ // 动态初始化 formData 默认值
90
+ function initFormData() {
91
+ formSchema.value.forEach((group) => {
92
+ group.schemas.forEach((schema) => {
93
+ formData.value[schema.field] = schema.value ?? null // 设置默认值
94
+ })
95
+ })
96
+ }
97
+ function close() {
98
+ if (prReject) prReject()
99
+ }
100
+
101
+ function handleCancel() {
102
+ visible.value = false
103
+ }
104
+
105
+ async function fixData(data: any) {
106
+ console.log('fixData', formRef.value)
107
+ await formRef.value?.resetFields()
108
+ initFormData() // 初始化 formData
109
+ if (!data) return
110
+ if (data && Object.keys(data).length > 0) {
111
+ for (const key of Object.keys(formData.value)) {
112
+ formData.value[key] = data[key]
113
+ }
114
+ }
115
+ }
116
+ async function open(data: { cellData: ICellData; title: '配置指标' | '指标详情' }) {
117
+ console.log('open', data)
118
+ visible.value = true
119
+ await nextTick()
120
+ const custom = data?.cellData?.custom || {}
121
+ await fixData(custom)
122
+ return new Promise((resolve, reject) => {
123
+ prResolve = resolve
124
+ prReject = reject
125
+ })
126
+ }
127
+
128
+ async function handleReset() {
129
+ formRef.value?.resetFields()
130
+ }
131
+ async function handleSubmit() {
132
+ try {
133
+ await formRef.value?.validate()
134
+ // emit('success', { ...formData.value })
135
+ prResolve({ ...formData.value })
136
+ visible.value = false
137
+ } catch (error) {
138
+ ElMessage.error('请填写完整的表单信息')
139
+ }
140
+ }
141
+
142
+ defineExpose({
143
+ handleCancel,
144
+ close,
145
+ open,
146
+ })
147
+ </script>
148
+
149
+ <style scoped>
150
+ .cst-card {
151
+ border: unset !important;
152
+ }
153
+ </style>
@@ -0,0 +1,19 @@
1
+ <template>
2
+ <svg
3
+ t="1741163047735"
4
+ class="icon"
5
+ viewBox="0 0 1024 1024"
6
+ version="1.1"
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ p-id="1370"
9
+ width="16"
10
+ height="16"
11
+ >
12
+ <path
13
+ d="M882.356706 0.150588a136.131765 136.131765 0 0 1 135.740235 135.770353v746.616471a136.131765 136.131765 0 0 1-135.740235 135.710117H135.740235A136.131765 136.131765 0 0 1 0 882.507294V135.890824A136.131765 136.131765 0 0 1 135.740235 0.180706h33.942589V322.56a102.098824 102.098824 0 0 0 101.797647 101.797647H746.616471a102.098824 102.098824 0 0 0 101.797647-101.797647V0.150588h33.942588zM240.790588 33.129412c0-18.221176 15.36-33.129412 34.123294-33.129412h443.723294c18.793412 0 34.153412 14.908235 34.153412 33.129412v265.035294c0 18.221176-15.36 33.129412-34.153412 33.129412H274.913882c-18.763294 0-34.123294-14.908235-34.123294-33.129412V33.129412zM667.407059 205.402353V122.578824c0-23.190588-18.763294-41.411765-42.646588-41.411765-23.913412 0-42.676706 18.221176-42.676706 41.411765v82.823529c0 23.190588 18.763294 41.411765 42.676706 41.411765 23.883294 0 42.646588-18.221176 42.646588-41.411765z"
14
+ fill="#FA581C"
15
+ p-id="1371"
16
+ ></path>
17
+ </svg>
18
+ </template>
19
+ <script setup lang="ts" name="ButtonIcon"></script>
@@ -0,0 +1,68 @@
1
+ import { Inject, Injector, Plugin, CommandType, ICommandService, touchDependencies, UniverInstanceType, IUniverInstanceService, Workbook } from '@univerjs/presets'
2
+ import { ComponentManager, IMenuManagerService, MenuItemType, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup } from '@univerjs/ui'
3
+ import type { IAccessor, ICommand, Dependency } from '@univerjs/core'
4
+ import { FUniver } from '@univerjs/core/facade'
5
+ // 自定义ui
6
+ // import { FolderSingle } from '@univerjs/icons'
7
+ import ButtonIcon from './ButtonIcon.vue'
8
+
9
+
10
+ // import saveIcon from '@/assets/icons/saveIcon.svg'
11
+
12
+ // 定义一个名为 CustomButtonPlugin 的类,继承自 Plugin 类
13
+ class SaveButtonPlugin extends Plugin {
14
+ static override pluginName = 'save-button'
15
+ univerApi: FUniver = {} as FUniver
16
+
17
+ constructor(
18
+ _config: any,
19
+ // inject injector, required
20
+ @Inject(Injector) readonly _injector: Injector,
21
+ // inject menu service, to add toolbar button
22
+ @Inject(IMenuManagerService) private readonly menuManagerService: IMenuManagerService,
23
+ // inject command service, to register command handler
24
+ @Inject(ICommandService) private readonly commandService: ICommandService,
25
+ // inject component manager, to register icon component
26
+ @Inject(ComponentManager) private readonly componentManager: ComponentManager,
27
+ ) {
28
+ super()
29
+ this.univerApi = _config?.univerAPI
30
+ }
31
+ onStarting(): void {
32
+ this.componentManager.register('saveIcon', ButtonIcon, { framework: 'vue3' })
33
+ // this.univerApi.registerComponent('saveIcon', ButtonIcon, { framework: 'vue3' })
34
+ const buttonId = 'save-button'
35
+ const menuItemFactory = () => ({
36
+ id: buttonId,
37
+ title: '保存',
38
+ tooltip: '保存',
39
+ icon: 'saveIcon',
40
+ type: MenuItemType.BUTTON,
41
+ })
42
+ this.menuManagerService.mergeMenu({
43
+ [RibbonStartGroup.LAYOUT]: {
44
+ [buttonId]: {
45
+ order: 1,
46
+ menuItemFactory,
47
+ },
48
+ },
49
+ })
50
+ const command: ICommand = {
51
+ type: CommandType.OPERATION,
52
+ // command id, same as menu button id
53
+ id: buttonId,
54
+ handler: (accessor: IAccessor) => {
55
+ console.log('点击了保存');
56
+ const univer = accessor.get(IUniverInstanceService)
57
+ const commandService = accessor.get(ICommandService)
58
+ const sheet = univer.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet()
59
+ const workbook = this.univerApi.getActiveWorkbook()
60
+ console.log('工作簿数据', workbook?.save().sheets)
61
+ return true;
62
+ }
63
+ }
64
+ this.commandService.registerCommand(command);
65
+ }
66
+ }
67
+
68
+ export default SaveButtonPlugin
@@ -0,0 +1,24 @@
1
+ <template>
2
+ <svg
3
+ t="1741243523970"
4
+ class="icon"
5
+ viewBox="0 0 1024 1024"
6
+ version="1.1"
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ p-id="7203"
9
+ width="16"
10
+ height="16"
11
+ >
12
+ <path
13
+ d="M810.666667 128H213.333333c-46.933333 0-85.333333 38.4-85.333333 85.333333v597.333334c0 46.933333 38.4 85.333333 85.333333 85.333333h597.333334c46.933333 0 85.333333-38.4 85.333333-85.333333V213.333333c0-46.933333-38.4-85.333333-85.333333-85.333333z m0 640c0 23.466667-19.2 42.666667-42.666667 42.666667H256c-23.466667 0-42.666667-19.2-42.666667-42.666667V256c0-23.466667 19.2-42.666667 42.666667-42.666667h512c23.466667 0 42.666667 19.2 42.666667 42.666667v512z"
14
+ fill="#297AFF"
15
+ p-id="7204"
16
+ ></path>
17
+ <path
18
+ d="M533.333333 490.666667h168.533334c8.533333 0 17.066667-4.266667 23.466666-8.533334l8.533334-8.533333c12.8-12.8 12.8-34.133333 0-46.933333l-36.266667-36.266667-104.533333-104.533333c-4.266667-8.533333-19.2-8.533333-27.733334 0l-29.866666 29.866666c-8.533333 8.533333-8.533333 21.333333 0 29.866667L597.333333 405.333333H313.6c-12.8 0-21.333333 8.533333-21.333333 21.333334v42.666666c0 12.8 8.533333 21.333333 21.333333 21.333334H533.333333zM497.066667 533.333333h-168.533334c-8.533333 0-17.066667 4.266667-23.466666 8.533334l-8.533334 8.533333c-12.8 12.8-12.8 34.133333 0 46.933333l36.266667 36.266667 104.533333 104.533333c4.266667 8.533333 19.2 8.533333 27.733334 0l29.866666-29.866666c8.533333-8.533333 8.533333-21.333333 0-29.866667L433.066667 618.666667h283.733333c12.8 0 21.333333-8.533333 21.333333-21.333334v-42.666666c0-12.8-8.533333-21.333333-21.333333-21.333334H497.066667z"
19
+ fill="#297AFF"
20
+ p-id="7205"
21
+ ></path>
22
+ </svg>
23
+ </template>
24
+ <script setup lang="ts" name="SyncContextMenu"></script>
@@ -0,0 +1,65 @@
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 { FUniver } from '@univerjs/core/facade';
5
+ // 自定义ui
6
+ // import { FolderSingle } from '@univerjs/icons'
7
+ import SyncContextMenu from './SyncContextMenu.vue'
8
+
9
+
10
+ // import saveIcon from '@/assets/icons/saveIcon.svg'
11
+
12
+ // 定义一个名为 CustomButtonPlugin 的类,继承自 Plugin 类
13
+ class SyncContextMenuPlugin extends Plugin {
14
+ static override pluginName = 'SyncContextMenuPlugin'
15
+ univerApi: FUniver = {} as FUniver
16
+
17
+ constructor(
18
+ _config: any,
19
+ // inject injector, required
20
+ @Inject(Injector) readonly _injector: Injector,
21
+ // inject menu service, to add toolbar button
22
+ @Inject(IMenuManagerService) private readonly menuManagerService: IMenuManagerService,
23
+ // inject command service, to register command handler
24
+ @Inject(ICommandService) private readonly commandService: ICommandService,
25
+ // inject component manager, to register icon component
26
+ @Inject(ComponentManager) private readonly componentManager: ComponentManager,
27
+ ) {
28
+ super()
29
+ this.univerApi = _config?.univerAPI
30
+ }
31
+ onStarting(): void {
32
+ this.componentManager.register('SyncContextMenu', SyncContextMenu, { framework: 'vue3' })
33
+ const buttonId = 'sync-context-menu-plugin'
34
+ const menuItemFactory = () => ({
35
+ id: buttonId,
36
+ title: '立刻同步',
37
+ icon: 'SyncContextMenu',
38
+ type: MenuItemType.BUTTON,
39
+ })
40
+ this.menuManagerService.mergeMenu({
41
+ [ContextMenuPosition.MAIN_AREA]: {
42
+ [ContextMenuGroup.OTHERS]: {
43
+ [buttonId]: {
44
+ order: 12,
45
+ menuItemFactory,
46
+ },
47
+ }
48
+ }
49
+ })
50
+ const command: ICommand = {
51
+ type: CommandType.OPERATION,
52
+ // command id, same as menu button id
53
+ id: buttonId,
54
+ handler: (accessor: IAccessor) => {
55
+ console.log('点击了立刻同步');
56
+ const univer = accessor.get(IUniverInstanceService)
57
+ const commandService = accessor.get(ICommandService)
58
+ return true;
59
+ }
60
+ }
61
+ this.commandService.registerCommand(command);
62
+ }
63
+ }
64
+
65
+ export default SyncContextMenuPlugin