gyyg-components 0.3.6 → 0.3.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gyyg-components",
3
- "version": "0.3.06",
3
+ "version": "0.3.08",
4
4
  "private": false,
5
5
  "main": "lib/gyyg-components.umd.js",
6
6
  "scripts": {
@@ -24,7 +24,7 @@
24
24
  :span="item.span || 1"
25
25
  :contentClassName="direction == 'vertical' ? 'vertical-content' : item.contentClassName || ''"
26
26
  :labelStyle="direction == 'horizontal' ? { width: labelWidth + 'px', textAlign: 'right' } : {}"
27
- :contentStyle="item.contentStyle || {}"
27
+ :contentStyle="direction == 'horizontal' ? { width: 'calc(100% - (' + labelWidth + 'px))' }: {}"
28
28
  :labelClassName="direction == 'vertical' ? 'vertical-label' : item.labelClassName || ''"
29
29
  >
30
30
  <div v-if="item.type === 'img'">
@@ -1,11 +1,10 @@
1
1
  <template>
2
2
  <div :class="showTags ? 'has-tags' : ''">
3
- <mec-tags
4
- v-if="showTags"
5
- :tagsList="tagsData"
6
- ></mec-tags>
7
- <div class="btn-group">
8
-
3
+
4
+ <div
5
+ class="btn-group"
6
+ ref="btnGroup"
7
+ >
9
8
  <div
10
9
  v-for="btn in btnList"
11
10
  :key="btn.id"
@@ -64,6 +63,12 @@
64
63
 
65
64
  </div>
66
65
  </div>
66
+ <mec-tags
67
+ v-if="showTags"
68
+ :tagsList="tagsData"
69
+ @tagClose="tagClose"
70
+ :btnWidth="btnWidth"
71
+ ></mec-tags>
67
72
 
68
73
  </div>
69
74
  </template>
@@ -86,7 +91,8 @@ export default {
86
91
  },
87
92
  data() {
88
93
  return {
89
- tagsData: null
94
+ tagsData: null,
95
+ btnWidth: 0
90
96
  }
91
97
  },
92
98
  watch: {
@@ -96,8 +102,25 @@ export default {
96
102
  },
97
103
  deep: true,
98
104
  immediate: true
105
+ },
106
+ btnList: {
107
+ handler(val) {
108
+ if (this.$refs.btnGroup) {
109
+ this.btnWidth = this.$refs.btnGroup.offsetWidth
110
+
111
+ }
112
+ },
113
+ deep: true,
114
+ immediate: true
99
115
  }
100
116
  },
117
+ mounted() {
118
+ this.$nextTick(() => {
119
+ this.btnWidth = this.$refs.btnGroup.offsetWidth
120
+ console.log('width: calc(100% - (' + this.btnWidth + ' px))')
121
+ })
122
+ },
123
+
101
124
  methods: {
102
125
  // 按钮点击事件
103
126
  btnClick(btn) {
@@ -105,12 +128,17 @@ export default {
105
128
  if (btn.trigger) {
106
129
  btn.trigger()
107
130
  }
131
+ },
132
+ tagClose(key, tag) {
133
+ this.$emit('tagClose', key, tag);
108
134
  }
109
135
  },
110
136
  }
111
137
  </script>
112
138
  <style lang="less" scoped>
113
139
  /deep/ .el-button {
140
+ font-weight: normal;
141
+
114
142
  &:not(:disabled):hover {
115
143
  transform: translateY(-1px);
116
144
  }
@@ -119,7 +147,6 @@ export default {
119
147
  .btn-group {
120
148
  display: flex;
121
149
  align-items: center;
122
- flex-wrap: wrap;
123
150
 
124
151
  &>div {
125
152
  margin-left: 5px;
@@ -136,7 +163,6 @@ export default {
136
163
  .has-tags {
137
164
  display: flex;
138
165
  align-content: center;
139
- justify-content: space-between;
140
166
  }
141
167
 
142
168
  /deep/ .el-badge__content.is-fixed {
@@ -1,28 +1,28 @@
1
1
  <template>
2
- <el-radio-group
3
- v-model="radio"
4
- :value="radio"
5
- @change="handleChange"
6
- v-bind="$attrs"
7
- class="radio-group"
8
- >
9
- <el-radio
10
- v-for="item in options"
11
- :label="item[props.value]"
12
- :key="item[props.value]"
13
- :value="item[props.value]"
14
- :border="border"
15
- >{{ item[props.label] }}</el-radio>
16
- </el-radio-group>
2
+ <el-radio-group
3
+ v-model="radio"
4
+ :value="radio"
5
+ @change="handleChange"
6
+ v-bind="$attrs"
7
+ class="radio-group"
8
+ >
9
+ <el-radio
10
+ v-for="item in option"
11
+ :label="item[props.value]"
12
+ :key="item[props.value]"
13
+ :value="item[props.value]"
14
+ :border="border"
15
+ >{{ item[props.label] }}</el-radio>
16
+ </el-radio-group>
17
17
  </template>
18
18
  <script>
19
19
  export default {
20
- name: 'mec-radio',
21
- props: {
20
+ name: 'mec-radio',
21
+ props: {
22
22
  value: {},
23
23
  border: {
24
- type: Boolean,
25
- default: false,
24
+ type: Boolean,
25
+ default: false,
26
26
  },
27
27
  options: {},
28
28
  props: {
@@ -34,30 +34,53 @@ export default {
34
34
  },
35
35
  },
36
36
  },
37
- data() {
38
- return {
39
- radio: this.value,
40
- }
37
+ data() {
38
+ return {
39
+ radio: this.value,
40
+ option: []
41
+ }
42
+ },
43
+ watch: {
44
+ value: {
45
+ handler(val) {
46
+ this.radio = val
47
+ },
48
+ immediate: true
41
49
  },
42
- watch: {
43
- value: {
44
- handler(val) {
45
- this.radio = val
46
- },
47
- immediate: true
48
- },
49
- radio: {
50
- handler(val) {
51
- this.$emit('input', val)
52
- this.$emit('update:value', val)
53
- },
50
+ radio: {
51
+ handler(val) {
52
+ this.$emit('input', val)
53
+ this.$emit('update:value', val)
54
+ },
55
+ },
56
+ options: {
57
+ handler: function (val) {
58
+ if (!Array.isArray(this.options) && this.options) {
59
+ if (this.options instanceof Promise) {
60
+ this.options.then(val => {
61
+ this.option = val.data || val;
62
+ });
63
+ }
64
+ if (typeof this.options == 'function') {
65
+ this.options().then(val => {
66
+ this.option = val.data || val;
67
+ });
68
+ }
69
+
70
+ } else {
71
+ this.option = this.options;
54
72
  }
73
+ },
74
+ deep: true,
75
+ immediate: true,
55
76
  },
56
- methods: {
57
- handleChange(e) {
58
- this.$emit('change', e)
59
- },
60
- }
77
+ },
78
+ methods: {
79
+ handleChange(val) {
80
+ let info = this.option.filter(item => item[this.props.value] === val)
81
+ this.$emit('change', val, info.length > 0 ? info[0] : {})
82
+ },
83
+ }
61
84
 
62
85
  }
63
86
  </script>
@@ -100,9 +100,10 @@ export default {
100
100
  methods: {
101
101
  handleChange(val) {
102
102
  this.selected = val;
103
+ let info = this.option.filter(item => item[this.props.value] == val)
103
104
  this.$emit("input", this.selected);
104
105
  this.$emit('update:value', val)
105
- this.$emit("change", val);
106
+ this.$emit("change", val, info.length > 0 ? info[0] : {});
106
107
  },
107
108
  clear() {
108
109
  this.selected = '';
@@ -1,13 +1,36 @@
1
1
  <template>
2
- <div>
3
- <el-tag
4
- v-for="tag in tagsList"
5
- :key="tag.id"
6
- closable
7
- :type="tag.type || ''"
2
+ <div
3
+ class="mec-tags"
4
+ :style="{ width: `calc(100% - ${btnWidth}px)` }"
5
+ ref="tagsContainer"
6
+ >
7
+ <el-button
8
+ icon="el-icon-arrow-left"
9
+ circle
10
+ v-show="showArrow"
11
+ @click="scrollLeft"
12
+ ></el-button>
13
+ <div
14
+ class="tags-box"
15
+ ref="tagsBox"
8
16
  >
9
- {{ tag.label }}: {{ tag.value }}
10
- </el-tag>
17
+ <el-tag
18
+ v-for="(tag, index) in tagsData"
19
+ :key="index"
20
+ closable
21
+ :type="tag.type || ''"
22
+ @close="handleClose(index, tag)"
23
+ >
24
+ {{ tag.label }}: {{ tag.value }}
25
+ </el-tag>
26
+ </div>
27
+ <el-button
28
+ style="margin-left: 3px"
29
+ icon="el-icon-arrow-right"
30
+ circle
31
+ v-show="showArrow"
32
+ @click="scrollRight"
33
+ ></el-button>
11
34
  </div>
12
35
  </template>
13
36
  <script>
@@ -15,9 +38,120 @@ export default {
15
38
  name: 'MecTags',
16
39
  props: {
17
40
  tagsList: {
18
- type: [Array, Object],
41
+ type: [Array, Object],
42
+ },
43
+ btnWidth: {
44
+ // type: Number,
45
+ },
46
+ },
47
+ data() {
48
+ return {
49
+ tagsData: [],
50
+ tagsContainerWidth: 0,
51
+ showArrow: false,
19
52
  }
20
53
  },
54
+ watch: {
55
+ tagsList: {
56
+ handler(val) {
57
+ this.tagsData = []
58
+ this.tagsData = [...val] ;
59
+ if(this.tagsData.length > 0) {
60
+ this.$nextTick(() => {
61
+ this.updateTagsContainerWidth();
62
+ });
63
+ }
64
+ },
65
+ deep: true,
66
+ immediate: true
67
+ }
68
+ },
69
+ mounted() {
70
+ this.updateTagsContainerWidth();
71
+ window.addEventListener('resize', this.updateTagsContainerWidth);
72
+ },
73
+ beforeDestroy() {
74
+ window.removeEventListener('resize', this.updateTagsContainerWidth);
75
+ },
76
+ methods: {
77
+ handleClose(index, tag) {
78
+ this.tagsData.splice(index, 1);
79
+ this.$emit('tagClose', tag.key, tag);
80
+ },
81
+ scrollLeft() {
82
+ const tagsBox = this.$refs.tagsBox;
83
+ tagsBox.scrollBy({
84
+ left: -150,
85
+ behavior: 'smooth'
86
+ });
87
+ },
88
+ scrollRight() {
89
+ const tagsBox = this.$refs.tagsBox;
90
+ tagsBox.scrollBy({
91
+ left: 150,
92
+ behavior: 'smooth'
93
+ });
94
+ },
95
+
96
+ updateTagsContainerWidth() {
97
+ this.tagsContainerWidth = this.$refs.tagsContainer.offsetWidth;
98
+ const boxWidth = this.$refs.tagsBox.scrollWidth;
99
+ if (boxWidth > this.tagsContainerWidth) {
100
+ this.showArrow = true;
101
+ } else {
102
+ this.showArrow = false;
103
+ }
104
+ }
105
+ }
21
106
  }
22
107
 
23
108
  </script>
109
+ <style lang="less" scoped>
110
+ .mec-tags {
111
+ height: 40px;
112
+ margin-left: 10px;
113
+ display: flex;
114
+ align-items: center;
115
+
116
+ /deep/ .el-tag {
117
+ margin-right: 10px;
118
+ margin-bottom: 10px;
119
+ margin-bottom: 5px;
120
+ margin-top: 5px;
121
+ font-size: 14px;
122
+ height: 30px;
123
+ line-height: 30px;
124
+ padding: 0 5px;
125
+ color: #1890ff;
126
+
127
+ .el-icon-close {
128
+ right: 0;
129
+ }
130
+ }
131
+
132
+ /deep/ .el-button.is-circle {
133
+ padding: 0;
134
+ width: 24px;
135
+ height: 24px;
136
+ line-height: 24px;
137
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
138
+ margin-right: 3px;
139
+ flex-grow: 0;
140
+ flex-shrink: 0;
141
+
142
+ &:hover,
143
+ &:focus {
144
+ background: #1890ff;
145
+ border-color: #1890ff;
146
+ color: #fff;
147
+ }
148
+ }
149
+ }
150
+
151
+ .tags-box {
152
+ display: flex;
153
+ overflow-x: auto;
154
+ scroll-behavior: smooth;
155
+ scrollbar-width: none;
156
+ }
157
+ </style>