cps_manage.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <template>
  2. <div>
  3. <el-tabs v-model="activeName" @tab-click="handleClick">
  4. <el-tab-pane name="tag">
  5. <span slot="label"><i class="el-icon-document-remove"></i> 标签</span>
  6. <!-- 头部操作模块 start -->
  7. <div style="width:200px;margin:0 15px;float:left;">
  8. <el-input v-model="tagName" placeholder="搜索标签" @keyup.enter.native="searchTag"></el-input>
  9. </div>
  10. <div style="width:200px;margin:0 15px;float:left;">
  11. <el-select v-model="category" clearable placeholder="全部领域">
  12. <el-option
  13. v-for="item in categoryOptions"
  14. :key="item.id"
  15. :label="item.name"
  16. :value="item.id">
  17. </el-option>
  18. </el-select>
  19. </div>
  20. <div style="width:100px;margin:0 15px;float:left;">
  21. <el-button type="primary" @click="searchTag">搜索</el-button>
  22. </div>
  23. <div style="margin:0 15px;float:right;">
  24. <el-button type="primary" @click="addTag"><i class="el-icon-plus"></i>新增标签</el-button>
  25. </div>
  26. <div style="clear: both;"></div>
  27. <!-- 头部操作模块 end -->
  28. <!-- 新增标签弹出层 start -->
  29. <el-dialog
  30. title="新增标签"
  31. :visible.sync="tagDialogVisible"
  32. width="30%">
  33. <el-form ref="form" :model="tagForm" label-width="100px">
  34. <el-form-item>
  35. <p slot="label">标签名<span style="color:red;">*</span></p>
  36. <el-input v-model="tagForm.name"></el-input>
  37. </el-form-item>
  38. <el-form-item label="标签别名">
  39. <el-select class="tag_aa"
  40. v-model="tagForm.aliases"
  41. multiple
  42. filterable
  43. allow-create
  44. default-first-option
  45. placeholder="请选择标签别名" style="width: 100%;">
  46. <el-option
  47. v-for="item in tagRelationOptions"
  48. :key="item.value"
  49. :label="item.label"
  50. :value="item.value" >
  51. </el-option>
  52. </el-select>
  53. </el-form-item>
  54. <el-form-item label="权重值">
  55. <el-input v-model="tagForm.weight"></el-input>
  56. </el-form-item>
  57. <el-form-item label="关联子标签">
  58. <el-select v-model="tagForm.subtags" remote multiple filterable :multiple-limit=5 reserve-keyword placeholder="请选择" style="width: 100%;">
  59. <el-option
  60. v-for="item in tagOption"
  61. :key="item.id"
  62. :label="item.name"
  63. :value="item.id">
  64. </el-option>
  65. </el-select>
  66. </el-form-item>
  67. <el-form-item>
  68. <el-button type="primary" @click="addTagSub">提交</el-button>
  69. </el-form-item>
  70. </el-form>
  71. </el-dialog>
  72. <el-dialog
  73. title="修改标签"
  74. :visible.sync="editTagDialogVisible"
  75. width="30%">
  76. <el-form ref="form" :model="tagForm" label-width="100px">
  77. <el-form-item>
  78. <p slot="label">标签名<span style="color:red;">*</span></p>
  79. <el-input v-model="tagForm.name" v-bind:readonly="isReadOnly"></el-input>
  80. </el-form-item>
  81. <el-form-item label="标签别名">
  82. <el-select class="tag_aa"
  83. v-model="tagForm.aliases"
  84. multiple
  85. filterable
  86. allow-create
  87. default-first-option
  88. placeholder="请选择标签别名" style="width: 100%;">
  89. <el-option
  90. v-for="item in tagRelationOptions"
  91. :key="item.value"
  92. :label="item.label"
  93. :value="item.value" >
  94. </el-option>
  95. </el-select>
  96. </el-form-item>
  97. <el-form-item label="权重值">
  98. <el-input v-model="tagForm.weight"></el-input>
  99. </el-form-item>
  100. <el-form-item label="关联子标签">
  101. <el-select v-model="tagForm.subtags" remote multiple filterable :multiple-limit=5 reserve-keyword placeholder="请选择" style="width: 100%;">
  102. <el-option
  103. v-for="item in tagOption"
  104. :key="item.id"
  105. :label="item.name"
  106. :value="item.id">
  107. </el-option>
  108. </el-select>
  109. </el-form-item>
  110. <el-form-item>
  111. <el-button type="primary" @click="editTagSub">提交</el-button>
  112. </el-form-item>
  113. </el-form>
  114. </el-dialog>
  115. <!-- 新增标签弹出层 end -->
  116. <!-- 标签表格数据 start -->
  117. <el-table
  118. :data="tagData">
  119. <el-table-column
  120. prop="name"
  121. label="标签名"
  122. width="180">
  123. </el-table-column>
  124. <el-table-column
  125. label="别名"
  126. width="280">
  127. <template slot-scope="scope">
  128. <template v-if="scope.row['aliases'] != null">
  129. <template v-for="item in scope.row['aliases']">
  130. <span style="margin-right: 8px">{{item}}</span>
  131. </template>
  132. </template>
  133. </template>
  134. </el-table-column>
  135. <el-table-column
  136. prop="weight"
  137. label="权重"
  138. width="180">
  139. </el-table-column>
  140. <el-table-column
  141. label="关联子标签">
  142. <template slot-scope="scope">
  143. <div v-if="scope.row['subtags'] && scope.row['subtags'].length">
  144. <el-tag v-for="(tagid, idx) in scope.row['subtags']" v-if="idx < 8">{{tag_map[tagid]}}</el-tag>
  145. <p>总共有{{scope.row['subtags'].length}}个</p>
  146. </div>
  147. </template>
  148. </el-table-column>
  149. <el-table-column
  150. label="关联领域">
  151. <template slot-scope="scope">
  152. {{scope.row['catIds'] && scope.row['catIds'].length ? scope.row['catIds'].map(id => cat_map[id]).join(', ') : '-'}}
  153. </template>
  154. </el-table-column>
  155. <el-table-column
  156. label="操作">
  157. <template slot-scope="scope">
  158. <el-button
  159. type="text"
  160. @click="editTag(scope.row)"
  161. ><i class="el-icon-edit"></i></el-button>
  162. <el-button
  163. type="text"
  164. @click="delTag(scope.row['id'])"
  165. ><i class="el-icon-delete"></i></el-button>
  166. </template>
  167. </el-table-column>
  168. </el-table>
  169. <!-- 标签表格数据 end -->
  170. </el-tab-pane>
  171. <el-tab-pane name="category">
  172. <span slot="label"><i class="el-icon-box"></i> 领域</span>
  173. <!-- 头部操作模块 start -->
  174. <div style="width:200px;margin:0 15px;float:left;">
  175. <el-input v-model="categoryName" placeholder="搜索领域" @keyup.enter.native="searchCat"></el-input>
  176. </div>
  177. <div style="width:250px;margin:0 15px;float:left;line-height: 40px;">
  178. <el-checkbox v-model="categoryChecked1">仅技术领域</el-checkbox>
  179. <el-checkbox v-model="categoryChecked2">仅行业领域</el-checkbox>
  180. </div>
  181. <div style="width:100px;margin:0 15px;float:left;">
  182. <el-button type="primary" @click="searchCat">搜索</el-button>
  183. </div>
  184. <div style="margin:0 15px;float:right;">
  185. <el-button type="primary" @click="addCategoryInit"><i class="el-icon-plus"></i>新增领域</el-button>
  186. </div>
  187. <div style="clear: both;"></div>
  188. <!-- 头部操作模块 end -->
  189. <!-- 领域表格数据 start -->
  190. <el-table
  191. :data="categoryData">
  192. <el-table-column
  193. prop="name"
  194. label="领域名"
  195. width="180">
  196. </el-table-column>
  197. <el-table-column
  198. prop="weight"
  199. label="权重"
  200. width="180">
  201. </el-table-column>
  202. <el-table-column
  203. label="技术领域"
  204. width="180">
  205. <template slot-scope="scope">
  206. <template v-if="scope.row['isTechnical'] == true">
  207. <p>是</p>
  208. </template>
  209. <template v-else>
  210. <p>否</p>
  211. </template>
  212. </template>
  213. </el-table-column>
  214. <el-table-column
  215. label="行业领域">
  216. <template slot-scope="scope">
  217. <template v-if="scope.row['isIndustrial'] == true">
  218. <p>是</p>
  219. </template>
  220. <template v-else>
  221. <p>否</p>
  222. </template>
  223. </template>
  224. </el-table-column>
  225. <el-table-column
  226. label="关联标签">
  227. <template slot-scope="scope">
  228. <div v-if="scope.row['tags'] && scope.row['tags'].length">
  229. <el-tag v-for="(tagid, idx) in scope.row['tags']" v-if="idx < 8">{{tag_map[tagid]}}</el-tag>
  230. <p>总共有{{scope.row['tags'].length}}个</p>
  231. </div>
  232. </template>
  233. </el-table-column>
  234. <el-table-column
  235. label="操作">
  236. <template slot-scope="scope">
  237. <el-button
  238. type="text"
  239. @click="editCat(scope.row)"
  240. ><i class="el-icon-edit"></i></el-button>
  241. <el-button
  242. type="text"
  243. @click="delCat(scope.row['id'])"
  244. ><i class="el-icon-delete"></i></el-button>
  245. </template>
  246. </el-table-column>
  247. </el-table>
  248. <!-- 领域表格数据 end -->
  249. <!-- 新增领域弹出层 start -->
  250. <el-dialog
  251. title="新增领域"
  252. :visible.sync="categoryDialogVisible"
  253. width="30%">
  254. <el-form ref="form" :model="catForm" label-width="100px">
  255. <el-form-item>
  256. <p slot="label">领域名<span style="color:red;">*</span></p>
  257. <el-input v-model="catForm.name"></el-input>
  258. </el-form-item>
  259. <el-form-item label="权重值">
  260. <el-input v-model="catForm.weight"></el-input>
  261. </el-form-item>
  262. <el-form-item label="领域归属">
  263. <el-checkbox v-model="catForm.isTechnical">仅技术领域</el-checkbox>
  264. <el-checkbox v-model="catForm.isIndustrial">仅行业领域</el-checkbox>
  265. </el-form-item>
  266. <el-form-item label="关联标签">
  267. <el-select v-model="catForm.tags" multiple filterable placeholder="请选择" style="width: 100%;">
  268. <el-option
  269. v-for="item in tagOption"
  270. :key="item.id"
  271. :label="item.name"
  272. :value="item.id">
  273. </el-option>
  274. </el-select>
  275. </el-form-item>
  276. <el-form-item>
  277. <el-button type="primary" @click="addCategory">提交</el-button>
  278. </el-form-item>
  279. </el-form>
  280. </el-dialog>
  281. <el-dialog
  282. title="编辑领域"
  283. :visible.sync="editCategoryDialogVisible"
  284. width="1300px">
  285. <el-form ref="form" :model="catForm" label-width="100px">
  286. <el-form-item>
  287. <p slot="label">领域名<span style="color:red;">*</span></p>
  288. <el-input v-model="catForm.name"></el-input>
  289. </el-form-item>
  290. <el-form-item label="权重值">
  291. <el-input v-model="catForm.weight"></el-input>
  292. </el-form-item>
  293. <el-form-item label="领域归属">
  294. <el-checkbox v-model="catForm.isTechnical">技术领域</el-checkbox>
  295. <el-checkbox v-model="catForm.isIndustrial">行业领域</el-checkbox>
  296. </el-form-item>
  297. <el-form-item label="关联标签">
  298. <el-select v-model="catForm.tags" multiple filterable placeholder="请选择" style="width: 100%;">
  299. <el-option
  300. v-for="item in tagOption"
  301. :key="item.id"
  302. :label="item.name"
  303. :value="item.id">
  304. </el-option>
  305. </el-select>
  306. </el-form-item>
  307. <el-form-item>
  308. <el-button type="primary" @click="editCategory">提交</el-button>
  309. </el-form-item>
  310. </el-form>
  311. </el-dialog>
  312. <!-- 新增领域弹出层 end -->
  313. </el-tab-pane>
  314. </el-tabs>
  315. <div style="position: absolute;right:30px;top:20px;">
  316. <el-link type="primary" @click="syncDictionary"><i class="el-icon-refresh"></i> 同步CPS词典</el-link>
  317. </div>
  318. </div>
  319. </template>
  320. <script>
  321. export default {
  322. data() {
  323. return {
  324. // activeName: 'tag',
  325. activeName: 'category',
  326. isReadOnly: true,
  327. tagData: [],//标签数据
  328. tagOption: [],//标签数据池
  329. tag_map: {},
  330. categoryData: [],//领域数据
  331. cat_map: {},
  332. tagName: '', //标签名称
  333. categoryOptions: [],//领域选项
  334. category:'',//领域选项值
  335. categoryName: '',//领域名称
  336. tagDialogVisible: false,//新增标签弹出层
  337. categoryDialogVisible: false,//新增领域弹出层
  338. editTagDialogVisible: false,//修改标签弹出层
  339. editCategoryDialogVisible: false,//修改领域弹出层
  340. tagForm: {weight:30},
  341. temp_data: {},
  342. catForm: {weight:50},
  343. form: {},
  344. categoryChecked1: false,
  345. categoryChecked2: false,
  346. tagRelationOptions: [],
  347. categoryRelationOptions: [],
  348. };
  349. },
  350. created: function () {
  351. this.getTableData()
  352. .catch(e => {
  353. this.$message({
  354. type: "error",
  355. message: e.message
  356. })
  357. });
  358. },
  359. methods: {
  360. // 获取列表数据
  361. async getTableData() {
  362. let tag_res = await this.$post("/api/admin/CpsManage/listTags", {});
  363. if(tag_res.status == 1){
  364. let map_i = {};
  365. this.tagData = tag_res.data;
  366. this.tagOption = tag_res.data;
  367. for(let t = 0; t < this.tagData.length; t++){
  368. map_i[this.tagData[t].id] = this.tagData[t].name;
  369. }
  370. this.tag_map = map_i;
  371. }
  372. let cat_res = await this.$post("/api/admin/CpsManage/listCategories", {});
  373. if(cat_res.status == 1){
  374. let map_ii = {};
  375. if(cat_res.data){
  376. this.categoryData = cat_res.data;
  377. this.categoryOptions = cat_res.data;
  378. for(let c = 0; c < this.categoryData.length; c++){
  379. map_ii[this.categoryData[c].id] = this.categoryData[c].name;
  380. }
  381. this.cat_map = map_ii;
  382. }
  383. }
  384. },
  385. //同步
  386. async syncDictionary(){
  387. let res = await this.$post("/api/admin/CpsManage/syncDictionary", {});
  388. if(res.status == 1){
  389. this.$message({
  390. type: "success",
  391. message: "同步成功!"
  392. });
  393. }
  394. },
  395. //标签搜索
  396. async searchTag(){
  397. this.tagData = this.tagOption.filter(this.searchTagRes);
  398. },
  399. searchTagRes(item){
  400. let q = this.tagName.toLowerCase();
  401. let cat_id = this.category;
  402. let res_i = true, res_ii = true;
  403. if(q){
  404. let name = item.name.toLowerCase();
  405. res_i = (name.search(q) > -1);
  406. }
  407. if(cat_id){
  408. res_ii = (item.catIds && item.catIds.indexOf(cat_id) > -1);
  409. }
  410. return (res_i && res_ii);
  411. },
  412. handleClick(tab, event) {
  413. },
  414. //领域搜索
  415. async searchCat(){
  416. this.categoryData = this.categoryOptions.filter(this.search);
  417. },
  418. search(item){
  419. let q = this.categoryName.toLowerCase();
  420. let res_i = true, res_ii = true, res_iii = true;
  421. if(q){
  422. let name = item.name.toLowerCase();
  423. res_i = (name.search(q) > -1);
  424. }
  425. if(this.categoryChecked1){
  426. res_ii = (item.isTechnical === true);
  427. }
  428. if(this.categoryChecked2){
  429. res_iii = (item.isIndustrial === true);
  430. }
  431. return (res_i && res_ii && res_iii);
  432. },
  433. editTag(rowInfo){
  434. this.editTagDialogVisible = true;
  435. this.temp_data = rowInfo;
  436. let info_str = JSON.stringify(rowInfo);
  437. this.tagForm = JSON.parse(info_str);
  438. },
  439. editTagSub(){
  440. let data = {
  441. id: this.tagForm.id,
  442. weight: this.tagForm.weight,
  443. aliases: this.tagForm.aliases,
  444. subtags: this.tagForm.subtags,
  445. };
  446. let res = this.$post("/api/admin/CpsManage/UpdateTag", data).then(res => {
  447. if (res.status === 1) {
  448. this.$message({
  449. type: "success",
  450. message: "修改成功!"
  451. });
  452. this.temp_data.weight = data.weight;
  453. this.temp_data.aliases = data.aliases;
  454. this.temp_data.subtags = data.subtags;
  455. }else{
  456. this.$message({
  457. type: "error",
  458. message: "修改失败!"
  459. });
  460. }
  461. this.tagForm = {};
  462. this.editTagDialogVisible = false;
  463. });
  464. },
  465. addTag(){
  466. this.tagDialogVisible= true;
  467. this.tagForm.weight=30;
  468. },
  469. addTagSub(){
  470. let data = {
  471. name: this.tagForm.name,
  472. weight: this.tagForm.weight,
  473. aliases: this.tagForm.aliases,
  474. subtags: this.tagForm.subtags,
  475. };
  476. let res = this.$post("/api/admin/CpsManage/CreateTag", data).then(res => {
  477. if (res.status === 1) {
  478. this.$message({
  479. type: "success",
  480. message: "新增成功!"
  481. });
  482. this.tagForm = {};
  483. this.tagDialogVisible = false;
  484. this.tagOption.unshift(res.data);
  485. this.tagData = this.tagOption;
  486. }else{
  487. this.$message({
  488. type: "error",
  489. message: "新增失败!"
  490. });
  491. this.tagForm = {};
  492. this.tagDialogVisible = false;
  493. }
  494. });
  495. },
  496. delTag(id){
  497. this.$confirm('此操作将永久删除该标签, 是否继续?', '提示', {
  498. confirmButtonText: '确定',
  499. cancelButtonText: '取消',
  500. type: 'warning'
  501. }).then(() => {
  502. let data = {
  503. id: id
  504. };
  505. let res = this.$post("/api/admin/CpsManage/DeleteTag", data).then(res => {
  506. if (res.status === 1) {
  507. this.$message({
  508. type: "success",
  509. message: "删除成功!"
  510. });
  511. for(let i = 0; i < this.tagData.length; i++) {
  512. if (this.tagOption[i]['id'] == id) {
  513. this.tagOption.splice(i, 1);
  514. continue;
  515. }
  516. }
  517. this.tagData = this.tagOption;
  518. }else{
  519. this.$message({
  520. type: "error",
  521. message: "删除失败!"
  522. });
  523. }
  524. });
  525. }).catch(() => {
  526. });
  527. },
  528. addCategoryInit(){
  529. this.categoryDialogVisible = true;
  530. this.catForm.weight = 50;
  531. },
  532. addCategory(){
  533. let data = {
  534. name: this.catForm.name,
  535. weight: this.catForm.weight,
  536. tags: this.catForm.tags,
  537. isTechnical: this.catForm.isTechnical,
  538. isIndustrial: this.catForm.isIndustrial
  539. };
  540. let res = this.$post("/api/admin/CpsManage/CreateCategory", data).then(res => {
  541. if (res.status === 1) {
  542. this.$message({
  543. type: "success",
  544. message: "新增成功!"
  545. });
  546. this.catForm = {};
  547. this.categoryDialogVisible = false;
  548. this.categoryOptions.unshift(res.data);
  549. }else{
  550. this.$message({
  551. type: "error",
  552. message: "新增失败!"
  553. });
  554. this.catForm = {};
  555. this.categoryDialogVisible = false;
  556. }
  557. });
  558. },
  559. editCat(rowInfo){
  560. this.editCategoryDialogVisible = true;
  561. this.temp_data = rowInfo;
  562. let info_str = JSON.stringify(rowInfo);
  563. this.catForm = JSON.parse(info_str);
  564. },
  565. editCategory(){
  566. let data = {
  567. id: this.catForm.id,
  568. name: this.catForm.name,
  569. weight: this.catForm.weight,
  570. tags: this.catForm.tags,
  571. isTechnical: this.catForm.isTechnical,
  572. isIndustrial: this.catForm.isIndustrial
  573. };
  574. let res = this.$post("/api/admin/CpsManage/UpdateCategory", data).then(res => {
  575. if (res.status === 1) {
  576. this.$message({
  577. type: "success",
  578. message: "编辑成功!"
  579. });
  580. this.temp_data.name = data.name;
  581. this.temp_data.weight = data.weight;
  582. this.temp_data.tags = data.tags;
  583. this.temp_data.isTechnical = data.isTechnical;
  584. this.temp_data.isIndustrial = data.isIndustrial;
  585. this.catForm = {};
  586. this.editCategoryDialogVisible = false;
  587. }else{
  588. this.$message({
  589. type: "error",
  590. message: "编辑失败!"
  591. });
  592. this.catForm = {};
  593. this.editCategoryDialogVisible = false;
  594. }
  595. });
  596. }
  597. ,delCat(id){
  598. this.$confirm('此操作将永久删除该领域, 是否继续?', '提示', {
  599. confirmButtonText: '确定',
  600. cancelButtonText: '取消',
  601. type: 'warning'
  602. }).then(() => {
  603. let data = {
  604. id: id
  605. };
  606. let res = this.$post("/api/admin/CpsManage/DeleteCategory", data).then(res => {
  607. if (res.status === 1) {
  608. this.$message({
  609. type: "success",
  610. message: "删除成功!"
  611. });
  612. for(let i = 0; i < this.categoryData.length; i++){
  613. if(this.categoryData[i]['id'] == id){
  614. this.categoryData.splice(i, 1);
  615. continue;
  616. }
  617. }
  618. }else{
  619. this.$message({
  620. type: "error",
  621. message: "删除失败!"
  622. });
  623. }
  624. });
  625. }).catch(() => {
  626. });
  627. }
  628. }
  629. };
  630. </script>