ConfigList.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <script setup lang="ts">
  2. import { $gettext } from '../../gettext'
  3. import StdTable from '@/components/StdDesign/StdDataDisplay/StdTable.vue'
  4. import config from '@/api/config'
  5. import configColumns from '@/views/config/configColumns'
  6. import FooterToolBar from '@/components/FooterToolbar/FooterToolBar.vue'
  7. import InspectConfig from '@/views/config/InspectConfig.vue'
  8. import { useBreadcrumbs } from '@/composables/useBreadcrumbs'
  9. import Mkdir from '@/views/config/components/Mkdir.vue'
  10. import Rename from '@/views/config/components/Rename.vue'
  11. const table = ref()
  12. const route = useRoute()
  13. const router = useRouter()
  14. const basePath = computed(() => {
  15. let dir = route?.query?.dir ?? ''
  16. if (dir)
  17. dir += '/'
  18. return dir as string
  19. })
  20. const getParams = computed(() => {
  21. return {
  22. dir: basePath.value,
  23. }
  24. })
  25. const update = ref(1)
  26. watch(getParams, () => {
  27. update.value++
  28. })
  29. const refInspectConfig = ref()
  30. const breadcrumbs = useBreadcrumbs()
  31. function updateBreadcrumbs() {
  32. const path = basePath.value
  33. .split('/')
  34. .filter(v => v)
  35. .map(v => {
  36. return {
  37. name: 'Manage Configs',
  38. translatedName: () => v,
  39. path: '/config',
  40. query: {
  41. dir: v,
  42. },
  43. hasChildren: false,
  44. }
  45. })
  46. breadcrumbs.value = [{
  47. name: 'Dashboard',
  48. translatedName: () => $gettext('Dashboard'),
  49. path: '/dashboard',
  50. hasChildren: false,
  51. }, {
  52. name: 'Manage Configs',
  53. translatedName: () => $gettext('Manage Configs'),
  54. path: '/config',
  55. hasChildren: false,
  56. }, ...path]
  57. }
  58. onMounted(() => {
  59. updateBreadcrumbs()
  60. })
  61. watch(route, () => {
  62. refInspectConfig.value?.test()
  63. updateBreadcrumbs()
  64. })
  65. function goBack() {
  66. router.push({
  67. path: '/config',
  68. query: {
  69. dir: `${basePath.value.split('/').slice(0, -2).join('/')}` || undefined,
  70. },
  71. })
  72. }
  73. const refMkdir = ref()
  74. const refRename = ref()
  75. </script>
  76. <template>
  77. <ACard :title="$gettext('Configurations')">
  78. <template #extra>
  79. <AButton
  80. v-if="basePath"
  81. type="link"
  82. size="small"
  83. @click="goBack"
  84. >
  85. {{ $gettext('Back') }}
  86. </AButton>
  87. <AButton
  88. type="link"
  89. size="small"
  90. @click="router.push({
  91. path: '/config/add',
  92. query: { basePath: basePath || undefined },
  93. })"
  94. >
  95. {{ $gettext('Create File') }}
  96. </AButton>
  97. <AButton
  98. type="link"
  99. size="small"
  100. @click="() => refMkdir.open(basePath)"
  101. >
  102. {{ $gettext('Create Folder') }}
  103. </AButton>
  104. </template>
  105. <InspectConfig ref="refInspectConfig" />
  106. <StdTable
  107. :key="update"
  108. ref="table"
  109. :api="config"
  110. :columns="configColumns"
  111. disable-delete
  112. disable-view
  113. row-key="name"
  114. :get-params="getParams"
  115. disable-query-params
  116. disable-modify
  117. >
  118. <template #actions="{ record }">
  119. <AButton
  120. type="link"
  121. size="small"
  122. @click="() => {
  123. if (!record.is_dir) {
  124. $router.push({
  125. path: `/config/${basePath}${record.name}/edit`,
  126. })
  127. }
  128. else {
  129. $router.push({
  130. query: {
  131. dir: basePath + record.name,
  132. },
  133. })
  134. }
  135. }"
  136. >
  137. {{ $gettext('Modify') }}
  138. </AButton>
  139. <ADivider type="vertical" />
  140. <AButton
  141. type="link"
  142. size="small"
  143. @click="() => refRename.open(basePath, record.name, record.is_dir)"
  144. >
  145. {{ $gettext('Rename') }}
  146. </AButton>
  147. </template>
  148. </StdTable>
  149. <Mkdir
  150. ref="refMkdir"
  151. @created="() => table.get_list()"
  152. />
  153. <Rename
  154. ref="refRename"
  155. @renamed="() => table.get_list()"
  156. />
  157. <FooterToolBar v-if="basePath">
  158. <AButton @click="goBack">
  159. {{ $gettext('Back') }}
  160. </AButton>
  161. </FooterToolBar>
  162. </ACard>
  163. </template>
  164. <style scoped>
  165. </style>