SortNodeDialog.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <!-- 调整节点排序 -->
  3. <HcDialog :show="nodeSortModel" title="调整排序" widths="80vw" is-table is-row-footer @close="nodeSortModalClose">
  4. <el-alert title="可拖动排序,也可在后面点击图标,切换排序" type="warning" :closable="false" />
  5. <div class="hc-table-h">
  6. <HcTable
  7. ui="hc-table-row-drop" is-row-drop quick-sort is-new :index-style="{ width: 60 }"
  8. :column="nodeSortTableColumn" :datas="nodeSortTableData" :loading="nodeSortTableLoading"
  9. @row-drop="nodeSortTableRowDrop" @row-sort="nodeSortTableRowDrop"
  10. >
  11. <template #key2="{ row }">
  12. <span class="text-link">{{ row?.key2 }}</span>
  13. </template>
  14. <template #action="{ index }">
  15. <span class="text-link text-xl" @click="nodeUpSortClick(index)">
  16. <HcIcon name="arrow-up" fill />
  17. </span>
  18. <span class="text-link text-xl ml-2" @click="nodeDownSortClick(index)">
  19. <HcIcon name="arrow-down" fill />
  20. </span>
  21. </template>
  22. </HcTable>
  23. </div>
  24. <template #rightRowFooter>
  25. <el-button hc-btn @click="nodeSortModalClose">
  26. <HcIcon name="close" />
  27. <span>取消</span>
  28. </el-button>
  29. <el-button type="primary" hc-btn :loading="nodeSortModalLoading" @click="nodeSortModalSave">
  30. <HcIcon name="check" />
  31. <span>确认</span>
  32. </el-button>
  33. </template>
  34. </HcDialog>
  35. </template>
  36. <script setup>
  37. import { nextTick, ref, toRefs, watch } from 'vue'
  38. import { submitArchiveTreeSort } from '~api/other'
  39. //参数
  40. const props = defineProps({
  41. projectId: {
  42. type: [String, Number],
  43. default: '',
  44. },
  45. contractId: {
  46. type: [String, Number],
  47. default: '',
  48. },
  49. node: {
  50. type: Object,
  51. default: () => ({}),
  52. },
  53. show:{
  54. type:Boolean,
  55. default:false,
  56. },
  57. })
  58. //事件
  59. const emit = defineEmits(['hide'])
  60. const projectId = ref(props.projectId)
  61. const contractId = ref(props.contractId)
  62. // 使用toRefs结构,使其具有响应式
  63. const { node } = toRefs(props)
  64. //监听
  65. watch(() => [
  66. props.projectId,
  67. props.contractId,
  68. ], ([UserProjectId, UserContractId]) => {
  69. projectId.value = UserProjectId
  70. contractId.value = UserContractId
  71. })
  72. watch(() => [props.show], ([newShow])=>{
  73. if (newShow) {
  74. sortNodeMoadl()
  75. } else {
  76. nodeSortModalClose()
  77. }
  78. })
  79. //节点排序
  80. const nodeSortModel = ref(false)
  81. const nodeSortTableColumn = ref([
  82. { key:'title', name: '节点名称' },
  83. { key:'action', name: '排序', width: 90 },
  84. ])
  85. const nodeSortTableData = ref([])
  86. const nodeSortTableLoading = ref(false)
  87. const nodeSortModalLoading = ref(false)
  88. const nodeSortModalClose = () =>{
  89. emit('hide', {})
  90. nodeSortModel.value = false
  91. }
  92. const nodeSortTableRowDrop = (rows)=>{
  93. nodeSortTableData.value = [] // 先清空,否则排序会异常
  94. nextTick(() => {
  95. nodeSortTableData.value = rows
  96. })
  97. }
  98. //向下
  99. const nodeDownSortClick = (index) => {
  100. const indexs = index + 1
  101. const data = nodeSortTableData.value
  102. if (indexs !== data.length) {
  103. const tmp = data.splice(indexs, 1)
  104. nodeSortTableData.value.splice(index, 0, tmp[0])
  105. } else {
  106. window?.$message?.warning('已经处于置底,无法下移')
  107. }
  108. }
  109. //向上
  110. const nodeUpSortClick = (index) => {
  111. const data = nodeSortTableData.value || []
  112. if (index !== 0) {
  113. const tmp = data.splice(index - 1, 1)
  114. nodeSortTableData.value.splice(index, 0, tmp[0])
  115. } else {
  116. window?.$message?.warning('已经处于置顶,无法上移')
  117. }
  118. }
  119. const sortNodeMoadl = ()=>{
  120. nodeSortModel.value = true
  121. let list = []
  122. if (node.value.parent) {
  123. node.value.parent.childNodes.forEach((element)=>{
  124. list.push(element.data)
  125. })
  126. }
  127. nodeSortTableData.value = list
  128. }
  129. const nodeSortModalSave = async ()=>{
  130. nodeSortModalLoading.value = true
  131. const { code } = await submitArchiveTreeSort({
  132. listSort:nodeSortTableData.value,
  133. })
  134. nodeSortModalLoading.value = false
  135. if (code === 200) {
  136. window.$message?.success('修改成功')
  137. window?.location?.reload() //刷新页面
  138. }
  139. }
  140. </script>