tadcode-wpsjs 1.0.0 → 1.1.1
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.
- package/README.md +16 -0
- package/index.js +1 -1
- package/index.ts +54 -17
- package/package.json +3 -2
- package/remoteCode/index.min.js +1 -0
- package/types/DB_Application_Plus/index.d.ts +7 -0
- package/types/DB_Application_Plus/record.d.ts +33 -0
- package/types/DB_Application_Plus/records.d.ts +58 -0
- package/types/DB_Application_Plus/sheet.d.ts +137 -0
- package/types/DB_Application_Plus/sheets.d.ts +113 -0
- package/types/DB_Application_Sheet.d.ts +39 -39
- package/types/index.d.ts +2 -1
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
- [**WPS多维表格:“开发”功能使用说明文档**](https://365.kdocs.cn/l/ctzsgDlAGF0l)
|
|
6
6
|
- [**执行AirScript脚本操作使用指南**](https://365.kdocs.cn/l/cdQOqc6TZuMk)
|
|
7
7
|
- [**快速入门多维表“开发”**](https://365.kdocs.cn/l/ctx1jAV1xJhR)
|
|
8
|
+
- [**WPS开放平台dbsheet-Api部分**](https://365.kdocs.cn/3rd/open/documents/app-integration-dev/guide/dbsheet/Api/api-instro)
|
|
8
9
|
|
|
9
10
|
## 联系我
|
|
10
11
|
|
|
@@ -55,6 +56,21 @@ const data = await wpsjsGlobal.Application.Sheet.GetSheets()
|
|
|
55
56
|
console.log(data)
|
|
56
57
|
```
|
|
57
58
|
|
|
59
|
+
### 重命名(远程赋值操作)
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { initRemoteCallWpsjsGlobal,setValue } from 'tadcode-wpsjs'
|
|
63
|
+
/* 脚本令牌 具体获取方式参考上面 */
|
|
64
|
+
const scriptToken = 'xxxx'
|
|
65
|
+
/* webhook url地址 具体获取方式参考上面 */
|
|
66
|
+
const webhookURL = 'xxxx'
|
|
67
|
+
const wpsjsGlobal = initRemoteCallWpsjsGlobal({ scriptToken, webhookURL, })
|
|
68
|
+
|
|
69
|
+
/* 类型完善中 */
|
|
70
|
+
const sheet = wpsjsGlobal.Application.Sheets(1)
|
|
71
|
+
await setValue(sheet,'Name','table1001')
|
|
72
|
+
```
|
|
73
|
+
|
|
58
74
|
### 执行脚本并且返回(不用部署remoteCode代码)
|
|
59
75
|
|
|
60
76
|
```ts
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{writeFile as
|
|
1
|
+
import{writeFile as V}from"fs/promises";import v from"path";var Q=Symbol("info"),G=Symbol("then"),I=(J)=>{let{scriptToken:B,webhookURL:X,isAsync:K=!1,printLog:Y=!1,writeLogFile:M=!1}=J,N={get(E,H,$){let Z=E[Q]??=[],z=()=>{};if(z[G]=!1,z[Q]=[...Z],H!=="then")z[Q].push({method:"get",arguments:[H]});else z[G]=!0;return new Proxy(z,N)},set(E,H,$,Z){let q=[...E[Q]??=[],{method:"set",arguments:[H,$]}];return U=D({scriptToken:B,webhookURL:X,isAsync:K,argv:{info:q}}).then(async(x)=>{let W=await x.json();if(Y)_(W);if(M)await P(W);return W?.data.result}),!0},apply(E,H,$){if(!E[G]){let Z=E[Q]??=[],z=()=>{};return z[G]=!1,z[Q]=[...Z,{method:"apply",arguments:$}],new Proxy(z,N)}else{let Z=E[Q];return D({scriptToken:B,webhookURL:X,isAsync:K,argv:{info:Z}}).then(async(z)=>{let q=await z.json();if(Y)_(q);if(M)await P(q);return q?.data.result}).then(...$)}}};return new Proxy(()=>{},N)},D=({scriptToken:J,webhookURL:B,isAsync:X,argv:K})=>{let Y=JSON.stringify({Context:{argv:K}}),M=v.parse(B);M.base=X?"task":"sync_task";let N=v.format(M);return fetch(N,{method:"post",headers:{"Content-Type":"application/json","AirScript-Token":J},body:Y})},U=null,j=async()=>U,O=(J)=>{let B=new URL("https://www.kdocs.cn/api/v3/script/task");return B.searchParams.append("task_id",J),fetch(B)},_=(J)=>{let B=J,{status:X,data:K,error:Y,error_details:M}=B;console.log("status:",X);let N=K.logs.at(-1).unix_time-K.logs[1].unix_time;if(console.log("runtime:",N),Y)console.error(M.name),console.error(M.msg),console.error(M.stack);let E=K.logs.filter((H)=>H.filename!=="<system>");if(E.length!==0){console.log("log:");for(let H of E)console[H.level](...H.args)}return console.log("result:"),console.log(K.result),B},P=(J)=>{return V("./wpsjs.log.json",JSON.stringify(J,void 0,2))};export{P as writeLogFileToCurrent,j as setValueOk,O as queryTask,I as initRemoteCallWpsjsGlobal,D as execution};
|
package/index.ts
CHANGED
|
@@ -14,24 +14,41 @@ interface Config {
|
|
|
14
14
|
/**在当前路径下写入日志文件 */
|
|
15
15
|
writeLogFile?: boolean
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
const
|
|
17
|
+
|
|
18
|
+
const infoSymbol = Symbol('info-tacode')
|
|
19
|
+
const isThenSymbol = Symbol('then-tacode')
|
|
20
|
+
const rawSymbol = Symbol('raw-tacode')
|
|
21
|
+
|
|
22
|
+
type ProxyTarget = { (): void;[infoSymbol]: InfoItem[], [isThenSymbol]: boolean }
|
|
23
|
+
|
|
19
24
|
const initRemoteCallWpsjsGlobal = (config: Config) => {
|
|
20
25
|
const { scriptToken, webhookURL, isAsync = false, printLog = false, writeLogFile = false, } = config
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
if (!scriptToken || !webhookURL) { throw new Error('scriptToken and webhookURL are both required') }
|
|
23
27
|
const handle: ProxyHandler<ProxyTarget> = {
|
|
24
|
-
get(target, p
|
|
28
|
+
get(target, p, _receiver) {
|
|
29
|
+
if (p === rawSymbol) { return target }
|
|
25
30
|
const oldInfo = target[infoSymbol] ??= []
|
|
26
31
|
const func: ProxyTarget = () => { }
|
|
27
32
|
func[isThenSymbol] = false
|
|
28
33
|
func[infoSymbol] = [...oldInfo]
|
|
29
34
|
if (p !== 'then')
|
|
30
|
-
func[infoSymbol].push({ method: 'get', arguments: [p] })
|
|
35
|
+
func[infoSymbol].push({ method: 'get', arguments: [p as string] })
|
|
31
36
|
else
|
|
32
37
|
func[isThenSymbol] = true
|
|
33
38
|
return new Proxy(func, handle)
|
|
34
39
|
},
|
|
40
|
+
set(target, p, newValue, _receiver) {
|
|
41
|
+
const oldInfo = target[infoSymbol] ??= []
|
|
42
|
+
const info = [...oldInfo, { method: 'set', arguments: [p, newValue] }]
|
|
43
|
+
setValuePromise = execution({ scriptToken, webhookURL, isAsync, argv: { info } })
|
|
44
|
+
.then(async (response) => {
|
|
45
|
+
const responseObj = await response.json()
|
|
46
|
+
if (printLog) printInfo(responseObj)
|
|
47
|
+
if (writeLogFile) await writeLogFileToCurrent(responseObj)
|
|
48
|
+
return responseObj?.['data']['result']
|
|
49
|
+
})
|
|
50
|
+
return true
|
|
51
|
+
},
|
|
35
52
|
apply(target, _thisArg, argArray) {
|
|
36
53
|
if (!target[isThenSymbol]) {
|
|
37
54
|
const oldInfo = target[infoSymbol] ??= []
|
|
@@ -74,6 +91,22 @@ const execution = ({ scriptToken, webhookURL, isAsync, argv }: ExecutionConfig)
|
|
|
74
91
|
})
|
|
75
92
|
}
|
|
76
93
|
|
|
94
|
+
let setValuePromise: any = null
|
|
95
|
+
/* 远程调用的赋值操作返回的promise */
|
|
96
|
+
const setValueOk = async () => setValuePromise
|
|
97
|
+
/**赋值 */
|
|
98
|
+
const setValue = async <T extends Promise<any>>(
|
|
99
|
+
promiseObj: T,
|
|
100
|
+
p: keyof Awaited<T>,
|
|
101
|
+
newValue: Awaited<T>[keyof Awaited<T>],
|
|
102
|
+
) => {
|
|
103
|
+
const obj = promiseObj as Awaited<T>
|
|
104
|
+
const func = obj[rawSymbol] as ProxyTarget
|
|
105
|
+
const info = func[infoSymbol]
|
|
106
|
+
info.push({ method: 'set', arguments: [p as string, newValue] })
|
|
107
|
+
return promiseObj
|
|
108
|
+
}
|
|
109
|
+
|
|
77
110
|
const queryTask = (id: string) => {
|
|
78
111
|
const url = new URL('https://www.kdocs.cn/api/v3/script/task')
|
|
79
112
|
url.searchParams.append('task_id', id)
|
|
@@ -83,23 +116,25 @@ const queryTask = (id: string) => {
|
|
|
83
116
|
const printInfo = (remoteCallResponse: RemoteCallWpsjsGlobalReturn) => {
|
|
84
117
|
const responseData = remoteCallResponse as RemoteCallWpsjsGlobalReturn
|
|
85
118
|
const { status, data, error, error_details } = responseData
|
|
86
|
-
console.log('
|
|
87
|
-
|
|
88
|
-
console.log('runtime:', time)
|
|
89
|
-
if (error) {
|
|
90
|
-
console.error(error_details.name)
|
|
91
|
-
console.error(error_details.msg)
|
|
92
|
-
console.error(error_details.stack)
|
|
93
|
-
}
|
|
119
|
+
console.log('===result===')
|
|
120
|
+
console.log(data.result)
|
|
94
121
|
const userInfo = data.logs.filter(x => x.filename !== '<system>')
|
|
95
122
|
if (userInfo.length !== 0) {
|
|
96
|
-
console.log('
|
|
123
|
+
console.log('===console===')
|
|
97
124
|
for (const item of userInfo) {
|
|
98
125
|
console[item.level](...item.args)
|
|
99
126
|
}
|
|
100
127
|
}
|
|
101
|
-
|
|
102
|
-
|
|
128
|
+
if (error) {
|
|
129
|
+
console.log('===error===')
|
|
130
|
+
console.error(error_details.name)
|
|
131
|
+
console.error(error_details.msg)
|
|
132
|
+
console.error(error_details.stack)
|
|
133
|
+
console.error(error_details.unix_time)
|
|
134
|
+
}
|
|
135
|
+
const time = data.logs.at(-1)!.unix_time - data.logs[1].unix_time
|
|
136
|
+
console.log('runtime:', time)
|
|
137
|
+
console.log('status:', status)
|
|
103
138
|
return responseData
|
|
104
139
|
}
|
|
105
140
|
|
|
@@ -111,5 +146,7 @@ export {
|
|
|
111
146
|
execution,
|
|
112
147
|
initRemoteCallWpsjsGlobal,
|
|
113
148
|
queryTask,
|
|
149
|
+
setValueOk,
|
|
150
|
+
setValue,
|
|
114
151
|
writeLogFileToCurrent,
|
|
115
152
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tadcode-wpsjs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"hot": "NODE_ENV=development bun --hot ignore/index.ts",
|
|
8
8
|
"dev": "NODE_ENV=development bun --watch index.ts",
|
|
9
|
-
"build": "NODE_ENV=production bun build index.ts --target node --minify --outfile index.js"
|
|
9
|
+
"build-main": "NODE_ENV=production bun build index.ts --target node --minify --outfile index.js",
|
|
10
|
+
"build-remotecode": "NODE_ENV=production bun build remoteCode/index.js --target browser --minify --outfile remoteCode/index.min.js"
|
|
10
11
|
},
|
|
11
12
|
"devDependencies": {
|
|
12
13
|
"@types/bun": "latest"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var{info:a}=Context.argv,s=void 0,e=globalThis;for(let t of a)switch(t.method){case"get":{s=e;let[r]=t.arguments;e=Reflect.get(e,r)}break;case"set":{let[r,o]=t.arguments;e=Reflect.set(e,r,o)}break;case"apply":e=Reflect.apply(e,s,t.arguments);break;default:throw Error("method must be get or apply")}return e;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 代表单个记录的信息。Record 对象可以返回值的数组或显示的文本数据。
|
|
3
|
+
* 值数组中不同字段会有不同的对象展示。
|
|
4
|
+
*/
|
|
5
|
+
export interface Record {
|
|
6
|
+
/**
|
|
7
|
+
* 记录的唯一标识符。
|
|
8
|
+
*/
|
|
9
|
+
readonly Id: string
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 记录的值数组,根据字段类型不同,数组项的数据结构也不同。
|
|
13
|
+
* 具体字段类型对应的数据结构请参考文档中的对照表。
|
|
14
|
+
*/
|
|
15
|
+
readonly Value: any[] // 由于数据结构多样,使用 any[] 或可进一步定义为联合类型
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 记录的显示文本数组。
|
|
19
|
+
*/
|
|
20
|
+
readonly Text: string[]
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 删除当前记录。
|
|
24
|
+
* @returns 返回一个布尔值,表示删除操作是否成功。
|
|
25
|
+
*/
|
|
26
|
+
Delete(): boolean
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 选中当前记录。
|
|
30
|
+
* @returns 返回一个表示操作结果的 ApiResult 对象(需根据文档确认具体类型)。
|
|
31
|
+
*/
|
|
32
|
+
Select(): ApiResult // ApiResult 类型需根据其他文档定义
|
|
33
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Records 对象代表与记录相关的集合。用户可以通过 Records 对象直接访问记录和字段。
|
|
3
|
+
* 支持多种访问方式:
|
|
4
|
+
* - View.Records.Item(recordId)
|
|
5
|
+
* - View.Records.Item(recordIndex)
|
|
6
|
+
* - View.Records(recordId/recordIndex, fieldIndex/fieldName)
|
|
7
|
+
* - View.Records(recordId/recordIndex).Item(fieldIndex/fieldName)
|
|
8
|
+
*/
|
|
9
|
+
export interface Records {
|
|
10
|
+
/**
|
|
11
|
+
* 记录集合中的记录总数。
|
|
12
|
+
*/
|
|
13
|
+
readonly Count: number
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 根据记录 ID 或索引获取对应的记录对象。
|
|
17
|
+
* @param identifier 记录的 ID(字符串)或索引位置(数字,从1开始)。
|
|
18
|
+
* @returns 返回一个 Record 对象。
|
|
19
|
+
*/
|
|
20
|
+
Item(identifier: string | number): Record
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 根据记录 ID/索引和字段索引/名称获取记录中特定字段的值或文本。
|
|
24
|
+
* 具体返回类型取决于调用方式,可能返回 Record 对象或字段值。
|
|
25
|
+
* 此方法为动态调用,TypeScript 中较难精确描述,建议结合 Item 方法使用。
|
|
26
|
+
* @param recordIdentifier 记录的 ID(字符串)或索引位置(数字,从1开始)。
|
|
27
|
+
* @param fieldIdentifier 字段的索引(数字,从1开始)或字段名称(字符串)。
|
|
28
|
+
* @returns 返回一个 Record 对象或字段值。
|
|
29
|
+
*/
|
|
30
|
+
(recordIdentifier: string | number, fieldIdentifier?: string | number): Record | any
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 在记录集合中新增一条记录。
|
|
34
|
+
* @returns 返回新创建的 Record 对象。
|
|
35
|
+
*/
|
|
36
|
+
Add(): Record
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 删除指定的记录。
|
|
40
|
+
* @param recordIdentifier 要删除的记录 ID 或索引位置。
|
|
41
|
+
* @returns 返回一个布尔值,表示删除操作是否成功。
|
|
42
|
+
*/
|
|
43
|
+
Delete(recordIdentifier: string | number): boolean
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 从当前位置开始向后查找匹配指定条件的记录。
|
|
47
|
+
* @param criteria 查找条件,具体类型需根据文档确认。
|
|
48
|
+
* @returns 返回找到的 Record 对象,如果未找到则返回 null。
|
|
49
|
+
*/
|
|
50
|
+
FindNext(criteria: any): Record | null
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 从当前位置开始向前查找匹配指定条件的记录。
|
|
54
|
+
* @param criteria 查找条件,具体类型需根据文档确认。
|
|
55
|
+
* @returns 返回找到的 Record 对象,如果未找到则返回 null。
|
|
56
|
+
*/
|
|
57
|
+
FindPrevious(criteria: any): Record | null
|
|
58
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sheet 对象代表数据表操作。
|
|
3
|
+
* sheet 通常指:数据表 (dbSheet)、仪表盘 (dashboardSheet)、说明页面 (fpSheet)
|
|
4
|
+
*/
|
|
5
|
+
export interface Sheet {
|
|
6
|
+
// ============ 属性 ============
|
|
7
|
+
/**
|
|
8
|
+
* 字段描述集合。可读可写。
|
|
9
|
+
*/
|
|
10
|
+
FieldDescriptors: any // FieldDescriptors 类型需根据其他文档定义
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 图标的配置。可读可写。
|
|
14
|
+
*/
|
|
15
|
+
Icon: any // Icon 类型需根据其他文档定义
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 数据表的唯一标识符。只读。
|
|
19
|
+
*/
|
|
20
|
+
readonly Id: string
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 数据表的名称。可读可写。
|
|
24
|
+
*/
|
|
25
|
+
Name: string
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 所有记录的范围对象。
|
|
29
|
+
*/
|
|
30
|
+
readonly RecordRange: RecordRange // RecordRange 类型需根据其他文档定义
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 视图集合对象。只读。
|
|
34
|
+
*/
|
|
35
|
+
readonly Views: Views
|
|
36
|
+
|
|
37
|
+
// ============ 方法 ============
|
|
38
|
+
/**
|
|
39
|
+
* 为当前数据表添加描述。
|
|
40
|
+
* @param description 描述内容
|
|
41
|
+
* @returns 返回操作结果
|
|
42
|
+
*/
|
|
43
|
+
AddDescription(description: string): any
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 创建当前数据表的副本。
|
|
47
|
+
* @param name 副本名称(可选)
|
|
48
|
+
* @returns 返回新创建的 Sheet 对象
|
|
49
|
+
*/
|
|
50
|
+
Copy(name?: string): Sheet
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 创建字段。
|
|
54
|
+
* @param fieldConfig 字段配置
|
|
55
|
+
* @returns 返回创建的字段对象
|
|
56
|
+
*/
|
|
57
|
+
CreateFields(fieldConfig: any): any // Field 类型需根据其他文档定义
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 删除当前数据表。
|
|
61
|
+
* @returns 返回一个布尔值,表示删除操作是否成功。
|
|
62
|
+
*/
|
|
63
|
+
Delete(): boolean
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 删除指定的字段信息。
|
|
67
|
+
* @param fieldIdentifier 字段标识符(索引、名称或ID)
|
|
68
|
+
* @returns 返回操作结果
|
|
69
|
+
*/
|
|
70
|
+
DeleteFields(fieldIdentifier: string | number): any
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 根据字段名称获取字段。
|
|
74
|
+
* @param fieldName 字段名称
|
|
75
|
+
* @returns 返回字段对象
|
|
76
|
+
*/
|
|
77
|
+
FieldId(fieldName: string): any // Field 类型需根据其他文档定义
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 获取该数据表的所有字段信息。
|
|
81
|
+
* @returns 返回字段集合
|
|
82
|
+
*/
|
|
83
|
+
GetFields(): any // Fields 类型需根据其他文档定义
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 分享当前数据表。
|
|
87
|
+
* @param shareConfig 分享配置
|
|
88
|
+
* @returns 返回分享结果
|
|
89
|
+
*/
|
|
90
|
+
Sharesheet(shareConfig: any): any
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 更新字段。
|
|
94
|
+
* @param fieldIdentifier 要更新的字段标识符
|
|
95
|
+
* @param updateConfig 更新配置
|
|
96
|
+
* @returns 返回更新后的字段对象
|
|
97
|
+
*/
|
|
98
|
+
UpdateFields(fieldIdentifier: string | number, updateConfig: any): any
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 追加并导入本地表文件数据到当前数据表。
|
|
102
|
+
* @param filePath 本地文件路径
|
|
103
|
+
* @param options 导入选项
|
|
104
|
+
* @returns 返回导入结果
|
|
105
|
+
*/
|
|
106
|
+
AppendFromLocal(filePath: string, options?: any): any
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 追加并导入在线表文件数据到当前数据表。
|
|
110
|
+
* @param fileId 在线文件ID
|
|
111
|
+
* @param options 导入选项
|
|
112
|
+
* @returns 返回导入结果
|
|
113
|
+
*/
|
|
114
|
+
AppendFromCloud(fileId: string, options?: any): any
|
|
115
|
+
|
|
116
|
+
// ============ 事件 ============
|
|
117
|
+
/**
|
|
118
|
+
* 新建记录时触发。
|
|
119
|
+
* @param callback 事件回调函数
|
|
120
|
+
* @returns 返回 EventContext 对象,可用于取消事件监听
|
|
121
|
+
*/
|
|
122
|
+
OnCreateRecord(callback: (data: { Record: Record }) => void): EventContext
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 删除数据表时触发。
|
|
126
|
+
* @param callback 事件回调函数
|
|
127
|
+
* @returns 返回 EventContext 对象,可用于取消事件监听
|
|
128
|
+
*/
|
|
129
|
+
OnDelete(callback: (data: any) => void): EventContext
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 编辑名称时触发。
|
|
133
|
+
* @param callback 事件回调函数
|
|
134
|
+
* @returns 返回 EventContext 对象,可用于取消事件监听
|
|
135
|
+
*/
|
|
136
|
+
OnRename(callback: (data: { newName: string; oldName: string }) => void): EventContext
|
|
137
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Sheet } from './sheet'
|
|
2
|
+
// 根据文档定义的字段类型字面量
|
|
3
|
+
type FieldType = 'SingleLineText' | 'MultiLineText' | 'Date' | 'SingleSelect' | 'Number' | 'Rating' // 文档示例中出现的类型,可能还有其他
|
|
4
|
+
|
|
5
|
+
// 根据文档定义的视图类型字面量
|
|
6
|
+
type ViewType = 'Grid' | 'Kanban' | 'Gallery' | 'Form' | 'Gantt' | 'Query' | 'Calendar'
|
|
7
|
+
|
|
8
|
+
// 列表项的结构
|
|
9
|
+
interface ListItem {
|
|
10
|
+
value: string
|
|
11
|
+
color: number // 颜色值,文档示例中为数字
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Field 参数的结构
|
|
15
|
+
interface Field {
|
|
16
|
+
fieldType: FieldType
|
|
17
|
+
args: {
|
|
18
|
+
fieldName: string
|
|
19
|
+
fieldWidth: number
|
|
20
|
+
listItems?: ListItem[] // 当 fieldType 为 'SingleSelect' 时可能需要
|
|
21
|
+
numberFormat?: string // 当 fieldType 为 'Date' 或 'Number' 时可能需要
|
|
22
|
+
maxRating?: number // 当 fieldType 为 'Rating' 时可能需要
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// View 参数的结构
|
|
27
|
+
interface View {
|
|
28
|
+
name: string
|
|
29
|
+
type: ViewType
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Config 参数的结构
|
|
33
|
+
interface AddSheetConfig {
|
|
34
|
+
fields?: Field[]
|
|
35
|
+
name?: string // 默认为 'data1'
|
|
36
|
+
views?: View[] // 默认创建 'Grid' 视图
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 更新后的 Sheets 接口
|
|
40
|
+
export interface Sheets {
|
|
41
|
+
/** 数据表的总数量,只读 */
|
|
42
|
+
readonly Count: number
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 新建一个数据表到指定位置
|
|
46
|
+
* @param Before 插入到Before(索引从1开始/数据表名)对应sheet之前。如果不需要此参数,传入 null。
|
|
47
|
+
* @param After 插入到After(索引从1开始/数据表名)对应sheet之后。如果不需要此参数,传入 null。
|
|
48
|
+
* @param Type 要创建的数据表类型。目前支持 "xlEtDataBaseSheet"(数据表)和 "xlDbDashBoardSheet"(仪表盘)。
|
|
49
|
+
* @param Config 数据表的专属配置对象。
|
|
50
|
+
* @returns 返回新创建的 Sheet 对象。
|
|
51
|
+
*/
|
|
52
|
+
Add(
|
|
53
|
+
Before: number | string | null,
|
|
54
|
+
After: number | string | null,
|
|
55
|
+
Type: 'xlEtDataBaseSheet' | 'xlDbDashBoardSheet', // 根据文档,'xlEtFlexPaperSheet'暂不支持
|
|
56
|
+
Config: AddSheetConfig
|
|
57
|
+
): Sheet
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 删除指定的数据表
|
|
61
|
+
* @param Index 要删除的数据表的索引位置(从1开始)或数据表名称。
|
|
62
|
+
* @returns 返回一个布尔值,表示删除操作是否成功。
|
|
63
|
+
*/
|
|
64
|
+
Delete(Index: number | string): boolean
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 将数据表移动到指定位置。Before 和 After 参数只需要提供一个,另一个需传入 null。
|
|
68
|
+
* @param From 要移动的数据表的名称或索引位置(从1开始)。
|
|
69
|
+
* @param Before 移动到 Before (索引从1开始/数据表名) 对应的 sheet 之前。如果不需要此参数,传入 null。
|
|
70
|
+
* @param After 移动到 After (索引从1开始/数据表名) 对应的 sheet 之后。如果不需要此参数,传入 null。
|
|
71
|
+
* @returns 返回一个布尔值,表示移动操作是否成功。
|
|
72
|
+
*/
|
|
73
|
+
Move(
|
|
74
|
+
From: number | string,
|
|
75
|
+
Before: number | string | null,
|
|
76
|
+
After: number | string | null
|
|
77
|
+
): boolean
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 根据索引位置(从1开始)或名称获取对应的数据表对象。
|
|
81
|
+
* @param Index 要获取的数据表的索引位置(从1开始)或数据表名称。
|
|
82
|
+
* @returns 返回一个 Sheet 对象。
|
|
83
|
+
*/
|
|
84
|
+
Item(Index: number | string): Sheet
|
|
85
|
+
(Index: number | string): Sheet
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 根据数据表的 ApproveId(即 SheetsId)获取对应的数据表对象。
|
|
89
|
+
* @param Id 要获取的数据表的 SheetsId,类型为数字或字符串。
|
|
90
|
+
* @returns 返回一个 Sheet 对象。
|
|
91
|
+
*/
|
|
92
|
+
ItemById(Id: number | string): Sheet
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 获取当前活动数据表的索引位置(从1开始)。
|
|
96
|
+
* @returns 返回一个数字,表示当前活动数据表的索引。
|
|
97
|
+
*/
|
|
98
|
+
GetActiveSheetIndex(): number
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 获取当前活动数据表的 ID (SheetsId)。
|
|
102
|
+
* @returns 返回一个数字,表示当前活动数据表的 ID。
|
|
103
|
+
*/
|
|
104
|
+
GetActiveSheetId(): number
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 为当前数据表集合添加 CreateSheet 事件监听。当新建数据表时触发(目前仅支持添加数据表事件,添加说明页和仪表盘不会触发)。
|
|
108
|
+
* 注意:在脚本编辑器中使用时,脚本运行结束后回调可能无法正常触发。
|
|
109
|
+
* @param Callback 指定事件发生时的回调方法。回调参数中包含新创建的 Sheet 对象。
|
|
110
|
+
* @returns 返回一个 EventContext 对象,可用于取消事件监听(调用其 Destroy() 方法)。
|
|
111
|
+
*/
|
|
112
|
+
OnCreateSheet(Callback: (data: { Sheet: Sheet }) => void): EventContext
|
|
113
|
+
}
|
|
@@ -2,44 +2,44 @@ import type { FieldTypeKeys, } from './DB_Application_Field'
|
|
|
2
2
|
import type { ViewType } from './DB_Application_View'
|
|
3
3
|
|
|
4
4
|
interface Sheet {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
description: string,
|
|
6
|
+
fields: {
|
|
7
|
+
arraySupport: boolean,
|
|
8
|
+
autoFillSourceField: string,
|
|
9
|
+
customConfig: string,
|
|
10
|
+
defaultValueType: 'Normal',
|
|
11
|
+
description: string,
|
|
12
|
+
id: string,
|
|
13
|
+
name: string,
|
|
14
|
+
numberFormat: string,
|
|
15
|
+
syncField: boolean,
|
|
16
|
+
type: 'FieldTypeKeys',
|
|
17
|
+
uniqueValue: boolean
|
|
18
|
+
loadLegalHoliday: number,
|
|
19
|
+
items: {
|
|
20
|
+
color: number,
|
|
21
|
+
id: string,
|
|
22
|
+
value: string
|
|
23
23
|
}[],
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
allowAddItemWhenInputting: true,
|
|
25
|
+
autoAddItem: boolean,
|
|
26
26
|
}[],
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
icon: string,
|
|
28
|
+
id: number,
|
|
29
|
+
name: number,
|
|
30
|
+
primaryFieldId: number,
|
|
31
|
+
recordsCount: number,
|
|
32
|
+
sheetType: 'xlEtDataBaseSheet',
|
|
33
|
+
subType: 'Normal',
|
|
34
|
+
syncFieldSourceId: string,
|
|
35
|
+
syncFieldSourceNameId: string,
|
|
36
|
+
syncType: None,
|
|
37
|
+
views: {
|
|
38
|
+
id: string,
|
|
39
|
+
name: string,
|
|
40
|
+
notice: string,
|
|
41
|
+
recordsCount: number,
|
|
42
|
+
type: ViewType
|
|
43
43
|
}[]
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -56,8 +56,8 @@ interface SheetFuncOptions {
|
|
|
56
56
|
export type { Sheet, SheetFuncOptions }
|
|
57
57
|
|
|
58
58
|
export default interface DBSheet {
|
|
59
|
-
CreateSheet(options: Omit<SheetFuncOptions,
|
|
59
|
+
CreateSheet(options: Omit<SheetFuncOptions, SheetId>): Sheet
|
|
60
60
|
GetSheets(): Sheet[]
|
|
61
|
-
UpdateSheet(options: Pick<SheetFuncOptions,
|
|
62
|
-
DeleteSheet(options: Pick<SheetFuncOptions,
|
|
61
|
+
UpdateSheet(options: Pick<SheetFuncOptions, SheetId | Name>): boolean
|
|
62
|
+
DeleteSheet(options: Pick<SheetFuncOptions, SheetId>): Pick<Sheet, id>
|
|
63
63
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { WithPromise } from './type-tools'
|
|
2
2
|
import type DB_Application from './DB_Application'
|
|
3
|
+
import type DB_Application_Plus from './DB_Application_Plus'
|
|
3
4
|
import type KSheet_Application from './KSheet_Application'
|
|
4
5
|
import type KSDrive from './KSDrive'
|
|
5
6
|
|
|
6
7
|
interface WpsjsGlobal {
|
|
7
8
|
KSDrive: KSDrive
|
|
8
|
-
Application: KSheet_Application & DB_Application
|
|
9
|
+
Application: KSheet_Application & DB_Application & DB_Application_Plus
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
type WpsjsGlobalApi = WithPromise<WpsjsGlobal>
|