fix table button

This commit is contained in:
Chuck1sn
2025-06-15 17:10:16 +08:00
parent f011086fcf
commit fe3ebdf931
3 changed files with 68 additions and 67 deletions

View File

@@ -1,6 +1,7 @@
<template> <template>
<div class="flex flex-col sm:flex-row sm:justify-between sm:items-center mb-4 gap-y-3 sm:gap-y-0"> <div class="flex flex-col sm:flex-row sm:justify-between sm:items-center mb-4 gap-y-3 sm:gap-y-0">
<form class="w-full min-w-[200px] sm:w-auto flex flex-col xs:flex-row gap-2 xs:gap-3 items-stretch xs:items-center"> <form
class="grid grid-cols-2 sm:grid-cols-1 w-full min-w-[200px] sm:w-auto gap-2 xs:gap-3 items-stretch xs:items-center">
<template v-for="(filter, index) in filters" :key="index"> <template v-for="(filter, index) in filters" :key="index">
<!-- 输入框类型 --> <!-- 输入框类型 -->
<div v-if="filter.type === 'input'" class="flex-grow"> <div v-if="filter.type === 'input'" class="flex-grow">
@@ -32,7 +33,6 @@
</select> </select>
</div> </div>
</template> </template>
<button type="submit" <button type="submit"
class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-3 py-2 min-w-[70px] flex items-center justify-center" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-3 py-2 min-w-[70px] flex items-center justify-center"
@click.prevent="handleSearch"> @click.prevent="handleSearch">
@@ -45,7 +45,7 @@
</form> </form>
<!-- 额外操作按钮插槽 --> <!-- 额外操作按钮插槽 -->
<div class="w-full sm:w-auto"> <div class="flex justify-end">
<slot name="actions"></slot> <slot name="actions"></slot>
</div> </div>
</div> </div>

View File

@@ -1,15 +1,15 @@
<template> <template>
<div class="px-2 sm:px-4 pt-6 sm:rounded-lg"> <div class="px-2 sm:px-4 pt-6 sm:rounded-lg">
<div class="mb-4 sm:mb-6 col-span-full"> <div class="mb-4 sm:mb-6 col-span-full">
<Breadcrumbs :names="['用户管理', '角色分配']" :routes="[{ name: RouteName.USERVIEW }]" /> <Breadcrumbs :names="['用户管理', '角色分配']" :routes="[{ name: RouteName.USERVIEW }]" />
<h1 class="text-xl sm:text-2xl mb-4 sm:mb-6 font-semibold text-gray-900">角色分配</h1> <h1 class="text-xl sm:text-2xl mb-4 sm:mb-6 font-semibold text-gray-900">角色分配</h1>
</div> </div>
<TableFilterForm :filters="filterConfig" :initialValues="filterValues" @search="handleSearch" <TableFilterForm :filters="filterConfig" :initialValues="filterValues" @search="handleSearch"
@update:values="updateFilterValues"> @update:values="updateFilterValues">
<template #actions> <template #actions>
<div class="flex gap-x-2"> <div class="flex gap-x-2">
<TableButton variant="primary" @click="() => { <TableButton variant="primary" @click="() => {
if (checkedRoleIds.length === 0) { if (checkedRoleIds.length === 0) {
alertStore.showAlert({ alertStore.showAlert({
content: '没有选择角色', content: '没有选择角色',
@@ -19,9 +19,9 @@
roleBindModal?.show(); roleBindModal?.show();
} }
}"> }">
绑定 绑定
</TableButton> </TableButton>
<TableButton variant="danger" @click="() => { <TableButton variant="danger" @click="() => {
if (checkedRoleIds.length === 0) { if (checkedRoleIds.length === 0) {
alertStore.showAlert({ alertStore.showAlert({
content: '没有选择角色', content: '没有选择角色',
@@ -31,60 +31,60 @@
roleUnbindModal?.show(); roleUnbindModal?.show();
} }
}"> }">
解绑 解绑
</TableButton> </TableButton>
</div> </div>
</template> </template>
</TableFilterForm> </TableFilterForm>
<!-- 移动端卡片布局 --> <!-- 移动端卡片布局 -->
<div class="md:hidden space-y-4"> <div class="md:hidden space-y-4">
<MobileCardListWithCheckbox :items="roles" v-model="checkedRoleIds"> <MobileCardListWithCheckbox :items="roles" v-model="checkedRoleIds">
<template #title="{ item }"> <template #title="{ item }">
{{ item.name }} {{ item.name }}
</template> </template>
<template #status="{ item }"> <template #status="{ item }">
<div class="flex items-center"> <div class="flex items-center">
<div class="h-2.5 w-2.5 rounded-full me-2" :class="item.isBound ? 'bg-green-500' : 'bg-red-500'"></div> <div class="h-2.5 w-2.5 rounded-full me-2" :class="item.isBound ? 'bg-green-500' : 'bg-red-500'"></div>
<span class="text-sm">{{ item.isBound === true ? "已绑定" : "未绑定" }}</span> <span class="text-sm">{{ item.isBound === true ? "已绑定" : "未绑定" }}</span>
</div> </div>
</template> </template>
<template #content="{ item }"> <template #content="{ item }">
<div> <div>
<p class="text-xs font-medium text-gray-600">角色编码</p> <p class="text-xs font-medium text-gray-600">角色编码</p>
<p class="text-sm text-gray-900 mt-0.5">{{ item.code }}</p> <p class="text-sm text-gray-900 mt-0.5">{{ item.code }}</p>
</div> </div>
</template> </template>
</MobileCardListWithCheckbox> </MobileCardListWithCheckbox>
</div> </div>
<!-- PC端表格布局 --> <!-- PC端表格布局 -->
<div class="hidden md:block"> <div class="hidden md:block">
<TableFormLayout :items="roles || []" :columns="columns" :hasCheckbox="true" v-model="checkedRoleIds" <TableFormLayout :items="roles || []" :columns="columns" :hasCheckbox="true" v-model="checkedRoleIds"
@all-checked-change="allChecked = $event"> @all-checked-change="allChecked = $event">
<template #code="{ item }"> <template #code="{ item }">
{{ item.code }} {{ item.code }}
</template> </template>
<template #name="{ item }"> <template #name="{ item }">
{{ item.name }} {{ item.name }}
</template> </template>
<template #bindState="{ item }"> <template #bindState="{ item }">
<div class="flex items-center"> <div class="flex items-center">
<div class="h-2.5 w-2.5 rounded-full me-2" :class="item.isBound ? 'bg-green-500' : 'bg-red-500'"> <div class="h-2.5 w-2.5 rounded-full me-2" :class="item.isBound ? 'bg-green-500' : 'bg-red-500'">
</div> </div>
{{ item.isBound === true ? "已绑定" : "未绑定" }} {{ item.isBound === true ? "已绑定" : "未绑定" }}
</div> </div>
</template> </template>
</TableFormLayout> </TableFormLayout>
</div> </div>
<TablePagination :pageChange="handlePageChange" :total="total" /> <TablePagination :pageChange="handlePageChange" :total="total" />
</div> </div>
<BindModal :id="'role-bind-modal'" :closeModal="() => { <BindModal :id="'role-bind-modal'" :closeModal="() => {
roleBindModal!.hide(); roleBindModal!.hide();
}" :onSubmit="handleBindRoleSubmit" title="确定绑定选中的角色吗"></BindModal> }" :onSubmit="handleBindRoleSubmit" title="确定绑定选中的角色吗"></BindModal>
<UnModal :id="'role-unbind-modal'" :closeModal="() => { <UnModal :id="'role-unbind-modal'" :closeModal="() => {
roleUnbindModal!.hide(); roleUnbindModal!.hide();
}" :onSubmit="handleUnbindRoleSubmit" title="确定解绑选中的角色吗"></UnModal> }" :onSubmit="handleUnbindRoleSubmit" title="确定解绑选中的角色吗"></UnModal>
</template> </template>

View File

@@ -8,12 +8,12 @@
<TableFilterForm :filters="filterConfig" :initialValues="filterValues" @search="handleSearch" <TableFilterForm :filters="filterConfig" :initialValues="filterValues" @search="handleSearch"
@update:values="updateFilterValues"> @update:values="updateFilterValues">
<template #actions> <template #actions>
<Button :handleClick="() => handleUpsertUserClick(undefined)" :isLoading="false" :abortable="false" <TableButton variant="primary" @click="() => handleUpsertUserClick(undefined)">
submitContent="新增用户" class="w-full sm:w-auto">
<template #icon> <template #icon>
<PlusIcon class="w-4 h-4 me-2" /> <PlusIcon class="w-4 h-4 me-2" />
</template> </template>
</Button> 新增用户
</TableButton>
</template> </template>
</TableFilterForm> </TableFilterForm>
@@ -185,6 +185,7 @@ import { useRouter } from "vue-router";
import type { components } from "../api/types/schema"; import type { components } from "../api/types/schema";
import useAlertStore from "../composables/store/useAlertStore"; import useAlertStore from "../composables/store/useAlertStore";
import { useUserUpsert } from "../composables/user/useUserUpsert"; import { useUserUpsert } from "../composables/user/useUserUpsert";
import TableButton from "@/components/TableButton.vue";
const filterConfig: FilterItem[] = [ const filterConfig: FilterItem[] = [
{ {