index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <style scoped lang="scss">
  2. .system-container {
  3. :deep(.el-card__body) {
  4. display: flex;
  5. flex-direction: column;
  6. justify-content: space-between;
  7. flex: 1;
  8. overflow: auto;
  9. .el-table {
  10. flex: 1;
  11. }
  12. }
  13. }
  14. .page-content {
  15. margin-bottom: 20px;
  16. }
  17. .page-pager {
  18. background-color: #fff;
  19. height: 24px;
  20. }
  21. </style>
  22. <template>
  23. <div class="system-container layout-padding">
  24. <el-card shadow="hover" class="layout-padding-auto">
  25. <el-form
  26. :model="state.formQuery"
  27. ref="queryRef"
  28. size="default" label-width="0px" class="mt5 mb5">
  29. <el-input
  30. v-model="state.formQuery.question"
  31. placeholder="问题"
  32. clearable
  33. @blur="loadData(true)"
  34. class="wd150 mr10">
  35. </el-input>
  36. <ext-d-select
  37. v-model="state.formQuery.status"
  38. placeholder="状态"
  39. type="Faq.status"
  40. clearable
  41. @blur="loadData(true)"
  42. class="wd150 mr10">
  43. </ext-d-select>
  44. <el-button class="ml10" plain size="default" type="success" @click="loadData(true)">
  45. <SvgIcon name="ele-Search"/>
  46. 查询
  47. </el-button>
  48. <el-button v-auth="'faq.add'" size="default" plain type="success" class="ml10" @click="handleRowClick('add',null)">
  49. <SvgIcon name="ele-FolderAdd"/>
  50. 新增
  51. </el-button>
  52. </el-form>
  53. <el-table
  54. border
  55. stripe="stripe"
  56. :height="state.tableData.height"
  57. highlight-current-row
  58. current-row-key="id"
  59. row-key="id"
  60. :data="state.tableData.data"
  61. v-loading="state.tableData.loading"
  62. @selection-change="handleTableSelectionChange"
  63. @sort-change="handleTableSortChange">
  64. <template #empty>
  65. <el-empty></el-empty>
  66. </template>
  67. <el-table-column
  68. v-for="field in state.tableData.columns"
  69. :key="field.prop"
  70. :label="field.label"
  71. :column-key="field.prop"
  72. :width="field.width"
  73. :min-width="field.minWidth"
  74. :fixed="field.fixed"
  75. :sortable="field.sortable"
  76. :show-overflow-tooltip="!field.fixed&&field.width>150" >
  77. <template #default="{row}">
  78. <template v-if="field.prop==='expand'">
  79. <p style="padding-left: 2em;" v-html="row[field.prop]"></p>
  80. </template>
  81. <template v-else-if="field.prop==='status'">
  82. <ext-d-label type="User.status" :model-value="row[field.prop]"></ext-d-label>
  83. <!-- <p style="padding-left: 2em;" v-html="row[field.prop]"></p>-->
  84. </template>
  85. <!-- <template v-else-if="field.prop==='answer'">
  86. <p style="padding-left: 2em;" v-html="row[field.prop]"></p>
  87. </template>-->
  88. <template v-else-if="field.prop==='action'">
  89. <el-button v-auth="'faq.modify'" size="small" plain type="warning" @click="handleRowClick('edit',row)">编辑</el-button>
  90. <el-button v-auth="'faq.remove'" size="small" plain type="danger" @click="handleRowDelete(row)">删除</el-button>
  91. </template>
  92. <template v-else>
  93. <div>{{ row[field.prop] }}</div>
  94. </template>
  95. </template>
  96. </el-table-column>
  97. </el-table>
  98. <ext-page class="page-pager" v-model:value="state.pageQuery" @change="loadData(false)"/>
  99. </el-card>
  100. <FaqDialog ref="faq_dialog_ref"></FaqDialog>
  101. </div>
  102. </template>
  103. <script setup lang="ts" name="FaqList">
  104. import {nextTick, onBeforeMount, onBeforeUnmount, onMounted, reactive, ref} from 'vue';
  105. import {$get,$body} from "/@/utils/request";
  106. import {Msg} from "/@/utils/message";
  107. import u from "/@/utils/u"
  108. import {useRoute} from "vue-router";
  109. import ExtPage from '/@/components/form/ExtPage.vue'
  110. import FaqDialog from "/@/views/admin/faq/dialog.vue"
  111. import mittBus from '/@/utils/mitt';
  112. import ExtDLabel from "/@/components/form/ExtDLabel.vue";
  113. const route = useRoute();
  114. //定义引用
  115. const queryRef = ref();
  116. const faq_dialog_ref = ref();
  117. //定义变量
  118. const state = reactive({
  119. formQuery: {},
  120. pageQuery: {
  121. pageNum: 1,
  122. pageSize: 10,
  123. total: 0
  124. },
  125. tableData: {
  126. height: 500,
  127. data: [] as Array<any>,
  128. loading: false,
  129. columns: [
  130. {label: '问题', prop: 'question', width: 200, resizable: true, fixed: 'left'},
  131. {label: '状态', prop: 'status', width: 150, resizable: true, fixed: 'left'},
  132. {label: '答案', prop: 'answer', resizable: true},
  133. {label: '操作', prop: 'action', sortable: 'custom', resizable: true, width: 200, fixed: 'right'},
  134. ],
  135. },
  136. })
  137. // 监听双向绑定 modelValue 的变化
  138. // watch(
  139. // () => state.pageNum,
  140. // () => {
  141. //
  142. // }
  143. // );
  144. //生命周期钩子
  145. onBeforeMount(() => {
  146. })
  147. onMounted(() => {
  148. var query = route.query;
  149. //console.log(route.params, route.query)
  150. if (query.mobilePhone) {
  151. state.formQuery.mobilePhone = query.mobilePhone;
  152. }
  153. loadData();
  154. nextTick(() => {
  155. let bodyHeight = document.body.clientHeight;
  156. let queryHeight = queryRef.value.$el.clientHeight;
  157. state.tableData.height = bodyHeight - queryHeight - 320
  158. })
  159. });
  160. //region 方法区
  161. // 初始化表格数据
  162. const loadData = (refresh: boolean = false) => {
  163. if (refresh) {
  164. state.pageQuery.pageNum = 1;
  165. }
  166. state.tableData.loading = true;
  167. $body(`/faq/list`, {...state.formQuery, ...state.pageQuery}).then((res: any) => {
  168. let {list, total} = res;
  169. state.tableData.data = list;
  170. state.pageQuery.total = total;
  171. state.tableData.loading = false;
  172. }).catch(e => {
  173. //console.error(e)
  174. state.tableData.loading = false;
  175. })
  176. };
  177. const handleRowClick = (type: string, row: any) => {
  178. faq_dialog_ref.value.open(type, row);
  179. };
  180. const handleRowDelete = (row: any) => {
  181. Msg.confirm(`此操作将永久删除:『${row.name}』,是否继续?`).then(() => {
  182. $get(`/faq/delete/${row.id}`).then(() => {
  183. Msg.message("删除成功", 'success')
  184. }).catch(() => {
  185. Msg.message("删除失败", 'error')
  186. })
  187. });
  188. };
  189. const handleTableSelectionChange = (selection: any) => {
  190. //console.log("handleTableSelectionChange>>", selection)
  191. // emit("on-check-change", selection)
  192. }
  193. const handleTableSortChange = (column, prop, order) => {
  194. //console.log("handleTableSortChange>>", column, prop, order)
  195. // emit("on-sort-change", column)
  196. }
  197. //endregion
  198. // 暴露变量
  199. // defineExpose({
  200. // loadData,
  201. // });
  202. </script>