labelManage.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <script setup>
  2. import { reactive, ref, watch, computed, nextTick } from 'vue'
  3. import { ElMessage, ElMessageBox } from 'element-plus'
  4. import { Search } from '@element-plus/icons-vue'
  5. import {labelTableColumn} from './config/tableColumn'
  6. import {TagInterface} from '@/api/modules/trainingApi'
  7. import _ from 'lodash'
  8. /* table */
  9. const tableLoading = ref(false)
  10. let tableData = ref([])
  11. const tableColumn = labelTableColumn
  12. const tableParams = reactive({
  13. searchText:'',
  14. /* table-page */
  15. currentPage:1,
  16. pageSize:10,
  17. total:0,
  18. })
  19. function getTableData(){
  20. tableLoading.value = true
  21. TagInterface.getTagList({
  22. PageSize:tableParams.pageSize,
  23. CurrentIndex:tableParams.currentPage,
  24. Keyword:tableParams.searchText
  25. }).then(res=>{
  26. tableLoading.value = false
  27. if(res.Ret!==200) return
  28. if(!res.Data){
  29. tableData.value = []
  30. tableParams.total = 0
  31. return
  32. }
  33. tableData.value = res.Data.List||[]
  34. tableParams.total = res.Data.Paging.Totals
  35. })
  36. }
  37. getTableData()
  38. function handleCurrentChange(page){
  39. tableParams.currentPage = page
  40. getTableData()
  41. }
  42. /* modify label */
  43. let currentLabel = ref({})
  44. let isModifyDialogShow = ref(false)
  45. function handleModifyLabel(data){
  46. currentLabel.value = _.cloneDeep(data)
  47. isModifyDialogShow.value = true
  48. }
  49. async function modifyLabel(){
  50. const {TagId,TagName} = currentLabel.value
  51. if(!TagName){
  52. ElMessage.warning("请输入标签名称")
  53. return
  54. }
  55. if(TagName.length>5){
  56. ElMessage.warning("标签名称过长,请重新编辑")
  57. return
  58. }
  59. let res = null
  60. if(TagId){
  61. //edit
  62. res = await TagInterface.editTag({TagId,TagName})
  63. }else{
  64. //add
  65. res = await TagInterface.addTag({TagName})
  66. }
  67. if(res.Ret!==200) return
  68. //添加/编辑成功
  69. ElMessage.success(`${TagId?'编辑':'添加'}成功`)
  70. handleCurrentChange(1)
  71. isModifyDialogShow.value = false
  72. }
  73. function deleteLabel(label){
  74. if(label.VideoTotal!==0){
  75. ElMessageBox.confirm('该标签已关联视频,删除失败','提示',{confirmButtonText:'知道了',showCancelButton:false,type:'error'})
  76. return
  77. }
  78. ElMessageBox.confirm(
  79. '删除后不可恢复,是否确认删除该标签?',
  80. '提示',
  81. {
  82. confirmButtonText: '确定',
  83. cancelButtonText: '取消',
  84. type: 'warning',
  85. }
  86. ).then(()=>{
  87. TagInterface.deleteTag({
  88. TagId:label.TagId
  89. }).then(res=>{
  90. if(res.Ret!==200) return
  91. ElMessage.success('删除成功')
  92. handleCurrentChange(1)
  93. })
  94. }).catch(()=>{}).finally(()=>{})
  95. }
  96. </script>
  97. <template>
  98. <!-- 培训管理-标签管理 -->
  99. <div class="label-manage-wrap traing-manage">
  100. <div class="top-wrap">
  101. <el-button type="primary" @click="handleModifyLabel({})">新增标签</el-button>
  102. <el-input v-model="tableParams.searchText" clearable
  103. :prefix-icon="Search" placeholder="请输入标签名称" @input="handleCurrentChange(1)"
  104. style="width:240px;"></el-input>
  105. </div>
  106. <div class="table-wrap">
  107. <el-table :data="tableData" border v-loading="tableLoading">
  108. <el-table-column v-for="column in tableColumn" :key="column.key"
  109. :label="column.label" align="center"
  110. :prop="column.key"
  111. :min-width="column.minWidth">
  112. </el-table-column>
  113. <el-table-column label="操作" align="center">
  114. <template #default="{row}">
  115. <el-link :underline="false" type="primary" style="margin-right: 20px;" @click="handleModifyLabel(row)">编辑</el-link>
  116. <el-link :underline="false" type="danger" @click="deleteLabel(row)" style="color:red;">删除</el-link>
  117. </template>
  118. </el-table-column>
  119. </el-table>
  120. <el-pagination
  121. layout="total,prev,pager,next,jumper"
  122. background
  123. :current-page="tableParams.currentPage"
  124. @current-change="handleCurrentChange"
  125. :page-size="tableParams.pageSize"
  126. :total="tableParams.total"
  127. style="margin-top: 60px;justify-content: flex-end;">
  128. </el-pagination>
  129. </div>
  130. <!-- 添加标签弹窗 -->
  131. <el-dialog
  132. :title="currentLabel.TagId?'编辑标签':'添加标签'"
  133. v-model="isModifyDialogShow"
  134. :close-on-click-modal="false"
  135. :modal-append-to-body="false"
  136. @close="isModifyDialogShow=false"
  137. width="589px"
  138. center
  139. >
  140. <div class="dialog-container">
  141. <div class="input-item">
  142. <el-input placeholder="请输入标签名称" v-model.trim="currentLabel.TagName" required ></el-input>
  143. </div>
  144. <p class="form-hint">注:名称不得超过5个字</p>
  145. </div>
  146. <div class="foot-container">
  147. <el-button @click="isModifyDialogShow=false">取 消</el-button>
  148. <el-button type="primary" @click="modifyLabel">确认</el-button>
  149. </div>
  150. </el-dialog>
  151. </div>
  152. </template>
  153. <style scoped lang="scss">
  154. @import "./css/manage.scss";
  155. </style>