1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import { Vue, Component, Prop, Watch } from 'vue-property-decorator';
import './app-embed-picker.less';
import { CreateElement } from 'vue';
import { Subject, Subscription } from 'rxjs';
@Component({})
export default class AppEmbedPicker extends Vue {
/**
* 表单数据
*
* @type {*}
* @memberof AppPicker
*/
@Prop() public data!: any;
/**
* 值
*
* @type {*}
* @memberof AppEmbedPicker
*/
@Prop() public value: any;
/**
* 表单状态
*
* @type {Subject<any>}
* @memberof AppEmbedPicker
*/
@Prop() public formState!: Subject<any>
/**
* 视图状态事件
*
* @protected
* @type {(Subscription | undefined)}
* @memberof SelectType
*/
protected formStateEvent: Subscription | undefined;
/**
* 值项名称
*
* @type {string}
* @memberof AppPicker
*/
@Prop() public valueItem?: string;
/**
* 关联视图名称
*
* @type {string}
* @memberof AppPicker
*/
@Prop() public refviewname?: string;
/**
* 提示信息
*
* @type {string}
* @memberof AppEmbedPicker
*/
@Prop() public placeholder!: string;
/**
* 空值文本
*
* @type {string}
* @memberof EmbedPicker
*/
@Prop() public emptyText?: string;
/**
* 属性项名称
*
* @type {string}
* @memberof AppPicker
*/
@Prop() public name!: string;
/**
* 关联视图参数
*
* @type {*}
* @memberof AppEmbedPicker
*/
@Prop() public itemParam: any;
/**
* 是否忽略之变化
*
* @type {boolean}
* @memberof AppEmbedPicker
*/
@Prop() public ignorefieldvaluechange!: boolean;
/**
* 重置项
*
* @type {string}
* @memberof AppEmbedPicker
*/
@Prop() public refreshitems?: string;
/**
* 视图参数
*
* @type {string}
* @memberof AppEmbedPicker
*/
public srfparentdata: any = '';
/**
* 设置视图参数
*
* @memberof AppEmbedPicker
*/
public setViewParam(activeData: any) {
if (!this.itemParam || !activeData) {
return;
}
let arg: any = {};
if (this.itemParam.parentdata) {
let parentData: any = {};
Object.keys(this.itemParam.parentdata).every((name: string) => {
let value: string = this.itemParam.parentdata[name];
if (value.startsWith('%') && value.endsWith('%')) {
const key: string = value.substring(1, value.length - 1);
if (!activeData.hasOwnProperty(key)) {
this.$Notice.error({ title: '错误', desc: `操作失败,未能找到当前表单项${key},无法继续操作` });
return false;
}
value = activeData[key];
}
Object.assign(parentData, { [name]: value });
return true;
});
Object.assign(arg, parentData);
}
this.srfparentdata = arg;
}
/**
* 监控值
*
* @param {*} newVal
* @param {*} oldVal
* @memberof AppFormDRUIPart
*/
@Watch('data')
onActivedataChange(newVal: any, oldVal: any) {
const newFormData: any = JSON.parse(newVal);
const oldDormData: any = JSON.parse(oldVal);
this.setViewParam(newFormData);
if (!this.refreshitems || this.ignorefieldvaluechange) {
return;
}
if(Object.is(newFormData[this.refreshitems], oldDormData[this.refreshitems])) {
return;
}
this.setValue([{srfmajortext: null, srfkey: null}]);
let param = this.srfparentdata;
this.srfparentdata = {};
Object.assign(this.srfparentdata, param);
}
/**
* 生命周期
*
* @memberof AppEmbedPicker
*/
public created() {
if(this.formState) {
this.formStateEvent = this.formState.subscribe(({ tag, action, data }) => {
if (Object.is('load', action)) {
this.setViewParam(JSON.parse(this.data));
}
});
}
}
/**
* vue 生命周期
*
* @memberof SelectType
*/
public destroyed() {
if (this.formStateEvent) {
this.formStateEvent.unsubscribe();
}
}
/**
* 设置值
*
* @param {*} item
* @memberof AppEmbedPicker
*/
public setValue(item: any) {
if (this.name) {
this.$emit('formitemvaluechange', { name: this.name, value: item[0].srfmajortext });
}
if (this.valueItem) {
this.$emit('formitemvaluechange', { name: this.valueItem, value: item[0].srfkey });
}
}
/**
* 绘制内容
*
* @param {CreateElement} h
* @returns
* @memberof AppEmbedPicker
*/
public render(h: CreateElement) {
if (this.refviewname) {
return (
<div class="app-embed-picker">
<div style={{ height: this.placeholder ? 'calc(100% - 32px)' : '100%' }}>
{
this.$createElement(this.refviewname, {
props: {
viewdata: JSON.stringify({ srfparentdata: this.srfparentdata })
},
on: {
'viewdataschange': (args: any) => {
if (args && args.length > 0) {
this.setValue(args);
}
}
},
style: {
height: '100%'
}
})
}
</div>
{ this.placeholder ? ( this.value ? <div class="app-embed-value">{this.value}</div> : <div class="app-embed-placeholder">{this.placeholder}</div> ) : '' }
</div>
);
} else {
return (<div>{this.emptyText}</div>);
}
}
}