@steedos/service-plugin-amis 2.3.0-beta.18 → 2.3.0-beta.20
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.
|
@@ -5,17 +5,23 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
; (function () {
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
const loadCss = (href)=>{
|
|
9
10
|
try {
|
|
10
|
-
|
|
11
|
+
// 加载Amis css
|
|
11
12
|
let amisStyle = document.createElement("link");
|
|
12
13
|
amisStyle.setAttribute("rel", "stylesheet");
|
|
13
14
|
amisStyle.setAttribute("type", "text/css");
|
|
14
|
-
amisStyle.setAttribute("href",
|
|
15
|
+
amisStyle.setAttribute("href", href);
|
|
15
16
|
document.getElementsByTagName("head")[0].appendChild(amisStyle);
|
|
16
17
|
} catch (error) {
|
|
17
18
|
console.error(error)
|
|
18
19
|
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
loadCss(Steedos.absoluteUrl("/unpkg.com/amis/sdk/sdk.css"))
|
|
23
|
+
loadCss(Steedos.absoluteUrl("/unpkg.com/amis/sdk/helper.css"))
|
|
24
|
+
loadCss(Steedos.absoluteUrl("/unpkg.com/amis/sdk/iconfont.css"))
|
|
19
25
|
|
|
20
26
|
try {
|
|
21
27
|
window['attrAccept'] = function (file, acceptedFiles) {
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Description: 提供amis选人组件需要的数据接口
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const objectql = require("@steedos/objectql");
|
|
6
|
+
const _ = require("lodash");
|
|
7
|
+
const clone = require("clone");
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
name: "amis-metadata-space_users",
|
|
12
|
+
mixins: [],
|
|
13
|
+
/**
|
|
14
|
+
* Settings
|
|
15
|
+
*/
|
|
16
|
+
settings: {
|
|
17
|
+
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Dependencies
|
|
22
|
+
*/
|
|
23
|
+
dependencies: [],
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Actions
|
|
27
|
+
*/
|
|
28
|
+
actions: {
|
|
29
|
+
getSpaceUsersOptions: {
|
|
30
|
+
rest: {
|
|
31
|
+
method: "GET",
|
|
32
|
+
path: "/space_users/options"
|
|
33
|
+
},
|
|
34
|
+
async handler(ctx) {
|
|
35
|
+
const options = await this.getSpaceUsersOptions(ctx);
|
|
36
|
+
return { status: 0, data: { options } }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Events
|
|
43
|
+
*/
|
|
44
|
+
events: {
|
|
45
|
+
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Methods
|
|
50
|
+
*/
|
|
51
|
+
methods: {
|
|
52
|
+
/**
|
|
53
|
+
1.当没有传入参数,即第一次请求接口时返回如下格式的数据:
|
|
54
|
+
[
|
|
55
|
+
{
|
|
56
|
+
"leftOptions": [
|
|
57
|
+
{
|
|
58
|
+
"label": "总公司",
|
|
59
|
+
"value": 1,
|
|
60
|
+
"defer": true
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
"children": [
|
|
64
|
+
{
|
|
65
|
+
"ref": 1,
|
|
66
|
+
"defer": true
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"ref": 2,
|
|
70
|
+
"defer": true
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"ref": 3,
|
|
74
|
+
"defer": true
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"ref": 4,
|
|
78
|
+
"defer": true
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"ref": 5,
|
|
82
|
+
"defer": true
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"ref": 6,
|
|
86
|
+
"defer": true
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
2.当传入def参数值时,表示展开左侧组织树某个组织,此时返回如下格式的数据:
|
|
92
|
+
[
|
|
93
|
+
{
|
|
94
|
+
"label": "部门 A",
|
|
95
|
+
"value": 2
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"label": "部门 B",
|
|
99
|
+
"value": 3,
|
|
100
|
+
"defer": true
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"label": "部门 C",
|
|
104
|
+
"value": 4
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
2.当传入ref参数值时,表示点击左侧某个组织,按此组织过滤右侧人员列表,此时返回如下格式的数据:
|
|
108
|
+
[
|
|
109
|
+
{
|
|
110
|
+
"label": "用户 1",
|
|
111
|
+
"value": "user1"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"label": "用户 2",
|
|
115
|
+
"value": "user2"
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
*/
|
|
119
|
+
getSpaceUsersOptions: {
|
|
120
|
+
async handler(ctx) {
|
|
121
|
+
const userSession = ctx.meta.user;
|
|
122
|
+
const spaceId = userSession.spaceId;
|
|
123
|
+
// 有 dep 值则是懒加载部门树,有 ref 值则是懒加载人员,否则按第一次加载返回第一个 option作为select的基本配置
|
|
124
|
+
// 需要懒加载的项通过返回相关项的 defer 为 true 来标记。左右两部分都支持懒加载。
|
|
125
|
+
// 参考 https://aisuda.bce.baidu.com/amis/zh-CN/components/form/select#%E4%BA%BA%E5%91%98%E7%82%B9%E9%80%89
|
|
126
|
+
const dep = ctx.params.dep;
|
|
127
|
+
const ref = ctx.params.ref;
|
|
128
|
+
const valueField = ctx.params.valueField || "user";//user or _id
|
|
129
|
+
const term = ctx.params.term;
|
|
130
|
+
if(dep){
|
|
131
|
+
// 有 dep 值则是懒加载部门树,返回展开后的部门列表
|
|
132
|
+
const fields = "_id,name,children".split(",");
|
|
133
|
+
const filters = [['space', '=', spaceId], ['parent', '=', dep]];
|
|
134
|
+
const orgs = await objectql.getObject('organizations').find({filters: filters, fields: fields});
|
|
135
|
+
const reOptions = _.map(orgs, (org)=>{
|
|
136
|
+
return {
|
|
137
|
+
value: org._id,
|
|
138
|
+
label: org.name,
|
|
139
|
+
defer: !!(org.children && org.children.length)
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return reOptions;
|
|
143
|
+
}
|
|
144
|
+
else if(ref || term){
|
|
145
|
+
// 有 ref 值则是懒加载人员,返回按ref值过滤后的人员列表
|
|
146
|
+
const fields = "_id,name,user".split(",");
|
|
147
|
+
const filters = [['space', '=', spaceId], ['user_accepted', '=', true]];
|
|
148
|
+
if(term){
|
|
149
|
+
const fieldsForSearch = ["name", "username", "email", "mobile"];
|
|
150
|
+
const termFilters = [];
|
|
151
|
+
fieldsForSearch.forEach(function(field){
|
|
152
|
+
termFilters.push([field, 'contains', term]);
|
|
153
|
+
termFilters.push("or");
|
|
154
|
+
});
|
|
155
|
+
termFilters.pop();
|
|
156
|
+
filters.push(termFilters);
|
|
157
|
+
}
|
|
158
|
+
else{
|
|
159
|
+
filters.push(['organizations_parents', '=', ref]);
|
|
160
|
+
}
|
|
161
|
+
const sus = await objectql.getObject('space_users').find({filters: filters, fields: fields});
|
|
162
|
+
const reOptions = _.map(sus, (su)=>{
|
|
163
|
+
return {
|
|
164
|
+
value: su[valueField],
|
|
165
|
+
label: su.name
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return reOptions;
|
|
169
|
+
}
|
|
170
|
+
else{
|
|
171
|
+
// 接口返回的选项中,第一个 option 是以下这种格式时,
|
|
172
|
+
// 也会把 options[0].leftOptions 当成 leftOptions
|
|
173
|
+
// options[0].children 当 options。
|
|
174
|
+
// 同时 options[0].leftDefaultValue 可以用来配置左侧选项的默认值。
|
|
175
|
+
const reOptions = [{
|
|
176
|
+
children: [],
|
|
177
|
+
leftOptions: [],
|
|
178
|
+
leftDefaultValue: ''
|
|
179
|
+
}];
|
|
180
|
+
const fields = "_id,name,children".split(",");
|
|
181
|
+
const filters = [['space', '=', spaceId], ['parent', '=', null]];
|
|
182
|
+
const rootOrgs = await objectql.getObject('organizations').find({filters: filters, fields: fields});
|
|
183
|
+
reOptions[0].leftOptions = _.map(rootOrgs, (org)=>{
|
|
184
|
+
return {
|
|
185
|
+
value: org._id,
|
|
186
|
+
label: org.name,
|
|
187
|
+
defer: !!(org.children && org.children.length)
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
reOptions[0].children = _.map(rootOrgs, (org)=>{
|
|
191
|
+
return {
|
|
192
|
+
ref: org._id,
|
|
193
|
+
defer: !!(org.children && org.children.length)
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return reOptions;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-plugin-amis",
|
|
3
|
-
"version": "2.3.0-beta.
|
|
3
|
+
"version": "2.3.0-beta.20",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "node .scripts/build.tailwind.js"
|
|
@@ -10,5 +10,5 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"gitHead": "
|
|
13
|
+
"gitHead": "78e92f69e7fb4ef58a7b9cc4861ec5a58642af95"
|
|
14
14
|
}
|