index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <!--
  2. * @FilePath: index.vue
  3. * @Author: 旭颖
  4. * @Date: 2024-08-29 14:19:28
  5. * @LastEditors: liangxvying 1615026511@qq.com
  6. * @LastEditTime: 2024-11-01 22:26:34
  7. -->
  8. <template>
  9. <div class="edit">
  10. <el-icon
  11. class="no-inherit"
  12. color="#409efc"
  13. v-if="editForm.id == row.id && editStatus == 1"
  14. @click="cancelSort(row)"
  15. size="18"
  16. >
  17. <CircleClose />
  18. </el-icon>
  19. <span
  20. v-if="editForm.id !== row.id || editStatus == 0"
  21. class="sort-num"
  22. size="18"
  23. >
  24. {{ row.sort }}
  25. </span>
  26. <el-input
  27. v-if="editForm.id == row.id && editStatus == 1"
  28. ref="getFocus"
  29. v-model="row.sort"
  30. class="input-sort"
  31. @input="inputSort"
  32. />
  33. <el-icon
  34. class="no-inherit"
  35. color="#409efc"
  36. v-if="editForm.id !== row.id || editStatus == 0"
  37. @click="changeSort(row)"
  38. size="18"
  39. >
  40. <Edit />
  41. </el-icon>
  42. <el-icon
  43. class="no-inherit"
  44. color="#409efc"
  45. size="18"
  46. v-if="editForm.id == row.id && editStatus == 1"
  47. @click="sureChange"
  48. >
  49. <CircleCheck />
  50. </el-icon>
  51. </div>
  52. </template>
  53. <script>
  54. import { putApi } from '@/api/api'
  55. import {
  56. Delete,
  57. Plus,
  58. Search,
  59. Upload,
  60. Download,
  61. Refresh,
  62. } from '@element-plus/icons-vue'
  63. export default defineComponent({
  64. name: 'RoleManagement',
  65. props: {
  66. row: {
  67. type: Object,
  68. default: {},
  69. },
  70. api: {
  71. type: Object,
  72. default: '',
  73. },
  74. },
  75. setup(props, { emit }) {
  76. const $baseConfirm = inject('$baseConfirm')
  77. const $baseMessage = inject('$baseMessage')
  78. const state = reactive({
  79. //修改排序
  80. oldSort: 0,
  81. editForm: '',
  82. editStatus: 0, //排序编辑状态 0为正常 1显示输入框
  83. getFocus: null,
  84. })
  85. //修改排序事件
  86. const changeSort = (row) => {
  87. state.editStatus = 1
  88. state.editForm = row
  89. state.oldSort = row.sort
  90. nextTick(() => {
  91. state['getFocus'].focus()
  92. })
  93. }
  94. const cancelSort = (row) => {
  95. state.editStatus = 0
  96. row.sort = state.oldSort
  97. }
  98. //修改排序
  99. const inputSort = (e) => {
  100. console.log(e, '000000000')
  101. state.editForm.sort = e
  102. }
  103. const sureChange = async () => {
  104. state.editStatus = 0
  105. if (state.oldSort !== state.editForm.sort) {
  106. const { message } = await putApi(props.api, state.editForm)
  107. $baseMessage(message, 'success', 'vab-hey-message-success')
  108. emit('fetch-data')
  109. } else {
  110. return
  111. }
  112. }
  113. return {
  114. ...toRefs(state),
  115. Delete,
  116. Plus,
  117. Search,
  118. Upload,
  119. Download,
  120. Refresh,
  121. cancelSort,
  122. inputSort,
  123. sureChange,
  124. changeSort,
  125. }
  126. },
  127. })
  128. </script>
  129. <style lang="scss" scoped>
  130. .edit {
  131. display: flex;
  132. align-items: center;
  133. margin: 0 auto;
  134. width: 100%;
  135. justify-content: center;
  136. }
  137. .input-sort {
  138. display: inline-block;
  139. width: 80px;
  140. margin-right: 10px;
  141. margin-left: 10px;
  142. border: none;
  143. }
  144. .no-inherit {
  145. color: #1890ff;
  146. cursor: pointer;
  147. }
  148. .sort-num {
  149. display: inline-block;
  150. margin-right: 10px;
  151. }
  152. </style>