|
@@ -1,80 +1,359 @@
|
|
|
<template>
|
|
|
<div class="classify">
|
|
|
- <div class="classify-list" v-for="(item,index) in getList" :key="'1' + index">
|
|
|
+ <div class="classify-list" v-for="(item,index) in list" :key="'1' + index">
|
|
|
<div class="classify-title">
|
|
|
<span class="title-text">{{item.s_item}}</span>
|
|
|
- <span class="icon-edit"></span>
|
|
|
- <span class="icon-delete"></span>
|
|
|
+ <span class="icon-edit" @click="editClassFn(item.s_item, index)"></span>
|
|
|
+ <span class="icon-delete" @click="deleteClassFn(item.s_item, index)"></span>
|
|
|
</div>
|
|
|
<div class="classify-content">
|
|
|
- <div class="list" v-for="(v,i) in item.a_key" :key="'2' + i">
|
|
|
+ <div class="list" v-for="(v, i) in item.a_key" :key="'2' + i">
|
|
|
<div class="list-box">
|
|
|
<div class="list-value">
|
|
|
- <p>关键词: {{v.key || '--'}}</p>
|
|
|
- <p>附加词: {{v.appendkey || '--'}}</p>
|
|
|
- <p>排除词: {{v.notkey || '--'}}</p>
|
|
|
+ <p>关键词: {{v.key.join(' ') || '--'}}</p>
|
|
|
+ <p>附加词: {{v.appendkey.join('、') || '--'}}</p>
|
|
|
+ <p>排除词: {{v.notkey.join('、') || '--'}}</p>
|
|
|
</div>
|
|
|
- <div class="list-icon"></div>
|
|
|
- <div class="list-edit" @click="editHandle(v)">
|
|
|
+ <div class="list-icon" @click="deleteKeyFn(index, i)"></div>
|
|
|
+ <div class="list-edit" @click="editKeyFn(item, v, index, i)">
|
|
|
编辑
|
|
|
<i class="tri-down"></i>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <div class="words-add">
|
|
|
+ <div class="words-add" @click="addKeyFn(item.s_item)">
|
|
|
<i class="el-icon-plus"></i>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
+ <!-- 修改分类dialog -->
|
|
|
+ <el-dialog
|
|
|
+ custom-class="sub-dialog"
|
|
|
+ :visible.sync="dialog.editClass"
|
|
|
+ :close-on-click-modal="false"
|
|
|
+ :show-close="false"
|
|
|
+ center
|
|
|
+ width="800px"
|
|
|
+ v-if="dialog.editClass"
|
|
|
+ >
|
|
|
+ <KeyCard @onCancel="dialog.editClass = false" @onConfirm="confirmEditClassFn">
|
|
|
+ <div slot="header">修改关键词分类</div>
|
|
|
+ <div class="class-edit-content">
|
|
|
+ <div class="item">
|
|
|
+ <div class="item-label">关键词分类:</div>
|
|
|
+ <div class="item-value">
|
|
|
+ <el-input class="custom-long-input" v-model.trim="props.className" maxlength="20" placeholder="请输入关键词分类"></el-input>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </KeyCard>
|
|
|
+ </el-dialog>
|
|
|
+ <!-- 删除分类dialog -->
|
|
|
+ <el-dialog
|
|
|
+ custom-class="sub-dialog small-dialog"
|
|
|
+ :visible.sync="dialog.delClass"
|
|
|
+ :close-on-click-modal="false"
|
|
|
+ :show-close="false"
|
|
|
+ center
|
|
|
+ top="30vh"
|
|
|
+ width="380px"
|
|
|
+ v-if="dialog.delClass"
|
|
|
+ >
|
|
|
+ <div class="delete-class">
|
|
|
+ <div class="delete-class-header">删除关键词分类</div>
|
|
|
+ <div class="delete-class-content">{{props.className}}</div>
|
|
|
+ <div class="delete-class-footer">
|
|
|
+ <el-button type="primary" class="confirm" @click="confirmDeleteClassFn">删除</el-button>
|
|
|
+ <el-button class="cancel" @click="dialog.delClass = false">取消</el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
+ <!-- 关键词dialog -->
|
|
|
+ <el-dialog
|
|
|
+ custom-class="sub-dialog"
|
|
|
+ :visible.sync="dialog.editKey"
|
|
|
+ :close-on-click-modal="false"
|
|
|
+ :show-close="false"
|
|
|
+ center
|
|
|
+ width="800px"
|
|
|
+ v-if="dialog.editKey"
|
|
|
+ >
|
|
|
+ <KeyCard @onCancel="dialog.editKey = false" @onConfirm="submitKeywords">
|
|
|
+ <div slot="header">修改关键词</div>
|
|
|
+ <div class="key-edit-content">
|
|
|
+ <KeyEdit ref="keyEditRef" :datas="props"></KeyEdit>
|
|
|
+ </div>
|
|
|
+ </KeyCard>
|
|
|
+ </el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
-import { Tooltip } from 'element-ui'
|
|
|
+import { Tooltip, Dialog, Input, Button } from 'element-ui'
|
|
|
+import KeyCard from '@/components/selector/SelectorCard'
|
|
|
+import KeyEdit from './KeyEdit'
|
|
|
export default {
|
|
|
name: 'keywords-list',
|
|
|
components: {
|
|
|
- [Tooltip.name]: Tooltip
|
|
|
+ [Tooltip.name]: Tooltip,
|
|
|
+ [Dialog.name]: Dialog,
|
|
|
+ [Input.name]: Input,
|
|
|
+ [Button.name]: Button,
|
|
|
+ KeyCard,
|
|
|
+ KeyEdit
|
|
|
},
|
|
|
- props: ['list'],
|
|
|
- data () {
|
|
|
- return {}
|
|
|
+ props: {
|
|
|
+ list: Array
|
|
|
},
|
|
|
- computed: {
|
|
|
- getList () {
|
|
|
- const newArr = this.list
|
|
|
- newArr.forEach((v) => {
|
|
|
- if (v.a_key) {
|
|
|
- v.a_key.forEach((s) => {
|
|
|
- if (this.isArray(s.key)) {
|
|
|
- s.key = s.key.join('、')
|
|
|
- }
|
|
|
- if (this.isArray(s.appendkey)) {
|
|
|
- s.appendkey = s.appendkey.join('、')
|
|
|
- }
|
|
|
- if (this.isArray(s.notkey)) {
|
|
|
- s.notkey = s.notkey.join('、')
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- return newArr
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ dialog: {
|
|
|
+ editClass: false, // 修改分类弹框
|
|
|
+ delClass: false, // 删除分类弹框
|
|
|
+ editKey: false // 修改关键词弹框
|
|
|
+ },
|
|
|
+ // 传给dialog子组件的数据
|
|
|
+ props: {
|
|
|
+ ways: '', // 编辑还是新增
|
|
|
+ classIndex: null, // 分类下标
|
|
|
+ className: '', // 分类名
|
|
|
+ keyIndex: null, // 关键词下标
|
|
|
+ key: [], // 关键词
|
|
|
+ notkey: [], // 排除词
|
|
|
+ appendkey: [] // 附加词
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
- mounted () {},
|
|
|
+ computed: {},
|
|
|
+ mounted () {
|
|
|
+ console.log(this.list, 'list')
|
|
|
+ },
|
|
|
methods: {
|
|
|
- editHandle (item) {
|
|
|
- this.$emit('openKeyDialog', {
|
|
|
- showDialog: true,
|
|
|
- data: item
|
|
|
+ // 打开修改关键词分类弹框
|
|
|
+ editClassFn (name, index) {
|
|
|
+ this.dialog.editClass = true
|
|
|
+ this.props.className = name
|
|
|
+ this.props.classIndex = index
|
|
|
+ },
|
|
|
+ // 确认修改分类
|
|
|
+ confirmEditClassFn () {
|
|
|
+ this.list.forEach((v, i) => {
|
|
|
+ if (this.props.classIndex === i) {
|
|
|
+ v.s_item = this.props.className
|
|
|
+ }
|
|
|
})
|
|
|
+ this.$emit('updateKey', this.list)
|
|
|
+ this.dialog.editClass = false
|
|
|
+ },
|
|
|
+ // 打开删除关键词分类弹框
|
|
|
+ deleteClassFn (name, index) {
|
|
|
+ this.props.classIndex = null
|
|
|
+ this.dialog.delClass = true
|
|
|
+ this.props.className = name
|
|
|
+ this.props.classIndex = index
|
|
|
+ },
|
|
|
+ // 确认删除分类
|
|
|
+ confirmDeleteClassFn () {
|
|
|
+ this.dialog.delClass = false
|
|
|
+ // 删除整个分类的数据
|
|
|
+ this.list.splice(this.props.classIndex, 1)
|
|
|
+ this.$emit('updateKey', this.list)
|
|
|
+ },
|
|
|
+ // 添加关键词
|
|
|
+ addKeyFn (name) {
|
|
|
+ this.dialog.editKey = true
|
|
|
+ this.props.ways = 'add'
|
|
|
+ this.props.className = name
|
|
|
+ this.props.key = []
|
|
|
+ this.props.notkey = []
|
|
|
+ this.props.appendkey = []
|
|
|
+ },
|
|
|
+ // 删除单个关键词
|
|
|
+ deleteKeyFn (index, i) {
|
|
|
+ console.log(index, i)
|
|
|
+ if (!this.list) return
|
|
|
+ this.list[index].a_key.splice(i, 1)
|
|
|
+ this.$emit('updateKey', this.list)
|
|
|
+ },
|
|
|
+ // 编辑单个关键词
|
|
|
+ editKeyFn (item, v, index, i) {
|
|
|
+ // index 分类下标 i 关键词下标
|
|
|
+ this.clearPropsData()
|
|
|
+ this.props.ways = 'edit'
|
|
|
+ this.dialog.editKey = true
|
|
|
+ // 把当前关键词传到dialog key,notkey,appendKey都为数组
|
|
|
+ this.props.className = item.s_item
|
|
|
+ this.props.key = v.key
|
|
|
+ this.props.notkey = v.notkey
|
|
|
+ this.props.appendkey = v.appendkey
|
|
|
+ this.props.keyIndex = i
|
|
|
+ this.props.classIndex = index
|
|
|
+ console.log(i)
|
|
|
+ },
|
|
|
+ // 清空传值
|
|
|
+ clearPropsData () {
|
|
|
+ this.props.className = ''
|
|
|
+ this.props.classIndex = null,
|
|
|
+ this.props.key = []
|
|
|
+ this.props.notkey = []
|
|
|
+ this.props.appendkey = []
|
|
|
+ },
|
|
|
+ // 修改关键词dialog 保存数据
|
|
|
+ submitKeywords () {
|
|
|
+ const data = this.list
|
|
|
+ const refs = this.$refs.keyEditRef.cur
|
|
|
+ const keyArr = this.getKeyTotalArray()
|
|
|
+ const type = this.props.ways
|
|
|
+ let obj = {
|
|
|
+ key: refs.key.split(' '),
|
|
|
+ notkey: refs.notkey,
|
|
|
+ appendkey: refs.appendkey
|
|
|
+ }
|
|
|
+ if (type === 'add') {
|
|
|
+ if (keyArr.indexOf(refs.key) > -1) {
|
|
|
+ return this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: '关键词不能重复'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ data.forEach((v) => {
|
|
|
+ if (v.s_item === this.props.className){
|
|
|
+ v.a_key.push(obj)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else if (type === 'edit') {
|
|
|
+ console.log(this.props.classIndex, this.props.keyIndex)
|
|
|
+ if (!data[this.props.classIndex].a_key) return
|
|
|
+ data[this.props.classIndex].a_key.splice(this.props.keyIndex, 1)
|
|
|
+ data.forEach((v) => {
|
|
|
+ if (v.s_item === this.props.className){
|
|
|
+ v.a_key.push(obj)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ console.log(data, 'data')
|
|
|
+ // 通知父组件发请求修改并更新
|
|
|
+ this.$emit('updateKey', data)
|
|
|
+ this.dialog.editKey = false
|
|
|
},
|
|
|
- isArray (o) {
|
|
|
- return Object.prototype.toString.call(o) === '[object Array]'
|
|
|
+ // 获取所有关键词的key的属性,并返回一个数组(主要用于判断添加关键词是否重复)
|
|
|
+ getKeyTotalArray () {
|
|
|
+ const keysArr = []
|
|
|
+ this.list.forEach((s) => {
|
|
|
+ if (s && s.a_key && Array.isArray(s.a_key)) {
|
|
|
+ s.a_key.forEach((v) => {
|
|
|
+ if (Array.isArray(v.key)) {
|
|
|
+ v.key.forEach(x => {
|
|
|
+ keysArr.push(x)
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ keysArr.push(v.key)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return keysArr
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
<style lang="scss" scoped>
|
|
|
+// dialog 自定义class样式
|
|
|
+.sub-dialog{
|
|
|
+ border-radius: 8px;
|
|
|
+ .selector-card{
|
|
|
+ width: 800px;
|
|
|
+ height: auto;
|
|
|
+ }
|
|
|
+ .key-edit-content,.class-edit-content{
|
|
|
+ width: 740px;
|
|
|
+ padding: 30px 0;
|
|
|
+ height: auto;
|
|
|
+ max-height: 340px;
|
|
|
+ margin: 0 auto;
|
|
|
+ border: 1px solid #ececec;
|
|
|
+ overflow-y: scroll;
|
|
|
+ box-sizing: border-box;
|
|
|
+ }
|
|
|
+ .item{
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ margin-bottom: 10px;
|
|
|
+ }
|
|
|
+ .item-label{
|
|
|
+ margin-right: 8px;
|
|
|
+ min-width: 120px;
|
|
|
+ height: 40px;
|
|
|
+ color: #1d1d1d;
|
|
|
+ font-size: 14px;
|
|
|
+ line-height: 40px;
|
|
|
+ text-align: right;
|
|
|
+ }
|
|
|
+ .item-label-required:before{
|
|
|
+ content: "*";
|
|
|
+ color: #f56c6c;
|
|
|
+ margin-right: 2px;
|
|
|
+ }
|
|
|
+ .item-value{
|
|
|
+ width: 352px;
|
|
|
+ }
|
|
|
+ .custom-long-input{
|
|
|
+ width: 352px;
|
|
|
+ }
|
|
|
+ .custom-short-input{
|
|
|
+ width: 170px;
|
|
|
+ }
|
|
|
+ .delete-class{
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ align-items: center;
|
|
|
+ padding: 32px 32px 42px;
|
|
|
+ background: #FFFFFF;
|
|
|
+ border-radius: 6px;
|
|
|
+ .delete-class-header{
|
|
|
+ font-size: 18px;
|
|
|
+ line-height: 28px;
|
|
|
+ color: #1D1D1D;
|
|
|
+ }
|
|
|
+ .delete-class-content{
|
|
|
+ padding: 20px 0 42px;
|
|
|
+ color: #686868;
|
|
|
+ font-size: 14px;
|
|
|
+ line-height: 22px;
|
|
|
+ }
|
|
|
+ .delete-class-footer{
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ .confirm,
|
|
|
+ .cancel {
|
|
|
+ padding: 10px 50px;
|
|
|
+ margin: 0 20px;
|
|
|
+ }
|
|
|
+ ::v-deep {
|
|
|
+ .el-button--primary {
|
|
|
+ color: #2cb7ca;
|
|
|
+ background: none;
|
|
|
+ border-color: #2cb7ca;
|
|
|
+ &:hover {
|
|
|
+ color: #fff;
|
|
|
+ background-color: #2cb7ca;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .el-button--default {
|
|
|
+ &:hover,
|
|
|
+ &:active {
|
|
|
+ color: #2cb7ca;
|
|
|
+ border-color: #2cb7ca;
|
|
|
+ background: #eaf8fa;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+.sub-dialog.small-dialog::v-deep.el-dialog{
|
|
|
+ border-radius: 8px!important;
|
|
|
+}
|
|
|
.classify-list{
|
|
|
margin-bottom: 30px;
|
|
|
.classify-title{
|