@xilonglab/vue-main 1.6.9 → 1.6.13

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": "@xilonglab/vue-main",
3
- "version": "1.6.9",
3
+ "version": "1.6.13",
4
4
  "description": "xilong vue main",
5
5
  "main": "packages/index.js",
6
6
  "scripts": {
@@ -8,8 +8,8 @@ const emits = defineEmits(['change', 'update:modelValue'])
8
8
 
9
9
  const props = defineProps({
10
10
  modelValue: {
11
- type: String,
12
- default: ''
11
+ type: Array,
12
+ default: () => []
13
13
  },
14
14
  editable: {
15
15
  type: Boolean,
@@ -25,20 +25,10 @@ const props = defineProps({
25
25
  }
26
26
  })
27
27
 
28
- const tags = computed({
29
- get() {
30
- if (typeof props.modelValue == 'string') {
31
- if (props.modelValue.length !== 0) {
32
- return props.modelValue.split(',');
33
- }
34
- }
35
- return []
36
- },
37
- set(data) {
38
- emits('change', data.join(','))
39
- emits('update:modelValue', data.join(','))
40
- },
41
- });
28
+ function updateValue(data) {
29
+ emits('change', data)
30
+ emits('update:modelValue', data)
31
+ }
42
32
 
43
33
  const valueMap = computed(() => {
44
34
  let tmp = {};
@@ -52,16 +42,15 @@ const newTag = ref('')
52
42
 
53
43
  const handlers = {
54
44
  add() {
55
- const temp = tags.value.slice()
45
+ const temp = Array.isArray(props.modelValue) ? props.modelValue.slice() : []
56
46
  temp.push(newTag.value);
57
- tags.value = temp
47
+ updateValue(temp)
58
48
  newTag.value = ''
59
49
  },
60
50
  remove(index) {
61
- tags.value.splice(index, 1)
62
- const temp = tags.value.slice()
51
+ const temp = Array.isArray(props.modelValue) ? props.modelValue.slice() : []
63
52
  temp.splice(index, 1);
64
- tags.value = temp
53
+ updateValue(temp)
65
54
  }
66
55
  }
67
56
  </script>
@@ -69,30 +58,52 @@ const handlers = {
69
58
 
70
59
  <template>
71
60
  <div class="xl-tags">
72
- <el-tag v-for="(tag, index) in tags" :key="tag" :closable="editable" @close="handlers.remove(index)">
73
- {{ type == 'select' ? valueMap[tag] : tag }}
74
- </el-tag>
75
- <xl-input v-if="editable && type == 'input'" class="new-tag" v-model="newTag" />
76
- <xl-search-select v-if="editable && type == 'select'" class="new-tag" v-model="newTag"
77
- :options="options"/>
78
- <xl-button v-if="editable" class="add-btn" @click="handlers.add">+ 添加</xl-button>
61
+ <div class="tags-list">
62
+ <el-tag v-for="(tag, index) in modelValue" :key="tag" :closable="editable" @close="handlers.remove(index)">
63
+ {{ type == 'select' ? valueMap[tag] : tag }}
64
+ </el-tag>
65
+ </div>
66
+ <div v-if="editable" class="editor-row">
67
+ <xl-input v-if="type == 'input'" class="new-tag" v-model="newTag" />
68
+ <xl-search-select v-if="type == 'select'" class="new-tag" v-model="newTag" :options="options" />
69
+ <xl-button class="add-btn" @click="handlers.add">+ 添加</xl-button>
70
+ </div>
79
71
  </div>
80
72
  </template>
81
73
 
82
74
 
83
75
  <style lang="less" scoped>
76
+ .xl-tags {
77
+ display: flex;
78
+ flex-wrap: wrap;
79
+ align-items: center;
80
+ gap: 6px;
81
+ }
82
+
83
+ .tags-list {
84
+ display: flex;
85
+ flex-wrap: wrap;
86
+ align-items: center;
87
+ gap: 6px;
88
+ min-height: 32px;
89
+ }
90
+
91
+ .editor-row {
92
+ display: inline-flex;
93
+ align-items: center;
94
+ gap: 6px;
95
+ }
96
+
84
97
  .el-tag {
85
- margin-left: 3px;
86
- margin-bottom: 2px;
98
+ margin: 0;
87
99
  }
88
100
 
89
- .xl-input{
90
- width:auto!important
101
+ .xl-input {
102
+ width: auto !important
91
103
  }
92
104
 
93
105
  .new-tag {
94
- margin-left: 3px;
95
- margin-bottom: 2px;
106
+ min-width: 180px;
96
107
  height: 32px;
97
108
  line-height: 30px;
98
109
  padding-top: 0;
@@ -100,6 +111,6 @@ const handlers = {
100
111
  }
101
112
 
102
113
  .add-btn {
103
- margin-left: 3px;
114
+ height: 32px;
104
115
  }
105
116
  </style>