ConfigList.vue 4.0 KB

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