help-center-category.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import SaveForm from '@/components/save-form'
  2. import Pagination from '@/components/pagination'
  3. import { NButton, NDataTable, NModal, NSpace, useDialog, useMessage } from 'naive-ui'
  4. import { defineComponent, onMounted, reactive, ref } from 'vue'
  5. import { helpCenterCatalogPage, helpCenterCatalogRemove } from '../../api'
  6. import HelpCenterCategoryOperation from '../modal/help-center-category-operation'
  7. export default defineComponent({
  8. name: 'content-flash',
  9. setup() {
  10. const dialog = useDialog()
  11. const message = useMessage()
  12. const state = reactive({
  13. loading: false,
  14. pagination: {
  15. page: 1,
  16. rows: 10,
  17. pageTotal: 0
  18. },
  19. dataList: [] as any,
  20. visiableCategory: false,
  21. categoryOperation: 'add',
  22. categoryData: {} as any
  23. })
  24. const columns = () => {
  25. return [
  26. {
  27. title: '编号',
  28. key: 'id'
  29. },
  30. {
  31. title: '名称',
  32. key: 'name'
  33. },
  34. {
  35. title: '操作',
  36. key: 'operation',
  37. render(row: any) {
  38. return (
  39. <NSpace>
  40. <NButton
  41. type="primary"
  42. size="small"
  43. text
  44. //v-auth="helpCenterCatalog/update1599694974123089922"
  45. onClick={() => {
  46. state.visiableCategory = true
  47. state.categoryOperation = 'edit'
  48. state.categoryData = row
  49. }}
  50. >
  51. 修改
  52. </NButton>
  53. <NButton
  54. type="primary"
  55. size="small"
  56. text
  57. onClick={() => onRmove(row)}
  58. //v-auth="helpCenterCatalog/remove1599695049448595458"
  59. >
  60. 删除
  61. </NButton>
  62. </NSpace>
  63. )
  64. }
  65. }
  66. ]
  67. }
  68. const onRmove = (row: any): void => {
  69. console.log(row, 'row')
  70. dialog.warning({
  71. title: '警告',
  72. content: `是否删除该数据?`,
  73. positiveText: '确定',
  74. negativeText: '取消',
  75. onPositiveClick: async () => {
  76. try {
  77. await helpCenterCatalogRemove({ id: row.id })
  78. getList()
  79. message.success('删除成功')
  80. } catch {}
  81. }
  82. })
  83. }
  84. const getList = async () => {
  85. try {
  86. state.loading = true
  87. const { data } = await helpCenterCatalogPage({ ...state.pagination })
  88. state.loading = false
  89. state.pagination.pageTotal = Number(data.total)
  90. state.dataList = data.rows || []
  91. } catch {
  92. state.loading = false
  93. }
  94. }
  95. onMounted(() => {
  96. getList()
  97. })
  98. return () => (
  99. <div class="system-menu-container">
  100. <div class={['section-container']}>
  101. <NSpace style={{ paddingBottom: '12px' }}>
  102. <NButton
  103. type="primary"
  104. //v-auth="helpCenterCatalog/save1599694895257591809"
  105. onClick={() => {
  106. state.visiableCategory = true
  107. state.categoryOperation = 'add'
  108. state.categoryData = {}
  109. }}
  110. >
  111. 添加分类
  112. </NButton>
  113. </NSpace>
  114. <NDataTable
  115. loading={state.loading}
  116. columns={columns()}
  117. data={state.dataList}
  118. ></NDataTable>
  119. <Pagination
  120. v-model:page={state.pagination.page}
  121. v-model:pageSize={state.pagination.rows}
  122. v-model:pageTotal={state.pagination.pageTotal}
  123. onList={getList}
  124. sync
  125. saveKey="help-center-category"
  126. ></Pagination>
  127. </div>
  128. <NModal
  129. v-model:show={state.visiableCategory}
  130. preset="dialog"
  131. showIcon={false}
  132. title={state.categoryOperation === 'add' ? '新增帮助分类' : '修改帮助分类'}
  133. style={{ width: '500px' }}
  134. >
  135. <HelpCenterCategoryOperation
  136. type={state.categoryOperation}
  137. data={state.categoryData}
  138. onClose={() => (state.visiableCategory = false)}
  139. onGetList={getList}
  140. />
  141. </NModal>
  142. </div>
  143. )
  144. }
  145. })