|
@@ -1,202 +1,207 @@
|
|
|
-<template>
|
|
|
- <div class="tag">
|
|
|
- <div :class="className(item)" v-for="item in list" :key="item.id" @click="selectTag(item)">
|
|
|
- <span class="label">{{item.name}}</span>
|
|
|
- <i class="iconfont huifont-bianji" v-if="type === 'insert'" @click.stop="updateTag(item)"></i>
|
|
|
- <i class="iconfont huifont-guanbi" v-if="type === 'insert'" @click.stop="deleteTag(item)"></i>
|
|
|
- </div>
|
|
|
- <div class="target-item target-item-insert" v-if="type === 'insert'" @click="insertTag">
|
|
|
- <i class="iconfont huifont-xinzeng"></i>
|
|
|
- <span class="label">新增标签</span>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
-</template>
|
|
|
-
|
|
|
-<script>
|
|
|
- import {
|
|
|
- getTagList,
|
|
|
- insertTag,
|
|
|
- updateTag,
|
|
|
- deleteTag
|
|
|
- } from '@/httpApi/space'
|
|
|
- export default {
|
|
|
- name: 'tag',
|
|
|
- props: {
|
|
|
- type: {
|
|
|
- type: String,
|
|
|
- default: ''
|
|
|
- },
|
|
|
- tagType: {
|
|
|
- type: Number,
|
|
|
- default: 1
|
|
|
- },
|
|
|
- tagActive: {
|
|
|
- type: Array,
|
|
|
- default: () => {
|
|
|
- return []
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- data() {
|
|
|
- return {
|
|
|
- list: [],
|
|
|
- tagList: [],
|
|
|
- dataBox: []
|
|
|
- }
|
|
|
- },
|
|
|
- created() {
|
|
|
- this.init();
|
|
|
- },
|
|
|
- methods: {
|
|
|
- init() {
|
|
|
- getTagList(this.tagType).then(res => {
|
|
|
- if (res.state) {
|
|
|
- this.dataBox = res.data;
|
|
|
- this.initTagList();
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- initTagList() {
|
|
|
- this.tagList = this.dataBox.filter(node => this.tagActive.filter(item => item == node.id)
|
|
|
- .length > 0);
|
|
|
- if (this.type === 'insert') {
|
|
|
- this.list = this.dataBox;
|
|
|
- } else {
|
|
|
- this.list = this.tagList;
|
|
|
- }
|
|
|
- },
|
|
|
- insertTag() {
|
|
|
- this.$prompt('请输入标签名称', '有极', {
|
|
|
- confirmButtonText: '确 定',
|
|
|
- cancelButtonClass: 'cancel',
|
|
|
- confirmButtonClass: 'confirm',
|
|
|
- cancelButtonText: '取 消',
|
|
|
- inputPattern: /\S/,
|
|
|
- inputErrorMessage: '请输入标签名称'
|
|
|
- }).then(({
|
|
|
- value
|
|
|
- }) => {
|
|
|
- insertTag({
|
|
|
- type: this.tagType,
|
|
|
- name: value
|
|
|
- }).then(res => {
|
|
|
- if (res.state) {
|
|
|
- this.init();
|
|
|
- this.$message.success('操作成功')
|
|
|
- }
|
|
|
- })
|
|
|
- }).catch(() => {});
|
|
|
- },
|
|
|
- updateTag(item) {
|
|
|
- this.$prompt('请输入标签名称', '有极', {
|
|
|
- confirmButtonText: '确 定',
|
|
|
- cancelButtonClass: 'cancel',
|
|
|
- confirmButtonClass: 'confirm',
|
|
|
- cancelButtonText: '取 消',
|
|
|
- inputPattern: /\S/,
|
|
|
- inputErrorMessage: '请输入标签名称',
|
|
|
- inputValue: item.name
|
|
|
- }).then(({
|
|
|
- value
|
|
|
- }) => {
|
|
|
- updateTag({
|
|
|
- type: this.tagType,
|
|
|
- name: value,
|
|
|
- id: item.id
|
|
|
- }).then(res => {
|
|
|
- if (res.state) {
|
|
|
- this.init();
|
|
|
- this.$message.success('操作成功')
|
|
|
- }
|
|
|
- })
|
|
|
- }).catch(() => {});
|
|
|
- },
|
|
|
- selectTag(item) {
|
|
|
- if (this.type === 'look') return;
|
|
|
- if (this.tagList.filter(node => node.id === item.id).length > 0) {
|
|
|
- let index = this.tagList.findIndex(node => node.id === item.id);
|
|
|
- this.tagList.splice(index, 1);
|
|
|
- } else {
|
|
|
- this.tagList.push(item);
|
|
|
- }
|
|
|
- },
|
|
|
- className(item) {
|
|
|
- let str = this.tagList.filter(node => node.id === item.id).length > 0 ? 'target-item active' :
|
|
|
- 'target-item';
|
|
|
- if (this.type === 'insert') str += ' add'
|
|
|
- return str;
|
|
|
- },
|
|
|
- deleteTag(item) {
|
|
|
- this.$confirm('确定要删除该标签?', () => {
|
|
|
- deleteTag(item.id).then(res => {
|
|
|
- if (res.state) {
|
|
|
- this.init();
|
|
|
- this.$message.success('操作成功');
|
|
|
- }
|
|
|
- })
|
|
|
- });
|
|
|
- },
|
|
|
- tagIds() {
|
|
|
- return this.tagList.sort((a, b) => a.id - b.id).map(node => node.id).join(',');
|
|
|
- }
|
|
|
- },
|
|
|
- watch: {
|
|
|
- tagActive() {
|
|
|
- this.initTagList();
|
|
|
- }
|
|
|
- },
|
|
|
- }
|
|
|
-</script>
|
|
|
-
|
|
|
-<style lang="scss">
|
|
|
- .tag {
|
|
|
- display: flex;
|
|
|
- flex-wrap: wrap;
|
|
|
-
|
|
|
- .target-item {
|
|
|
- display: flex;
|
|
|
- height: 32px;
|
|
|
- align-items: center;
|
|
|
- margin: 5px 0;
|
|
|
- margin-right: 15px;
|
|
|
- background: #46577a;
|
|
|
- border-radius: 15px;
|
|
|
- padding: 0 15px;
|
|
|
-
|
|
|
- .iconfont {
|
|
|
- margin-left: 10px;
|
|
|
- font-size: 12px;
|
|
|
- }
|
|
|
-
|
|
|
- .huifont-bianji {
|
|
|
- font-size: 18px;
|
|
|
- }
|
|
|
-
|
|
|
- &.active {
|
|
|
- background: $--color-primary;
|
|
|
- color: #fff;
|
|
|
- }
|
|
|
-
|
|
|
- &.add {
|
|
|
- cursor: pointer;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- .target-item-insert {
|
|
|
- cursor: pointer;
|
|
|
- background: transparent;
|
|
|
- border: 1px solid #7383ad;
|
|
|
- color: #7383ad;
|
|
|
-
|
|
|
- .iconfont {
|
|
|
- margin-left: 0;
|
|
|
- margin-right: 10px;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- .target-item-insert:hover {
|
|
|
- border-color: $--color-primary;
|
|
|
- color: $--color-primary;
|
|
|
- }
|
|
|
- }
|
|
|
+<template>
|
|
|
+ <div class="tag">
|
|
|
+ <div class="no-tips" v-if="list.length === 0 && type === 'look'">暂无标签</div>
|
|
|
+ <div :class="className(item)" v-for="item in list" :key="item.id" @click="selectTag(item)">
|
|
|
+ <span class="label">{{item.name}}</span>
|
|
|
+ <i class="iconfont huifont-bianji" v-if="type === 'insert'" @click.stop="updateTag(item)"></i>
|
|
|
+ <i class="iconfont huifont-guanbi" v-if="type === 'insert'" @click.stop="deleteTag(item)"></i>
|
|
|
+ </div>
|
|
|
+ <div class="target-item target-item-insert" v-if="type === 'insert'" @click="insertTag">
|
|
|
+ <i class="iconfont huifont-xinzeng"></i>
|
|
|
+ <span class="label">新增标签</span>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+ import {
|
|
|
+ getTagList,
|
|
|
+ insertTag,
|
|
|
+ updateTag,
|
|
|
+ deleteTag
|
|
|
+ } from '@/httpApi/space'
|
|
|
+ export default {
|
|
|
+ name: 'tag',
|
|
|
+ props: {
|
|
|
+ type: {
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
+ },
|
|
|
+ tagType: {
|
|
|
+ type: Number,
|
|
|
+ default: 1
|
|
|
+ },
|
|
|
+ tagActive: {
|
|
|
+ type: Array,
|
|
|
+ default: () => {
|
|
|
+ return []
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ list: [],
|
|
|
+ tagList: [],
|
|
|
+ dataBox: []
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.init();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ init() {
|
|
|
+ getTagList(this.tagType).then(res => {
|
|
|
+ if (res.state) {
|
|
|
+ this.dataBox = res.data;
|
|
|
+ this.initTagList();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ initTagList() {
|
|
|
+ this.tagList = this.dataBox.filter(node => this.tagActive.filter(item => item == node.id)
|
|
|
+ .length > 0);
|
|
|
+ if (this.type === 'insert') {
|
|
|
+ this.list = this.dataBox;
|
|
|
+ } else {
|
|
|
+ this.list = this.tagList;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ insertTag() {
|
|
|
+ this.$prompt('请输入标签名称', '有极', {
|
|
|
+ confirmButtonText: '确 定',
|
|
|
+ cancelButtonClass: 'cancel',
|
|
|
+ confirmButtonClass: 'confirm',
|
|
|
+ cancelButtonText: '取 消',
|
|
|
+ inputPattern: /\S/,
|
|
|
+ inputErrorMessage: '请输入标签名称'
|
|
|
+ }).then(({
|
|
|
+ value
|
|
|
+ }) => {
|
|
|
+ insertTag({
|
|
|
+ type: this.tagType,
|
|
|
+ name: value
|
|
|
+ }).then(res => {
|
|
|
+ if (res.state) {
|
|
|
+ this.init();
|
|
|
+ this.$message.success('操作成功')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }).catch(() => {});
|
|
|
+ },
|
|
|
+ updateTag(item) {
|
|
|
+ this.$prompt('请输入标签名称', '有极', {
|
|
|
+ confirmButtonText: '确 定',
|
|
|
+ cancelButtonClass: 'cancel',
|
|
|
+ confirmButtonClass: 'confirm',
|
|
|
+ cancelButtonText: '取 消',
|
|
|
+ inputPattern: /\S/,
|
|
|
+ inputErrorMessage: '请输入标签名称',
|
|
|
+ inputValue: item.name
|
|
|
+ }).then(({
|
|
|
+ value
|
|
|
+ }) => {
|
|
|
+ updateTag({
|
|
|
+ type: this.tagType,
|
|
|
+ name: value,
|
|
|
+ id: item.id
|
|
|
+ }).then(res => {
|
|
|
+ if (res.state) {
|
|
|
+ this.init();
|
|
|
+ this.$message.success('操作成功')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }).catch(() => {});
|
|
|
+ },
|
|
|
+ selectTag(item) {
|
|
|
+ if (this.type === 'look') return;
|
|
|
+ if (this.tagList.filter(node => node.id === item.id).length > 0) {
|
|
|
+ let index = this.tagList.findIndex(node => node.id === item.id);
|
|
|
+ this.tagList.splice(index, 1);
|
|
|
+ } else {
|
|
|
+ this.tagList.push(item);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ className(item) {
|
|
|
+ let str = this.tagList.filter(node => node.id === item.id).length > 0 ? 'target-item active' :
|
|
|
+ 'target-item';
|
|
|
+ if (this.type === 'insert') str += ' add'
|
|
|
+ return str;
|
|
|
+ },
|
|
|
+ deleteTag(item) {
|
|
|
+ this.$confirm('确定要删除该标签?', () => {
|
|
|
+ deleteTag(item.id).then(res => {
|
|
|
+ if (res.state) {
|
|
|
+ this.init();
|
|
|
+ this.$message.success('操作成功');
|
|
|
+ }
|
|
|
+ })
|
|
|
+ });
|
|
|
+ },
|
|
|
+ tagIds() {
|
|
|
+ return this.tagList.sort((a, b) => a.id - b.id).map(node => node.id).join(',');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ tagActive() {
|
|
|
+ this.initTagList();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ }
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss">
|
|
|
+ .tag {
|
|
|
+ display: flex;
|
|
|
+ flex-wrap: wrap;
|
|
|
+
|
|
|
+ .target-item {
|
|
|
+ display: flex;
|
|
|
+ height: 28px;
|
|
|
+ align-items: center;
|
|
|
+ margin: 5px 0;
|
|
|
+ margin-right: 15px;
|
|
|
+ background: #46577a;
|
|
|
+ border-radius: 15px;
|
|
|
+ padding: 0 15px;
|
|
|
+
|
|
|
+ .label {
|
|
|
+ font-size: 12px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .iconfont {
|
|
|
+ margin-left: 10px;
|
|
|
+ font-size: 12px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .huifont-bianji {
|
|
|
+ font-size: 18px;
|
|
|
+ }
|
|
|
+
|
|
|
+ &.active {
|
|
|
+ background: $--color-primary;
|
|
|
+ color: #fff;
|
|
|
+ }
|
|
|
+
|
|
|
+ &.add {
|
|
|
+ cursor: pointer;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .target-item-insert {
|
|
|
+ cursor: pointer;
|
|
|
+ background: transparent;
|
|
|
+ border: 1px solid #7383ad;
|
|
|
+ color: #7383ad;
|
|
|
+
|
|
|
+ .iconfont {
|
|
|
+ margin-left: 0;
|
|
|
+ margin-right: 10px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .target-item-insert:hover {
|
|
|
+ border-color: $--color-primary;
|
|
|
+ color: $--color-primary;
|
|
|
+ }
|
|
|
+ }
|
|
|
</style>
|