Dir.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <el-drawer
  3. :title="title"
  4. :modal-append-to-body="false"
  5. :modal="false"
  6. :wrapper-closable="false"
  7. size="25%"
  8. :visible.sync="dialogVisible"
  9. >
  10. <div class="content-container">
  11. <el-form ref="ruleForm" :model="formData" :rules="rules" label-position="top" label-width="100px">
  12. <el-form-item label="目录名称" prop="dirTitle">
  13. <el-input v-model="formData.dirTitle" />
  14. </el-form-item>
  15. </el-form>
  16. <div class="btn-group">
  17. <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
  18. <el-button class="cancel-btn" @click="dialogVisible = false">取 消</el-button>
  19. </div>
  20. </div>
  21. </el-drawer>
  22. </template>
  23. <script>
  24. import { ACTION_ADD, ACTION_UPDATE } from '@/utils/actionType'
  25. import { createDir, updateDir, getDir } from '@/api/system/docApi'
  26. export default {
  27. name: 'DocDirectoryComponent',
  28. props: {
  29. title: {
  30. type: String,
  31. default: ''
  32. }
  33. },
  34. data() {
  35. return {
  36. dialogVisible: false,
  37. formData: {
  38. dirId: '',
  39. dirTitle: '',
  40. parentId: ''
  41. },
  42. rules: {
  43. dirTitle: [
  44. { required: true, message: '请输入目录名称', trigger: 'blur' }
  45. ]
  46. },
  47. actionType: ''
  48. }
  49. },
  50. mounted() {
  51. },
  52. methods: {
  53. // Add Model
  54. showAddModel(parentId) {
  55. this.resetFormData()
  56. this.actionType = ACTION_ADD
  57. this.dialogVisible = true
  58. this.formData.parentId = parentId
  59. },
  60. // Edit Model
  61. showEditModel(dirId) {
  62. this.resetFormData()
  63. this.actionType = ACTION_UPDATE
  64. this.dialogVisible = true
  65. getDir(dirId).then((resp) => {
  66. const { code, data, msg } = resp
  67. if (code === 200) {
  68. this.formData = data
  69. } else {
  70. this.$message.error(msg)
  71. }
  72. }).catch((error) => {
  73. console.log(error)
  74. })
  75. },
  76. // 处理
  77. resetFormData() {
  78. this.formData = {
  79. dirId: '',
  80. dirTitle: '',
  81. parentId: ''
  82. }
  83. },
  84. // 提交
  85. submitForm(formName) {
  86. this.$refs[formName].validate((valid) => {
  87. if (valid) {
  88. switch (this.actionType) {
  89. case ACTION_ADD:
  90. createDir(this.formData).then((resp) => {
  91. const { code, msg } = resp
  92. if (code === 200) {
  93. this.dialogVisible = false
  94. this.$message.success(msg)
  95. this.formSuccess()
  96. } else {
  97. this.$message.error(msg)
  98. }
  99. }).catch((error) => {
  100. console.log(error)
  101. })
  102. break
  103. case ACTION_UPDATE:
  104. updateDir(this.formData).then((resp) => {
  105. const { code, msg } = resp
  106. if (code === 200) {
  107. this.dialogVisible = false
  108. this.$message.success(msg)
  109. this.formSuccess()
  110. } else {
  111. this.$message.error(msg)
  112. }
  113. }).catch((error) => {
  114. console.log(error)
  115. })
  116. break
  117. }
  118. } else {
  119. console.log('error submit!!')
  120. return false
  121. }
  122. })
  123. },
  124. formSuccess() {
  125. this.$emit('formSuccess')
  126. },
  127. resetFormField(formName) {
  128. this.$refs[formName].resetFields()
  129. }
  130. }
  131. }
  132. </script>
  133. <style lang="scss">
  134. </style>
  135. <style lang="scss" scoped>
  136. </style>