rename.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <CzrDialog
  3. :show="show"
  4. title="重命名"
  5. @onClose="$emit('update:show', false)"
  6. @onSubmit="onSubmit"
  7. width="33rem"
  8. :loading="state.loading"
  9. >
  10. <div class="bm-form">
  11. <CzrForm ref="ref_form" layout="y">
  12. <CzrFormColumn
  13. required
  14. :span="24"
  15. label="文件名称"
  16. v-model:param="state.name"
  17. />
  18. </CzrForm>
  19. </div>
  20. </CzrDialog>
  21. </template>
  22. <script setup lang="ts">
  23. import {
  24. computed,
  25. getCurrentInstance,
  26. nextTick,
  27. reactive,
  28. ref,
  29. watch,
  30. } from 'vue'
  31. import { ElMessage, ElMessageBox } from 'element-plus'
  32. import { useDialogStore, useDictionaryStore } from '@/stores'
  33. import { useRouter } from 'vue-router'
  34. import { documentUpdateFileName } from '@/api/modules/knowledge/document'
  35. const router = useRouter()
  36. const DictionaryStore = useDictionaryStore()
  37. const DialogStore = useDialogStore()
  38. const emit = defineEmits(['update:show', 'refresh'])
  39. const { proxy } = getCurrentInstance()
  40. const props = defineProps({
  41. show: { default: false },
  42. transfer: <any>{},
  43. })
  44. const state: any = reactive({
  45. loading: false,
  46. name: '',
  47. })
  48. const ref_form = ref()
  49. watch(
  50. () => props.show,
  51. (n) => {
  52. if (n) {
  53. state.name = props.transfer.name
  54. nextTick(() => {
  55. ref_form.value.reset()
  56. })
  57. }
  58. },
  59. )
  60. const onSubmit = () => {
  61. ref_form.value
  62. .submit()
  63. .then(() => {
  64. DialogStore.confirm({
  65. content: `请确认是否重命名文件?`,
  66. onSubmit: () => {
  67. state.loading = true
  68. documentUpdateFileName({
  69. docId: props.transfer.id,
  70. name: state.name,
  71. })
  72. .then(() => {
  73. ElMessage.success(`重命名成功!`)
  74. emit('update:show', false)
  75. emit('refresh')
  76. })
  77. .catch(() => {})
  78. .finally(() => {
  79. state.loading = false
  80. })
  81. },
  82. })
  83. })
  84. .catch((e) => {
  85. ElMessage({
  86. message: e[0].message,
  87. grouping: true,
  88. type: 'warning',
  89. })
  90. })
  91. }
  92. </script>
  93. <style lang="scss" scoped></style>