KeyConfig.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <div class="keywords">
  3. <div class="key-title">关键词设置 <span style="font-size:14px;"><em style="color: #2cb7ca;">{{keyCounts}}</em>/{{datas.maxKeyCounts}}</span></div>
  4. <div class="key-content">
  5. <div class="item">
  6. <div class="item-label">关键词分类:</div>
  7. <div class="item-value">
  8. <el-input class="custom-long-input" v-model.trim="cur.classify" maxlength="20" placeholder="请输入关键词分类"></el-input>
  9. </div>
  10. </div>
  11. <div class="item">
  12. <div class="item-label item-label-required">关键词:</div>
  13. <div class="item-value">
  14. <el-input class="custom-long-input" v-model.trim="cur.key" maxlength="20" placeholder="请输入关键词"></el-input>
  15. </div>
  16. </div>
  17. <div class="item">
  18. <div class="item-label"></div>
  19. <div class="item-value item-keywords-value">
  20. <div>
  21. <div class="add-word-list" v-for="(add,index) in cur.appendkey" :key="'add' + index">
  22. <el-input v-model.trim="cur.appendkey[index]" class="custom-short-input" maxlength="20" placeholder="请输入附加词"></el-input>
  23. </div>
  24. <div class="add-tag" @click="addAttachWordsFn">+添加附加词</div>
  25. </div>
  26. <div>
  27. <div class="add-word-list" v-for="(not,index) in cur.notkey" :key="'0' + index">
  28. <el-input v-model.trim="cur.notkey[index]" class="custom-short-input" maxlength="20" placeholder="请输入排除词"></el-input>
  29. </div>
  30. <div class="add-tag" @click="addExcludeWordsFn">+添加排除词</div>
  31. </div>
  32. </div>
  33. </div>
  34. <div class="item">
  35. <div class="item-label"></div>
  36. <div class="item-value">
  37. <button type="button" :disabled="keyDisabled" class="save-btn" @click="submitKeywords">保存关键词</button>
  38. <div class="keywords-help">
  39. <p>例:某公司主管业务为软件系统开发 </p>
  40. <p>关键词:目标信息钟的关键性词语,如“软件系统” </p>
  41. <p>附加词:与关键词形成一体/组合,便于查找准确信息,如“开发”</p>
  42. <p>排除词:与关键词互斥,可排除一部分非目标信息,如“运维”</p>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </template>
  49. <script>
  50. import { Input, Button } from 'element-ui'
  51. import { updateKey } from '@/api/modules/subscribe'
  52. export default {
  53. name: 'key-config',
  54. props: {
  55. datas: {
  56. keywordsList: Array,
  57. maxKeyCounts: Number
  58. }
  59. },
  60. components: {
  61. [Input.name]: Input,
  62. [Button.name]: Button
  63. },
  64. data () {
  65. return {
  66. cur: {
  67. classify: '',
  68. key: '',
  69. appendkey: [''],
  70. notkey: ['']
  71. },
  72. curArr: {
  73. a_key: [],
  74. s_item: ''
  75. }
  76. }
  77. },
  78. computed: {
  79. keyCounts () {
  80. let count = 0
  81. this.datas.keywordsList.forEach(v => {
  82. if (v && v.a_key) {
  83. count += v.a_key.length
  84. }
  85. })
  86. return count
  87. },
  88. keyDisabled () {
  89. return !this.cur.key
  90. }
  91. },
  92. mounted () {
  93. console.log(this.datas)
  94. },
  95. methods: {
  96. // 保存数据
  97. saveCurData () {
  98. let newData = []
  99. this.curArr.s_item = this.cur.classify
  100. this.curArr.a_key = [{
  101. appendkey: this.cur.appendkey,
  102. key: [this.cur.key],
  103. notkey: this.cur.notkey
  104. }]
  105. this.datas.keywordsList.push(this.curArr)
  106. newData = this.datas.keywordsList
  107. console.log(newData)
  108. return newData
  109. },
  110. // 提交关键词
  111. submitKeywords () {
  112. const classArr = this.getClassArray()
  113. const keyArr = this.getKeyTotalArray()
  114. if (classArr.indexOf(this.cur.classify) > -1) {
  115. return this.$message({
  116. type: 'warning',
  117. message: '分类名不能重复'
  118. })
  119. }
  120. if (keyArr.indexOf(this.cur.key) > -1) {
  121. return this.$message({
  122. type: 'warning',
  123. message: '关键词不能重复'
  124. })
  125. }
  126. const params = {
  127. a_items: this.saveCurData()
  128. }
  129. console.log(params, 'data')
  130. updateKey({
  131. a_items: params.a_items
  132. }).then((res) => {
  133. console.log(res)
  134. })
  135. },
  136. // 添加附加词
  137. addAttachWordsFn () {
  138. const arr = this.cur.appendkey
  139. if (this.inputIsEmpty(arr)) {
  140. this.$message({
  141. message: '请输入附加词',
  142. type: 'warning'
  143. })
  144. } else {
  145. this.cur.appendkey.push('')
  146. }
  147. },
  148. // 添加排除词
  149. addExcludeWordsFn () {
  150. const arr = this.cur.notkey
  151. if (this.inputIsEmpty(arr)) {
  152. this.$message({
  153. message: '请输入排除词',
  154. type: 'warning'
  155. })
  156. } else {
  157. this.cur.notkey.push('')
  158. }
  159. },
  160. // 判断附加词排除词输入框是否有空
  161. inputIsEmpty (arr) {
  162. return arr.some((v) => !v)
  163. },
  164. getClassArray () {
  165. const classArr = []
  166. this.datas.keywordsList.forEach((v) => {
  167. if (v.s_item) {
  168. classArr.push(v.s_item)
  169. }
  170. })
  171. return classArr
  172. },
  173. // 获取所有关键词的key的属性,并返回一个数组(主要用于判断添加关键词是否重复)
  174. getKeyTotalArray () {
  175. const keysArr = []
  176. this.datas.keywordsList.forEach((s) => {
  177. if (s && s.a_key && this.isArray(s.a_key)) {
  178. s.a_key.forEach((v) => {
  179. if (this.isArray(v.key)) {
  180. v.key.forEach(x => {
  181. keysArr.push(x)
  182. })
  183. } else {
  184. keysArr.push(v.key)
  185. }
  186. })
  187. }
  188. })
  189. return keysArr
  190. },
  191. // 判断变量是否是数组
  192. isArray (o) {
  193. return Object.prototype.toString.call(o) === '[object Array]'
  194. },
  195. groupListKeyArrToString (list, state) {
  196. let mList = JSON.parse(JSON.stringify(list))
  197. if (this.isArray(mList)) {
  198. mList.forEach((keyList) => {
  199. if (keyList && keyList.a_key && this.isArray(keyList.a_key)) {
  200. keyList.a_key.forEach((item) => {
  201. if (!state && this.isArray(item.key)) {
  202. // 数组拼接
  203. item.key = item.key.join(' ')
  204. } else if (state === 1) {
  205. // 字符串切割
  206. item.key = item.key.replace(/\s+/g, ' ').split(' ')
  207. } else {
  208. if (state) {
  209. console.error('关键词key,必须为字符串。并且state参数只有两种数值0和1')
  210. } else {
  211. console.error('关键词key,必须为数组')
  212. }
  213. }
  214. })
  215. }
  216. })
  217. } else {
  218. mList = []
  219. }
  220. console.log(mList)
  221. return mList
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .keywords{
  228. .key-title{
  229. padding-bottom: 8px;
  230. font-size: 18px;
  231. color: #1d1d1d;
  232. line-height: 28px;
  233. border-bottom: 1px solid #ececec;
  234. }
  235. .key-content{
  236. padding: 20px 0;
  237. .item{
  238. display: flex;
  239. align-items: center;
  240. justify-content: center;
  241. margin-bottom: 10px;
  242. }
  243. .item-label{
  244. margin-right: 8px;
  245. min-width: 120px;
  246. height: 40px;
  247. color: #1d1d1d;
  248. font-size: 14px;
  249. line-height: 40px;
  250. text-align: right;
  251. }
  252. .item-label-required:before{
  253. content: "*";
  254. color: #f56c6c;
  255. margin-right: 2px;
  256. }
  257. .item-value{
  258. width: 352px;
  259. }
  260. .custom-long-input{
  261. width: 352px;
  262. }
  263. .custom-short-input{
  264. width: 170px;
  265. }
  266. .item-other{
  267. display: flex;
  268. justify-content: center;
  269. margin-bottom: 10px;
  270. }
  271. .item-other-value{
  272. margin-top: 8px;
  273. }
  274. .math-tips{
  275. margin-top: 4px;
  276. font-size: 12px;
  277. color: #999999;
  278. line-height: 20px;
  279. }
  280. .radio-item{
  281. margin-bottom: 10px;
  282. }
  283. .item-keywords-value{
  284. display: flex;
  285. justify-content: space-between;
  286. }
  287. .add-tag{
  288. width: 170px;
  289. height: 40px;
  290. line-height: 40px;
  291. color: #2cb7ca;
  292. border-radius: 6px;
  293. text-align: center;
  294. cursor: pointer;
  295. color: #2cb7ca;
  296. border: 1px dashed #2cb7ca;
  297. }
  298. .add-word-list{
  299. margin-bottom: 6px;
  300. }
  301. .save-btn{
  302. width: 352px;
  303. height: 46px;
  304. line-height: 46px;
  305. font-size: 16px;
  306. background: #2cb7ca;
  307. border-radius: 6px;
  308. color: #fff;
  309. &:disabled{
  310. opacity: 0.5;
  311. cursor: not-allowed;
  312. }
  313. }
  314. .keywords-help{
  315. width: 412px;
  316. margin-top: 20px;
  317. font-size: 12px;
  318. color: #999999;
  319. line-height: 20px;
  320. text-align: justify;
  321. }
  322. }
  323. // element-ui样式修改
  324. ::v-deep.el-input__inner{
  325. font-size: 14px;
  326. color: #1D1D1D;
  327. border-color: #ececec;
  328. }
  329. ::v-deep.el-input__inner:hover{
  330. border-color: #ececec;
  331. }
  332. ::v-deep.el-input__inner:focus{
  333. border-color: #2cb7ca;
  334. }
  335. }
  336. </style>