新版交易所前段管理后台
1
PC-20250623MANY\Administrator
2025-07-06 0363875eb333c67529c8b27221a6da45d1a50bfa
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
<template>
  <div class="tag-manage">
    <div class="title">
      <span>已选择</span>
    </div>
 
    <div class="tag-groups">
      <p
        v-for="(tag, i) in tags"
        v-show="tag.isSelectd"
        :key="i"
        class="tag-item"
      >
        <span>{{ tag.name }}</span>
        <i class="el-icon-close" @click="active(tag.id, tag.isSelectd)" />
      </p>
    </div>
 
    <div class="title">
      <span>标签栏</span>
    </div>
 
    <div class="tag-groups">
      <p
        v-for="(tag, i) in tags"
        :key="i"
        class="tag-item"
        :class="{ active: tag.isSelectd }"
        @click="active(tag.id, tag.isSelectd)"
      >
        <span>{{ tag.name }}</span>
      </p>
    </div>
 
    <el-button
      v-show="!isInput"
      type="primary"
      class="addbtn"
      @click="isInput = !isInput"
      >+ 添加标签
    </el-button>
 
    <div class="tag-input" v-show="isInput">
      <input
        ref="editTaginput"
        type="text"
        placeholder="回车保存..."
        v-model.trim="tagText"
        @keyup.enter="save"
      />
 
      <el-button type="primary" size="small" @click="isInput = false"
        >取消编辑
      </el-button>
    </div>
  </div>
</template>
<script>
import { ServeUpdateArticleTag, ServeEditArticleTag } from '@/api/article'
export default {
  name: 'NoteTagBox',
  props: {
    note_id: {
      type: Number,
      default: 0,
    },
    tag_ids: {
      type: Array,
      default() {
        return []
      },
    },
  },
  data() {
    return {
      ids: [],
      isInput: false,
      tagText: '',
    }
  },
  created() {
    this.ids = this.tag_ids.map(tag => tag.id)
  },
  computed: {
    tags() {
      let tags = []
      this.$store.state.note.tags.forEach(tag => {
        tags.push({
          id: tag.id,
          name: tag.tag_name,
          isSelectd: this.ids.includes(tag.id),
        })
      })
 
      return tags
    },
  },
 
  methods: {
    // 设置笔记标签事件
    active(tag_id, isSelect) {
      if (isSelect) {
        this.ids.forEach((item, index) => {
          if (item == tag_id) {
            this.ids.splice(index, 1)
          }
        })
      } else {
        if (this.ids.length >= 5) {
          this.$notify.info({
            title: '消息',
            message: '最多只能选择5个标签!',
          })
          return
        }
 
        this.ids.push(tag_id)
      }
 
      ServeUpdateArticleTag({
        article_id: this.note_id,
        tags: this.getSelectTags(),
      })
    },
 
    // 获取选中的标签ids
    getSelectTags() {
      let ids = []
      for (let item of this.tags) {
        if (item.isSelectd) ids.push(item.id)
      }
 
      return ids
    },
 
    // 保存标签事件
    save() {
      let tag_name = this.tagText
      ServeEditArticleTag({
        tag_id: 0,
        tag_name,
      }).then(({ code, data }) => {
        if (code !== 200) return false
 
        this.$store.commit('PUSH_NOTE_TAG', {
          id: data.id,
          tag_name: tag_name,
          count: 0,
        })
 
        this.tagText = ''
        this.isInput = false
      })
    },
  },
}
</script>
<style lang="less" scoped>
.tag-manage {
  .title {
    height: 20px;
    line-height: 20px;
    font-size: 14px;
    color: #ccc;
    border-bottom: 1px solid #f0e9e9;
    padding-bottom: 5px;
    position: relative;
  }
 
  .tag-groups {
    padding: 8px 8px 8px 0;
    cursor: pointer;
 
    .tag-item {
      display: inline-block;
      height: 25px;
      line-height: 25px;
      padding: 0 10px;
      font-size: 12px;
      box-sizing: border-box;
      white-space: nowrap;
      margin: 0 3px 5px 0;
      color: #409eff;
      background: rgba(64, 158, 255, 0.1);
      border-radius: 3px;
 
      i {
        cursor: pointer;
        margin-left: 5px;
      }
 
      &.active {
        border: 1px dashed #70b5fb;
      }
    }
  }
 
  .addbtn {
    height: 35px;
    width: 100%;
    margin-top: 20px;
    line-height: 9px;
    border-radius: 3px;
  }
 
  .tag-input {
    margin-top: 20px;
    min-height: 30px;
    display: flex;
    align-items: center;
 
    input {
      width: 200px;
      height: 30px;
      border: 1px solid #66b1ff;
      padding: 0 5px;
      border-radius: 3px;
      margin-right: 5px;
 
      &::-webkit-input-placeholder {
        font-size: 13px;
        color: #ccc;
      }
    }
  }
}
</style>