vdesign-ui 0.1.24 → 0.2.0

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.
Files changed (76) hide show
  1. package/dist/components/activityviews/index.vue +14 -12
  2. package/dist/components/button/index.vue +1 -1
  3. package/dist/components/checkbox/checkbox-group/index.vue +2 -1
  4. package/dist/components/checkbox/index.vue +19 -20
  5. package/dist/components/dialog/index.vue +15 -11
  6. package/dist/components/dropdown/index.vue +43 -31
  7. package/dist/components/empty/404-dark.png +0 -0
  8. package/dist/components/empty/404.png +0 -0
  9. package/dist/components/empty/index.vue +30 -2
  10. package/dist/components/empty/network-dark.png +0 -0
  11. package/dist/components/empty/network.png +0 -0
  12. package/dist/components/empty/nocoupons-dark.png +0 -0
  13. package/dist/components/empty/nocoupons.png +0 -0
  14. package/dist/components/empty/nodata-dark.png +0 -0
  15. package/dist/components/empty/nodata.png +0 -0
  16. package/dist/components/empty/nomargin-dark.png +0 -0
  17. package/dist/components/empty/nomargin.png +0 -0
  18. package/dist/components/empty/nonotice-dark.png +0 -0
  19. package/dist/components/empty/nonotice.png +0 -0
  20. package/dist/components/empty/noocomments-dark.png +0 -0
  21. package/dist/components/empty/noocomments.png +0 -0
  22. package/dist/components/empty/noorders-dark.png +0 -0
  23. package/dist/components/empty/noorders.png +0 -0
  24. package/dist/components/empty/noposition-dark.png +0 -0
  25. package/dist/components/empty/noposition.png +0 -0
  26. package/dist/components/empty/nosearch-dark.png +0 -0
  27. package/dist/components/empty/nosearch.png +0 -0
  28. package/dist/components/empty/style.less +4 -0
  29. package/dist/components/footer/index.vue +5 -1
  30. package/dist/components/footnav/footnav-item/index.vue +11 -42
  31. package/dist/components/footnav/index.vue +29 -33
  32. package/dist/components/headnav/index.vue +55 -37
  33. package/dist/components/headnav/style.less +0 -9
  34. package/dist/components/icon/font/iconfont.css +62 -952
  35. package/dist/components/icon/font/iconfont.js +5 -1
  36. package/dist/components/icon/index.vue +26 -18
  37. package/dist/components/input/calcTextareaHeight.js +36 -140
  38. package/dist/components/input/index.vue +107 -109
  39. package/dist/components/input/search/index.vue +18 -22
  40. package/dist/components/input/stepper/index.vue +32 -26
  41. package/dist/components/input/style.less +20 -33
  42. package/dist/components/list/index.vue +57 -69
  43. package/dist/components/list/style.less +20 -92
  44. package/dist/components/loading/img_status_loading_white_ani.svg +155 -0
  45. package/dist/components/loading/img_status_refresh_ani.svg +158 -0
  46. package/dist/components/loading/index.vue +28 -11
  47. package/dist/components/loading/style.less +1 -1
  48. package/dist/components/mixins/clickoutside.js +81 -81
  49. package/dist/components/mixins/outlineConfigPlugin.js +11 -6
  50. package/dist/components/noticebar/index.vue +9 -4
  51. package/dist/components/pagebreak/index.vue +21 -14
  52. package/dist/components/radio/index.vue +164 -135
  53. package/dist/components/radio/radio-group/index.vue +40 -52
  54. package/dist/components/result/index.vue +1 -2
  55. package/dist/components/selector/index.vue +49 -31
  56. package/dist/components/selector/style.less +14 -0
  57. package/dist/components/step-item/index.vue +2 -2
  58. package/dist/components/tabs/index.vue +55 -32
  59. package/dist/components/tabs/tab/index.vue +13 -16
  60. package/dist/components/tag/index.vue +18 -4
  61. package/dist/components/tag/style.less +2 -2
  62. package/dist/components/title/index.vue +11 -8
  63. package/dist/components/title/style.less +6 -0
  64. package/dist/img/img_status_loading_white_ani.b56fcfae.svg +155 -0
  65. package/dist/img/img_status_refresh_ani.d0e59f12.svg +158 -0
  66. package/dist/token.css +8 -0
  67. package/dist/vdesign-ui.common.js +1481 -1354
  68. package/dist/vdesign-ui.css +1 -1
  69. package/dist/vdesign-ui.umd.js +1481 -1354
  70. package/dist/vdesign-ui.umd.min.js +3 -3
  71. package/package.json +1 -1
  72. package/dist/components/loading/loading.png +0 -0
  73. package/dist/components/loading/refresh.png +0 -0
  74. package/dist/img/404-dark.775df5bb.png +0 -0
  75. package/dist/img/network-dark.11a147bb.png +0 -0
  76. package/dist/img/nodata-dark.b0ea0e39.png +0 -0
@@ -1,81 +1,81 @@
1
- import Vue from 'vue';
2
- import { on } from './dom';
3
- // 定义一个空数组 nodeList,用于存储绑定了该指令的元素。
4
- const nodeList = [];
5
- //定义一个常量 ctx,用于标识特殊属性名。
6
- const ctx = '@@clickoutsideContext';
7
- // 定义一个变量 startClick,用于存储点击开始时的事件对象。
8
- let startClick;
9
- // 定义一个变量 seed,用作节点标识的种子。
10
- let seed = 0;
11
- // 在文档上添加一个 mousedown 事件监听器,用于记录点击开始时的事件对象。
12
- !Vue.prototype.$isServer && on(document, 'mousedown', e => (startClick = e));
13
- // 添加一个 mouseup 事件监听器。当鼠标放开时,
14
- !Vue.prototype.$isServer && on(document, 'mouseup', e => {
15
- // 遍历 nodeList 数组中的每个元素,并执行它们的 documentHandler 函数。
16
- nodeList.forEach(node => node[ctx].documentHandler(e, startClick));
17
- });
18
- // 创建一个处理文档点击事件的函数。
19
- // 该函数返回一个闭包函数,用于检查点击事件是否发生在绑定的元素外部,并执行相应的回调函数。
20
- function createDocumentHandler(el, binding, vnode) {
21
- return function (mouseup = {}, mousedown = {}) {
22
- if (!vnode ||
23
- !vnode.context ||
24
- !mouseup.target ||
25
- !mousedown.target ||
26
- el.contains(mouseup.target) ||
27
- el.contains(mousedown.target) ||
28
- el === mouseup.target ||
29
- (vnode.context.popperElm &&
30
- (vnode.context.popperElm.contains(mouseup.target) ||
31
- vnode.context.popperElm.contains(mousedown.target)))) return;
32
-
33
- if (binding.expression &&
34
- el[ctx].methodName &&
35
- vnode.context[el[ctx].methodName]) {
36
- vnode.context[el[ctx].methodName]();
37
- } else {
38
- el[ctx].bindingFn && el[ctx].bindingFn();
39
- }
40
- };
41
- }
42
-
43
- /**
44
- * v-clickoutside
45
- * @desc 点击元素外面才会触发的事件
46
- * @example
47
- * ```vue
48
- * <div v-element-clickoutside="handleClose">
49
- * ```
50
- */
51
- export default {
52
- // 将元素添加到 nodeList 数组中,并为该元素添加一个包含事件处理函数的特殊属性。
53
- bind(el, binding, vnode) {
54
- nodeList.push(el);
55
- const id = seed++;
56
- el[ctx] = {
57
- id,
58
- documentHandler: createDocumentHandler(el, binding, vnode),
59
- methodName: binding.expression,
60
- bindingFn: binding.value
61
- };
62
- },
63
- // 当指令所在组件的 VNode 更新时调用,更新元素的事件处理函数和绑定方法。
64
- update(el, binding, vnode) {
65
- el[ctx].documentHandler = createDocumentHandler(el, binding, vnode);
66
- el[ctx].methodName = binding.expression;
67
- el[ctx].bindingFn = binding.value;
68
- },
69
- // 从 nodeList 中移除对应的元素,并删除特殊属性。
70
- unbind(el) {
71
- let len = nodeList.length;
72
-
73
- for (let i = 0; i < len; i++) {
74
- if (nodeList[i][ctx].id === el[ctx].id) {
75
- nodeList.splice(i, 1);
76
- break;
77
- }
78
- }
79
- delete el[ctx];
80
- }
81
- };
1
+ import Vue from 'vue';
2
+ import { on } from './dom';
3
+ // 定义一个空数组 nodeList,用于存储绑定了该指令的元素。
4
+ const nodeList = [];
5
+ //定义一个常量 ctx,用于标识特殊属性名。
6
+ const ctx = '@@clickoutsideContext';
7
+ // 定义一个变量 startClick,用于存储点击开始时的事件对象。
8
+ let startClick;
9
+ // 定义一个变量 seed,用作节点标识的种子。
10
+ let seed = 0;
11
+ // 在文档上添加一个 mousedown 事件监听器,用于记录点击开始时的事件对象。
12
+ !Vue.prototype.$isServer && on(document, 'mousedown', e => (startClick = e));
13
+ // 添加一个 mouseup 事件监听器。当鼠标放开时,
14
+ !Vue.prototype.$isServer && on(document, 'mouseup', e => {
15
+ // 遍历 nodeList 数组中的每个元素,并执行它们的 documentHandler 函数。
16
+ nodeList.forEach(node => node[ctx].documentHandler(e, startClick));
17
+ });
18
+ // 创建一个处理文档点击事件的函数。
19
+ // 该函数返回一个闭包函数,用于检查点击事件是否发生在绑定的元素外部,并执行相应的回调函数。
20
+ function createDocumentHandler(el, binding, vnode) {
21
+ return function (mouseup = {}, mousedown = {}) {
22
+ if (!vnode ||
23
+ !vnode.context ||
24
+ !mouseup.target ||
25
+ !mousedown.target ||
26
+ el.contains(mouseup.target) ||
27
+ el.contains(mousedown.target) ||
28
+ el === mouseup.target ||
29
+ (vnode.context.popperElm &&
30
+ (vnode.context.popperElm.contains(mouseup.target) ||
31
+ vnode.context.popperElm.contains(mousedown.target)))) return;
32
+
33
+ if (binding.expression &&
34
+ el[ctx].methodName &&
35
+ vnode.context[el[ctx].methodName]) {
36
+ vnode.context[el[ctx].methodName](mouseup.target);
37
+ } else {
38
+ el[ctx].bindingFn && el[ctx].bindingFn();
39
+ }
40
+ };
41
+ }
42
+
43
+ /**
44
+ * v-clickoutside
45
+ * @desc 点击元素外面才会触发的事件
46
+ * @example
47
+ * ```vue
48
+ * <div v-element-clickoutside="handleClose">
49
+ * ```
50
+ */
51
+ export default {
52
+ // 将元素添加到 nodeList 数组中,并为该元素添加一个包含事件处理函数的特殊属性。
53
+ bind(el, binding, vnode) {
54
+ nodeList.push(el);
55
+ const id = seed++;
56
+ el[ctx] = {
57
+ id,
58
+ documentHandler: createDocumentHandler(el, binding, vnode),
59
+ methodName: binding.expression,
60
+ bindingFn: binding.value
61
+ };
62
+ },
63
+ // 当指令所在组件的 VNode 更新时调用,更新元素的事件处理函数和绑定方法。
64
+ update(el, binding, vnode) {
65
+ el[ctx].documentHandler = createDocumentHandler(el, binding, vnode);
66
+ el[ctx].methodName = binding.expression;
67
+ el[ctx].bindingFn = binding.value;
68
+ },
69
+ // 从 nodeList 中移除对应的元素,并删除特殊属性。
70
+ unbind(el) {
71
+ let len = nodeList.length;
72
+
73
+ for (let i = 0; i < len; i++) {
74
+ if (nodeList[i][ctx].id === el[ctx].id) {
75
+ nodeList.splice(i, 1);
76
+ break;
77
+ }
78
+ }
79
+ delete el[ctx];
80
+ }
81
+ };
@@ -1,5 +1,5 @@
1
1
  // outlineConfigPlugin.js
2
-
2
+ import { inBrowser } from '@p/utils/env'
3
3
  // __debug=1&__debug_vdesign_token=1
4
4
  const OutlineConfig = {
5
5
  install(Vue, options = {}) {
@@ -11,14 +11,19 @@ const OutlineConfig = {
11
11
 
12
12
  Vue.mixin({
13
13
  created() {
14
- this.$outlineConfig.outlineEnabled = this.shouldEnableOutline()
15
-
16
- this.$watch('$outlineConfig.outlineEnabled', (newValue) => {
17
- document.documentElement.style.setProperty('--outline-visible', newValue ? '1px' : '0');
18
- }, { immediate: true });
14
+ if (inBrowser) {
15
+ this.$outlineConfig.outlineEnabled = this.shouldEnableOutline()
16
+ this.$watch('$outlineConfig.outlineEnabled', (newValue) => {
17
+ document.documentElement.style.setProperty('--outline-visible', newValue ? '1px' : '0');
18
+ }, { immediate: true });
19
+ }
19
20
  },
20
21
  methods:{
21
22
  shouldEnableOutline() {
23
+ if (!inBrowser) {
24
+ // 如果是在服务端渲染,返回默认值 false
25
+ return false;
26
+ }
22
27
  // 获取URL的查询参数部分
23
28
  const searchParams = new URLSearchParams(window.location.search);
24
29
  // 对于哈希模式,也解析哈希中的查询字符串
@@ -66,6 +66,7 @@
66
66
  </template>
67
67
 
68
68
  <script>
69
+ import { inBrowser } from '@p/utils/env'
69
70
  export default {
70
71
  name: 'vd-noticebar',
71
72
  props: {
@@ -173,12 +174,16 @@ export default {
173
174
  },
174
175
 
175
176
  updated() {
176
- this.$_checkOverflow()
177
+ if (inBrowser) {
178
+ this.$_checkOverflow();
179
+ }
177
180
  },
178
181
 
179
182
  mounted() {
180
- this.$_checkOverflow()
181
- this.init()
183
+ if (inBrowser) {
184
+ this.$_checkOverflow();
185
+ this.init();
186
+ }
182
187
  },
183
188
 
184
189
  methods: {
@@ -209,7 +214,7 @@ export default {
209
214
 
210
215
  },
211
216
  init() {
212
-
217
+ if (!inBrowser) return; // 确保只在浏览器环境执行
213
218
  const { wrap, content } = this.$refs
214
219
  if (wrap && content) {
215
220
  // const _width = window.innerWidth
@@ -1,14 +1,14 @@
1
1
  <template>
2
2
  <div class="vd-page-break">
3
- <template v-if="drop">
3
+ <template v-if="drop === 'dropdot'">
4
4
  <div v-for="pageNumber in totalPages" class="vd-page-break__cell"
5
5
  :class="{ 'vd-page-break__cell--active': pageNumber === currentPage }" :key="pageNumber"
6
6
  @click="changePage(pageNumber)">
7
7
  </div>
8
8
  </template>
9
9
 
10
- <div class="vd-page-break__number" v-else>
11
- <span class="vd-page-break__number--active" v-html="number"></span>
10
+ <div class="vd-page-break__number" v-else-if="drop === 'dropnum'">
11
+ <span class="vd-page-break__number--active" v-if="number">{{ number }}</span>
12
12
  <span class="vd-page-break__number--line">/</span>
13
13
  <span class="vd-page-break__number--total">{{ total }}</span>
14
14
  </div>
@@ -19,36 +19,43 @@
19
19
  export default {
20
20
  name: 'vd-page-break',
21
21
  props: {
22
+ drop: {
23
+ type: String,
24
+ default: 'dropdot'
25
+ },
22
26
  totalPages: {
23
27
  type: Number,
24
28
  default: 5
25
29
  },
26
- drop: {
27
- type: Boolean,
28
- default: true
29
- },
30
- number: {
30
+ activePage: {
31
31
  type: Number,
32
- default: 1
32
+ default: 1 // 默认显示第一页
33
33
  },
34
34
  total: {
35
35
  type: Number,
36
36
  default: 9
37
- }
37
+ },
38
+ number: {
39
+ type: Number,
40
+ default: 1
41
+ },
42
+
38
43
  },
39
44
  data() {
40
45
  return {
41
- currentPage: 1,
46
+ currentPage: this.activePage // 从外部传入的值初始化,
42
47
  }
43
48
  },
44
- computed: {
45
-
49
+ watch: {
50
+ activePage(newVal) {
51
+ this.currentPage = newVal; // 外部传入值变化时更新当前页
52
+ }
46
53
  },
47
54
  methods: {
48
55
  changePage(pageNumber) {
49
56
  if (pageNumber >= 1 && pageNumber <= this.totalPages) {
50
57
  this.currentPage = pageNumber;
51
- this.$emit('page-changed', pageNumber);
58
+ this.$emit('change', pageNumber);
52
59
  }
53
60
  },
54
61
  },
@@ -1,155 +1,184 @@
1
1
  <template>
2
+ <!-- 常规单选框 -->
2
3
  <label :class="wrapClasses" v-if="!radioButton">
3
- <span :class="radioClasses">
4
- <span :class="innerClasses"></span>
5
- <input type="radio" :class="inputClasses" :disabled="disabled" :checked="currentValue" @change="change">
6
- </span>
7
- <div class="vd-radio__label" v-if="$slots.default">
8
- <div class="vd-radio__text">
9
- <slot></slot>
10
- </div>
11
- <!-- <p class="vd-radio__description" v-if="extra">{{ extra }}</p> -->
4
+ <span :class="radioClasses">
5
+ <span :class="innerClasses"></span>
6
+ <input
7
+ type="radio"
8
+ :class="inputClasses"
9
+ :disabled="isDisabled"
10
+ :checked="currentValue"
11
+ @change="handleChange"
12
+ >
13
+ </span>
14
+ <!-- 标签内容 -->
15
+ <div class="vd-radio__label" v-if="$slots.default">
16
+ <div class="vd-radio__text">
17
+ <slot></slot>
12
18
  </div>
19
+ </div>
13
20
  </label>
14
-
15
-
16
- <label class="vd-radio vd-radio-button" :class="radioButtonClasses" v-else>
17
- <input type="radio" :class="inputClasses" :disabled="disabled" :checked="currentValue" @change="change">
18
- <span class="vd-radio-button-text">
19
- <slot></slot>
20
- </span>
21
+
22
+ <!-- 按钮样式的单选框 -->
23
+ <label
24
+ class="vd-radio vd-radio-button"
25
+ :class="radioButtonClasses"
26
+ v-else
27
+ >
28
+ <input
29
+ type="radio"
30
+ :class="inputClasses"
31
+ :disabled="isDisabled"
32
+ :checked="currentValue"
33
+ @change="handleChange"
34
+ >
35
+ <span class="vd-radio-button-text">
36
+ <slot></slot>
37
+ </span>
21
38
  </label>
22
- </template>
23
- <script>
24
- import { findComponentUpward } from './assist';
25
- const prefixCls = 'vd-radio';
26
-
27
- export default {
39
+ </template>
40
+ <script>
41
+ import { findComponentUpward } from './assist';
42
+
43
+ const prefixCls = 'vd-radio';
44
+
45
+ export default {
28
46
  name: 'vd-radio',
29
47
  props: {
30
- radioButton: {
31
- type: Boolean,
32
- default: false
33
- },
34
- disabled: {
35
- type: Boolean,
36
- default: false
37
- },
38
- value: {
39
- type: [String, Number, Boolean],
40
- default: false
41
- },
42
- trueValue: {
43
- type: [String, Number, Boolean],
44
- default: true
45
- },
46
- falseValue: {
47
- type: [String, Number, Boolean],
48
- default: false
49
- },
50
- name: {
51
- type: [String, Number, Boolean]
52
- },
53
- type: {
54
- type: String,
55
- default: ''
56
- },
48
+ // 组件的值,用于 v-model 绑定
49
+ value: {
50
+ type: [String, Number, Boolean],
51
+ default: false,
52
+ },
53
+ // 是否为按钮样式
54
+ radioButton: Boolean,
55
+ // 是否禁用
56
+ disabled: {
57
+ type: Boolean,
58
+ default: false,
59
+ },
60
+ // 选中时的值
61
+ trueValue: {
62
+ type: [String, Number, Boolean],
63
+ default: true,
64
+ },
65
+ // 未选中时的值
66
+ falseValue: {
67
+ type: [String, Number, Boolean],
68
+ default: false,
69
+ },
70
+ // 单选框的标识名称,在组内使用
71
+ name: {
72
+ type: [String, Number, Boolean],
73
+ },
74
+ // 类型,用于样式
75
+ type: String,
57
76
  },
58
77
  data() {
59
- return {
60
- currentValue: this.value,
61
- group: false,
62
- parent: findComponentUpward(this, 'vd-radio-group'),
63
- // parent: this.$parent,
64
- focusWrapper: false,
65
- focusInner: false
66
- };
78
+ return {
79
+ // 当前是否选中
80
+ currentValue: this.value === this.trueValue,
81
+ // 是否属于单选框组
82
+ isGroup: false,
83
+ // 父级单选框组的引用
84
+ parentGroup: null,
85
+ };
67
86
  },
68
87
  computed: {
69
- wrapClasses() {
70
- return [
71
- `${prefixCls}`,
72
- {
73
- [`${prefixCls}--checked`]: this.currentValue,
74
- [`${prefixCls}--disabled`]: this.disabled,
75
- }
76
- ];
77
- },
78
- radioClasses() {
79
- return [
80
- `${prefixCls}__input`,
81
- ];
82
- },
83
- innerClasses() {
84
- return [
85
- `${prefixCls}__icon`,
86
- ];
87
- },
88
- inputClasses() {
89
- return `${prefixCls}__original`;
90
- },
91
- radioButtonClasses() {
92
- return [
93
- {
94
- [`${prefixCls}-button--checked`]: this.currentValue,
95
- [`${prefixCls}-button--${this.type}`]: this.type,
96
- [`${prefixCls}-button--disabled`]: this.disabled,
97
- }
98
- ]
99
-
100
- }
88
+ // 计算禁用状态,优先级:自身 > 组
89
+ isDisabled() {
90
+ return this.disabled || (this.isGroup && this.parentGroup.disabled);
91
+ },
92
+ // 包裹类名
93
+ wrapClasses() {
94
+ return [
95
+ `${prefixCls}`,
96
+ {
97
+ [`${prefixCls}--checked`]: this.currentValue,
98
+ [`${prefixCls}--disabled`]: this.isDisabled,
99
+ },
100
+ ];
101
+ },
102
+ // 单选框的类名
103
+ radioClasses() {
104
+ return [`${prefixCls}__input`];
105
+ },
106
+ // 图标的类名
107
+ innerClasses() {
108
+ return [`${prefixCls}__icon`];
109
+ },
110
+ // 输入框的类名
111
+ inputClasses() {
112
+ return `${prefixCls}__original`;
113
+ },
114
+ // 按钮样式的类名
115
+ radioButtonClasses() {
116
+ return [
117
+ {
118
+ [`${prefixCls}-button--checked`]: this.currentValue,
119
+ [`${prefixCls}-button--${this.type}`]: this.type,
120
+ [`${prefixCls}-button--disabled`]: this.isDisabled,
121
+ },
122
+ ];
123
+ },
101
124
  },
102
125
  mounted() {
103
- if (this.parent) {
104
- this.group = true;
126
+ // 查找父级 vd-radio-group 组件
127
+ this.parentGroup = findComponentUpward(this, 'vd-radio-group');
128
+ this.isGroup = !!this.parentGroup;
129
+
130
+ if (this.isGroup) {
131
+ // 如果在组内,注册到组中
132
+ this.parentGroup.updateValue();
133
+ } else {
134
+ // 如果不在组内,更新自身的选中状态
135
+ this.updateValue();
136
+ }
137
+ },
138
+ methods: {
139
+ // 处理 change 事件
140
+ handleChange(event) {
141
+ if (this.isDisabled) {
142
+ return;
105
143
  }
106
-
107
- if (this.group) {
108
- this.parent.updateValue();
144
+
145
+ const checked = event.target.checked;
146
+ this.currentValue = checked;
147
+ const value = checked ? this.trueValue : this.falseValue;
148
+ this.$emit('input', value);
149
+
150
+ if (this.isGroup) {
151
+ // 如果在组内,通知组更新
152
+ this.parentGroup.change(this.name);
109
153
  } else {
110
- this.updateValue();
154
+ // 否则,触发自身的 change 事件
155
+ this.$emit('change', value);
111
156
  }
112
- },
113
- methods: {
114
- change(event) {
115
- if (this.disabled) {
116
- return false;
117
- }
118
-
119
- const checked = event.target.checked;
120
- this.currentValue = checked;
121
-
122
- const value = checked ? this.trueValue : this.falseValue;
123
- this.$emit('input', value);
124
-
125
- if (this.group) {
126
- if (this.name !== undefined) {
127
- this.parent.change({
128
- value: this.name,
129
- checked: this.value
130
- });
131
- }
132
- } else {
133
- this.$emit('change', value);
134
- }
135
- },
136
- updateValue() {
137
- this.currentValue = this.value === this.trueValue;
138
- },
139
-
157
+ },
158
+ // 更新 currentValue
159
+ updateValue() {
160
+ if (this.isGroup) {
161
+ // 组内,通过比较组的值和自身的 name 来确定是否选中
162
+ this.currentValue = this.parentGroup.value === this.name;
163
+ } else {
164
+ // 组外,通过比较 value 和 trueValue
165
+ this.currentValue = this.value === this.trueValue;
166
+ }
167
+ },
140
168
  },
141
169
  watch: {
142
- value(val) {
143
- if (val === this.trueValue || val === this.falseValue) {
144
- this.updateValue();
145
- } else {
146
- throw 'Value should be trueValue or falseValue.';
147
- }
148
- }
149
- }
150
- };
151
- </script>
152
-
170
+ // 监听 value 的变化
171
+ value() {
172
+ this.updateValue();
173
+ },
174
+ // 如果在组内,监听组的 value 变化
175
+ 'parentGroup.value'() {
176
+ this.updateValue();
177
+ },
178
+ },
179
+ };
180
+ </script>
181
+
153
182
  <style lang="less">
154
- @import './style.less';
183
+ @import "./style.less";
155
184
  </style>