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
| <template>
| <view class="u-flex-1">
| <u-radio-group v-model="options.value" :disabled="disabled" @change="change">
| <u-radio v-for="(item, index) in options.items" :key="index"
| :name="item[itemValue]">{{item[itemLabel]}}</u-radio>
| </u-radio-group>
| </view>
| </template>
| <script>
| /**
| * 单选框组件
| * @property {Object} value 用于双向绑定选择框的值,返回选择框的 Value
| * @property {Boolean} disabled 是否禁用模式,是否只读模式
| * @property {String} dictType 字典类型,从字典里获取,自动设置 items、itemLabel、itemValue
| * @property {String} items 列表数据,可接受对象集合,如:[{name: '是', value: '否'}]
| * @property {String} itemLabel 指定列表数据中的什么属性名作为 option 的标签名,如 name
| * @property {String} itemValue 指定列表数据中的什么属性名作为 option 的 value 值,如 value
| * @example <js-radio v-model="model.type" dict-type="sys_yes_no"></js-radio>
| * @description Copyright (c) 2013-Now http://jeesite.com All rights reserved.
| * @author ThinkGem
| * @version 2021-3-11
| */
| export default {
| props: {
| value: {
| type: String,
| default: ''
| },
| disabled: {
| type: Boolean,
| default: false
| },
| dictType: {
| type: String,
| default: ''
| },
| items: {
| type: Array,
| default() {
| return [];
| }
| },
| itemLabel: {
| type: String,
| default: 'label'
| },
| itemValue: {
| type: String,
| default: 'value'
| }
| },
| data() {
| return {
| options: {
| value: this.value,
| items: this.items
| }
| };
| },
| watch: {
| value(val, oldVal) {
| this.options.value = val;
| },
| items(val, oldVal){
| this.options.items = val;
| }
| },
| created() {
| this.loadData();
| },
| methods: {
| loadData(){
| if (this.dictType != ''){
| this.$u.api.dictData({dictType: this.dictType}).then(res => {
| if (typeof res === 'object' && res.result === 'login'){
| return;
| }
| this.options.items = res.data;
| });
| }else{
| this.options.items = this.items;
| }
| },
| change(val){
| // console.log(val);
| this.$emit('input', val);
| }
| }
| }
| </script>
| <style lang="scss" scoped>
|
| </style>
|
|