index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div class="p-2">
  3. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  4. <div v-show="showSearch" class="mb-[10px]">
  5. <el-card shadow="hover">
  6. <el-form ref="queryFormRef" :model="queryParams" :inline="true">
  7. <el-form-item label="分组名" prop="rgName">
  8. <el-input v-model="queryParams.rgName" placeholder="请输入分组名" clearable @keyup.enter="handleQuery" />
  9. </el-form-item>
  10. <el-form-item>
  11. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  12. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  13. </el-form-item>
  14. </el-form>
  15. </el-card>
  16. </div>
  17. </transition>
  18. <el-card shadow="never">
  19. <template #header>
  20. <el-row :gutter="10" class="mb8">
  21. <el-col :span="1.5">
  22. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:rankGroup:add']">新增</el-button>
  23. </el-col>
  24. <el-col :span="1.5">
  25. <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['system:rankGroup:edit']">修改</el-button>
  26. </el-col>
  27. <el-col :span="1.5">
  28. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['system:rankGroup:remove']">删除</el-button>
  29. </el-col>
  30. <el-col :span="1.5">
  31. <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:rankGroup:export']">导出</el-button>
  32. </el-col>
  33. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  34. </el-row>
  35. </template>
  36. <el-table v-loading="loading" border :data="rankGroupList" @selection-change="handleSelectionChange">
  37. <el-table-column type="selection" width="55" align="center" />
  38. <el-table-column label="分组id" align="center" prop="rgId" v-if="false" />
  39. <el-table-column label="赛事ID" align="center" prop="eventId" v-if="false" />
  40. <el-table-column label="分组名" align="center" prop="rgName" />
  41. <el-table-column label="更新时间" align="center" prop="updateTime" />
  42. <el-table-column label="状态" align="center" prop="status" v-if="false" />
  43. <el-table-column label="备注" align="center" prop="remark" />
  44. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  45. <template #default="scope">
  46. <el-tooltip content="修改" placement="top">
  47. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:rankGroup:edit']"></el-button>
  48. </el-tooltip>
  49. <el-tooltip content="删除" placement="top">
  50. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:rankGroup:remove']"></el-button>
  51. </el-tooltip>
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  56. </el-card>
  57. <!-- 添加或修改排名分组对话框 -->
  58. <el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
  59. <el-form ref="rankGroupFormRef" :model="form" :rules="rules" label-width="80px">
  60. <el-form-item label="分组名" prop="rgName">
  61. <el-input v-model="form.rgName" placeholder="请输入分组名" />
  62. </el-form-item>
  63. <el-form-item label="备注" prop="remark">
  64. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  65. </el-form-item>
  66. </el-form>
  67. <template #footer>
  68. <div class="dialog-footer">
  69. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  70. <el-button @click="cancel">取 消</el-button>
  71. </div>
  72. </template>
  73. </el-dialog>
  74. </div>
  75. </template>
  76. <script setup name="RankGroup" lang="ts">
  77. import { listRankGroup, getRankGroup, delRankGroup, addRankGroup, updateRankGroup } from '@/api/system/rankGroup';
  78. import { RankGroupVO, RankGroupQuery, RankGroupForm } from '@/api/system/rankGroup/types';
  79. import { useGameEventStore } from '@/store/modules/gameEvent';
  80. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  81. const rankGroupList = ref<RankGroupVO[]>([]);
  82. const buttonLoading = ref(false);
  83. const loading = ref(true);
  84. const showSearch = ref(true);
  85. const ids = ref<Array<string | number>>([]);
  86. const single = ref(true);
  87. const multiple = ref(true);
  88. const total = ref(0);
  89. const queryFormRef = ref<ElFormInstance>();
  90. const rankGroupFormRef = ref<ElFormInstance>();
  91. let gameEventStore = null;
  92. let defaultEventInfo = null;
  93. const dialog = reactive<DialogOption>({
  94. visible: false,
  95. title: ''
  96. });
  97. const getInitFormData = () => ({
  98. rgId: undefined,
  99. eventId: defaultEventInfo?.eventId, // 使用可选链操作符防止报错
  100. rgName: undefined,
  101. updateTime: undefined,
  102. status: '0',
  103. remark: undefined
  104. });
  105. const data = reactive<PageData<RankGroupForm, RankGroupQuery>>({
  106. form: getInitFormData(),
  107. queryParams: {
  108. pageNum: 1,
  109. pageSize: 10,
  110. eventId: defaultEventInfo?.eventId, // 同样使用可选链操作符
  111. rgName: undefined,
  112. status: '0',
  113. orderByColumn: undefined,
  114. isAsc: undefined,
  115. params: {}
  116. },
  117. rules: {
  118. rgName: [
  119. { required: true, message: "分组名不能为空", trigger: "blur" }
  120. ]
  121. }
  122. });
  123. const { queryParams, form, rules } = toRefs(data);
  124. /** 查询排名分组列表 */
  125. const getList = async () => {
  126. loading.value = true;
  127. const res = await listRankGroup(queryParams.value);
  128. rankGroupList.value = res.rows;
  129. total.value = res.total;
  130. loading.value = false;
  131. }
  132. /** 取消按钮 */
  133. const cancel = () => {
  134. reset();
  135. dialog.visible = false;
  136. }
  137. /** 表单重置 */
  138. const reset = () => {
  139. form.value = getInitFormData();
  140. rankGroupFormRef.value?.resetFields();
  141. }
  142. /** 搜索按钮操作 */
  143. const handleQuery = () => {
  144. queryParams.value.pageNum = 1;
  145. getList();
  146. }
  147. /** 重置按钮操作 */
  148. const resetQuery = () => {
  149. queryFormRef.value?.resetFields();
  150. handleQuery();
  151. }
  152. /** 多选框选中数据 */
  153. const handleSelectionChange = (selection: RankGroupVO[]) => {
  154. ids.value = selection.map(item => item.rgId);
  155. single.value = selection.length != 1;
  156. multiple.value = !selection.length;
  157. }
  158. /** 新增按钮操作 */
  159. const handleAdd = () => {
  160. reset();
  161. dialog.visible = true;
  162. dialog.title = "添加排名分组";
  163. }
  164. /** 修改按钮操作 */
  165. const handleUpdate = async (row?: RankGroupVO) => {
  166. reset();
  167. const _rgId = row?.rgId || ids.value[0]
  168. const res = await getRankGroup(_rgId);
  169. Object.assign(form.value, res.data);
  170. dialog.visible = true;
  171. dialog.title = "修改排名分组";
  172. }
  173. /** 提交按钮 */
  174. const submitForm = () => {
  175. rankGroupFormRef.value?.validate(async (valid: boolean) => {
  176. if (valid) {
  177. buttonLoading.value = true;
  178. if (form.value.rgId) {
  179. await updateRankGroup(form.value).finally(() => buttonLoading.value = false);
  180. } else {
  181. await addRankGroup(form.value).finally(() => buttonLoading.value = false);
  182. }
  183. proxy?.$modal.msgSuccess("操作成功");
  184. dialog.visible = false;
  185. await getList();
  186. }
  187. });
  188. }
  189. /** 删除按钮操作 */
  190. const handleDelete = async (row?: RankGroupVO) => {
  191. const _rgIds = row?.rgId || ids.value;
  192. await proxy?.$modal.confirm('是否确认删除排名分组编号为"' + _rgIds + '"的数据项?').finally(() => loading.value = false);
  193. await delRankGroup(_rgIds);
  194. proxy?.$modal.msgSuccess("删除成功");
  195. await getList();
  196. }
  197. /** 导出按钮操作 */
  198. const handleExport = () => {
  199. proxy?.download('system/rankGroup/export', {
  200. ...queryParams.value
  201. }, `rankGroup_${new Date().getTime()}.xlsx`)
  202. }
  203. // 在 onMounted 中初始化 store 后更新表单数据
  204. onMounted(() => {
  205. gameEventStore = useGameEventStore();
  206. defaultEventInfo = gameEventStore.defaultEventInfo;
  207. form.value.eventId = defaultEventInfo?.eventId;
  208. queryParams.value.eventId = defaultEventInfo?.eventId;
  209. getList();
  210. });
  211. </script>