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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
| <style lang="less">
| @import "./render.less";
| @import "@/styles/drawer-common.less";
| </style>
| <template>
| <div class="render">
| <Card>
| <Alert show-icon>
| iView自3.2.0版本起,Table组件已支持 slot-scope 用法,建议使用该新用法,
| <a href="https://run.iviewui.com/50ahQHrs" target="_blank"
| >查看官方示例</a
| >。 以下为原小于3.2.0版本中Render函数的相关用法示例
| </Alert>
| <Table border :columns="columns" :data="data" ref="table"></Table>
| </Card>
|
| <Drawer width="640" v-model="infoDrawerVisible" title="详细信息">
| <Avatar :src="infoForm.avatar" size="large" style="margin-bottom: 10px" />
| <p class="render-info-title">基本信息</p>
| <div class="demo-drawer-profile">
| <Row>
| <Col span="12">用户名: {{ infoForm.name }}</Col>
| <Col span="12">注册邮箱: {{ infoForm.email }}</Col>
| </Row>
| <Row>
| <Col span="12">生日: {{ infoForm.birth }}</Col>
| <Col span="12">
| 个人网页:
| <a :href="infoForm.website" target="_blank">{{
| infoForm.website
| }}</a>
| </Col>
| </Row>
| </div>
| <Divider />
| <p class="render-info-title">联系方式</p>
| <div class="demo-drawer-profile">
| <Row>
| <Col span="12">Email: {{ infoForm.email }}</Col>
| <Col span="12">手机号: {{ infoForm.mobile }}</Col>
| </Row>
| <Row>
| <Col span="12">
| GitHub:
| <a :href="infoForm.github" target="_blank">{{ infoForm.github }}</a>
| </Col>
| </Row>
| </div>
| </Drawer>
|
| <Drawer title="编辑" v-model="editDrawerVisible" :mask-closable="false" width="720">
| <div :style="{ maxHeight: maxHeight }" class="drawer-content">
| <Form :model="infoForm" label-position="top">
| <Row :gutter="32">
| <Col span="12">
| <FormItem label="姓名">
| <Input v-model="infoForm.name" />
| </FormItem>
| </Col>
| <Col span="12">
| <FormItem label="个人网站">
| <Input v-model="infoForm.website">
| <span slot="prepend">http://</span>
| </Input>
| </FormItem>
| </Col>
| </Row>
| <Row :gutter="32">
| <Col span="12">
| <FormItem label="状态">
| <Select v-model="infoForm.status" transfer>
| <Option :value="0">启用</Option>
| <Option :value="-1">禁用</Option>
| </Select>
| </FormItem>
| </Col>
| <Col span="12">
| <FormItem label="审核状态">
| <Select v-model="infoForm.value" transfer>
| <Option :value="0">待审核</Option>
| <Option :value="1">审核通过</Option>
| <Option :value="-1">审核驳回</Option>
| </Select>
| </FormItem>
| </Col>
| </Row>
| <Row :gutter="32">
| <Col span="12">
| <FormItem label="创建时间">
| <DatePicker
| v-model="infoForm.date"
| :options="options"
| type="date"
| style="display: block"
| placement="bottom-end"
| transfer
| ></DatePicker>
| </FormItem>
| </Col>
| </Row>
| <FormItem label="描述">
| <Input type="textarea" v-model="infoForm.desc" :rows="4" />
| </FormItem>
| </Form>
| </div>
| <div class="drawer-footer br">
| <Button type="primary" @click="submitEdit">提交</Button>
| <Button @click="editDrawerVisible = false">取消</Button>
| </div>
| </Drawer>
|
| <Modal v-model="picVisible" title="图片预览" footer-hide draggable>
| <img
| :src="infoForm.avatar"
| alt="无效的图片链接"
| style="width: 100%; margin: 0 auto; display: block"
| />
| </Modal>
| </div>
| </template>
|
| <script>
| import expandRow from "./expand.vue";
| export default {
| name: "render",
| components: { expandRow },
| data() {
| return {
| maxHeight: 510,
| infoDrawerVisible: false, // 信息查看
| editDrawerVisible: false, // 编辑
| picVisible: false, // 图片预览
| columns: [
| // 表头
| {
| type: "selection",
| width: 60,
| align: "center",
| },
| {
| type: "expand",
| width: 50,
| render: (h, params) => {
| return h(expandRow, {
| props: {
| row: params.row,
| },
| });
| },
| },
| {
| type: "index",
| width: 60,
| align: "center",
| },
| {
| title: "用户",
| key: "name",
| minWidth: 190,
| sortable: true,
| render: (h, params) => {
| return h("div", [
| h(
| "a",
| {
| on: {
| click: () => {
| this.showDetail(params.row);
| },
| },
| },
| params.row.name
| ),
| ]);
| },
| },
| {
| title: "图片(点击可预览)",
| key: "createTime",
| align: "center",
| width: 150,
| render: (h, params) => {
| return h("img", {
| attrs: {
| src: params.row.avatar,
| alt: "加载图片失败",
| },
| style: {
| cursor: "pointer",
| width: "40px",
| height: "40px",
| "margin-top": "5px",
| "object-fit": "contain",
| },
| on: {
| click: () => {
| this.showPic(params.row);
| },
| },
| });
| },
| },
| {
| title: "状态",
| key: "status",
| align: "center",
| width: 150,
| render: (h, params) => {
| return h(
| "i-switch",
| {
| props: {
| value: params.row.status,
| size: "large",
| "true-value": 0,
| "false-value": -1,
| },
| on: {
| "on-change": (v) => {
| this.changeStatus(params.row, v);
| },
| },
| },
| [
| h("span", { slot: "open" }, "启用"),
| h("span", { slot: "close" }, "禁用"),
| ]
| );
| },
| },
| {
| title: "价格设定",
| key: "price",
| align: "center",
| width: 150,
| render: (h, params) => {
| return h("InputNumber", {
| props: {
| value: params.row.price,
| min: 0,
| precision: 2,
| },
| on: {
| "on-change": (v) => {
| this.changePrice(params.row, v);
| },
| },
| });
| },
| },
| {
| title: "审核操作",
| key: "value",
| width: 200,
| render: (h, params) => {
| return h(
| "Select",
| {
| props: {
| value: params.row.value,
| transfer: true,
| },
| on: {
| "on-change": (v) => {
| this.changeSelect(params.row, v);
| },
| },
| },
| [
| h(
| "Option",
| {
| props: {
| value: 0,
| },
| },
| "待审核"
| ),
| h(
| "Option",
| {
| props: {
| value: 1,
| },
| },
| "审核通过"
| ),
| h(
| "Option",
| {
| props: {
| value: -1,
| },
| },
| "审核驳回"
| ),
| ]
| );
| },
| },
| {
| title: "操作",
| key: "action",
| align: "center",
| width: 250,
| fixed: "right",
| render: (h, params) => {
| return h("div", [
| h(
| "Button",
| {
| props: {
| type: "primary",
| size: "small",
| icon: "ios-create-outline",
| },
| style: {
| marginRight: "5px",
| },
| on: {
| click: () => {
| this.edit(params.row);
| },
| },
| },
| "编辑"
| ),
| h(
| "Dropdown",
| {
| props: { transfer: true },
| on: {
| "on-click": (v) => {
| this.changeDropDown(params.row, v);
| },
| },
| },
| [
| h(
| "Button",
| {
| props: { size: "small" },
| style: {
| height: "23.5px",
| },
| },
| [
| "更多操作",
| h("Icon", {
| props: {
| type: "ios-arrow-down",
| },
| }),
| ]
| ),
| h("DropdownMenu", { slot: "list" }, [
| h("DropdownItem", { props: { name: "reset" } }, "重置密码"),
| h("DropdownItem", { props: { name: "delete" } }, "删除"),
| ]),
| ]
| ),
| ]);
| },
| },
| ],
| data: [], // 表单数据
| infoForm: {},
| options: {
| shortcuts: [
| {
| text: "今天",
| value() {
| return new Date();
| },
| onClick: (picker) => {
| this.$Message.info("Click today");
| },
| },
| {
| text: "昨天",
| value() {
| const date = new Date();
| date.setTime(date.getTime() - 3600 * 1000 * 24);
| return date;
| },
| onClick: (picker) => {
| this.$Message.info("Click yesterday");
| },
| },
| {
| text: "一周前",
| value() {
| const date = new Date();
| date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
| return date;
| },
| onClick: (picker) => {
| this.$Message.info("Click a week ago");
| },
| },
| ],
| },
| };
| },
| methods: {
| init() {
| this.maxHeight =
| Number(document.documentElement.clientHeight - 121) + "px";
| this.getDataList();
| },
| getDataList() {
| // 以下为模拟数据
| this.data = [
| {
| id: "1",
| name: "XBoot(点我查看详细信息)",
| email: "1012139570@qq.com",
| birth: "2018-08-08",
| website: "http://xboot.exrick.cn",
| mobile: "18782059033",
| github: "https://github.com/Exrick/XBoot",
| avatar: "https://s1.ax1x.com/2018/05/19/CcdVQP.png",
| value: 0,
| status: 0,
| price: 18.88,
| date: "2018-08-08",
| desc: "XBoot开发平台",
| },
| {
| id: "2",
| name: "Exrick(点我查看详细信息)",
| email: "1012139570@qq.com",
| birth: "2018-08-08",
| website: "http://exrick.cn",
| mobile: "18782059032",
| github: "https://github.com/Exrick",
| avatar: "https://ooo.0o0.ooo/2021/01/16/VuODA1yUSCeXzFM.png",
| value: 1,
| status: -1,
| price: 66.66,
| date: "2018-08-08",
| desc: "XBoot作者",
| },
| ];
| },
| showDetail(v) {
| // 转换null为""
| for (let attr in v) {
| if (v[attr] == null) {
| v[attr] = "";
| }
| }
| let str = JSON.stringify(v);
| let data = JSON.parse(str);
| this.infoForm = data;
| this.infoDrawerVisible = true;
| },
| showPic(v) {
| this.infoForm.avatar = v.avatar;
| this.picVisible = true;
| },
| changeStatus(row, v) {
| this.$Message.success("修改用户 " + row.name + " 状态为 " + v + " 成功");
| },
| changePrice(row, v) {
| this.$Message.success("修改 " + row.name + " 价格为 " + v + " 成功");
| },
| changeSelect(row, v) {
| this.$Message.success("修改 " + row.name + " 审核状态为 " + v + " 成功");
| },
| changeDropDown(row, v) {
| this.$Message.info("点击了 " + row.name + " 的 " + v);
| },
| edit(v) {
| // 转换null为""
| for (let attr in v) {
| if (v[attr] == null) {
| v[attr] = "";
| }
| }
| let str = JSON.stringify(v);
| let data = JSON.parse(str);
| this.infoForm = data;
| this.editDrawerVisible = true;
| },
| submitEdit() {
| this.$Message.success("编辑成功");
| this.editDrawerVisible = false;
| },
| },
| mounted() {
| this.init();
| },
| };
| </script>
|
|