[色子游戏]底注配置

This commit is contained in:
2026-03-25 14:33:58 +08:00
parent 5ef8ee8bc5
commit 1027612cc0
13 changed files with 777 additions and 0 deletions

View File

@@ -0,0 +1,139 @@
<template>
<div class="art-full-height">
<TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" />
<ElCard class="art-table-card" shadow="never">
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
<template #left>
<ElSpace wrap>
<ElButton v-permission="'dice:ante_config:index:save'" @click="showDialog('add')" v-ripple>
<template #icon>
<ArtSvgIcon icon="ri:add-fill" />
</template>
{{ $t('table.actions.add') }}
</ElButton>
<ElButton
v-permission="'dice:ante_config:index:destroy'"
:disabled="selectedRows.length === 0"
@click="deleteSelectedRows(api.delete, refreshData)"
v-ripple
>
<template #icon>
<ArtSvgIcon icon="ri:delete-bin-5-line" />
</template>
{{ $t('table.actions.delete') }}
</ElButton>
</ElSpace>
</template>
</ArtTableHeader>
<ArtTable
ref="tableRef"
rowKey="id"
:loading="loading"
:data="data"
:columns="columns"
:pagination="pagination"
@sort-change="handleSortChange"
@selection-change="handleSelectionChange"
@pagination:size-change="handleSizeChange"
@pagination:current-change="handleCurrentChange"
>
<template #is_default="{ row }">
<ElTag :type="row.is_default === 1 ? 'success' : 'info'" size="small">
{{ row.is_default === 1 ? $t('page.table.defaultYes') : $t('page.table.defaultNo') }}
</ElTag>
</template>
<template #operation="{ row }">
<div class="flex gap-2">
<SaButton
v-permission="'dice:ante_config:index:update'"
type="secondary"
@click="showDialog('edit', row)"
/>
<SaButton
v-permission="'dice:ante_config:index:destroy'"
type="error"
@click="deleteRow(row, api.delete, refreshData)"
/>
</div>
</template>
</ArtTable>
</ElCard>
<EditDialog
v-model="dialogVisible"
:dialog-type="dialogType"
:data="dialogData"
@success="refreshData"
/>
</div>
</template>
<script setup lang="ts">
import { useTable } from '@/hooks/core/useTable'
import { useSaiAdmin } from '@/composables/useSaiAdmin'
import api from '../../api/ante_config/index'
import TableSearch from './modules/table-search.vue'
import EditDialog from './modules/edit-dialog.vue'
const searchForm = ref({
name: undefined,
title: undefined,
is_default: undefined
})
const handleSearch = (params: Record<string, unknown>) => {
Object.assign(searchParams, params)
getData()
}
const {
columns,
columnChecks,
data,
loading,
getData,
searchParams,
pagination,
resetSearchParams,
handleSortChange,
handleSizeChange,
handleCurrentChange,
refreshData
} = useTable({
core: {
apiFn: api.list,
columnsFactory: () => [
{ type: 'selection' },
{ prop: 'id', label: 'page.table.id', width: 80, align: 'center' },
{ prop: 'name', label: 'page.table.name', align: 'center' },
{ prop: 'title', label: 'page.table.title', align: 'center' },
{ prop: 'mult', label: 'page.table.mult', align: 'center' },
{ prop: 'is_default', label: 'page.table.isDefault', width: 110, align: 'center', useSlot: true },
{ prop: 'create_time', label: 'page.table.createTime', width: 170, align: 'center' },
{ prop: 'update_time', label: 'page.table.updateTime', width: 170, align: 'center' },
{
prop: 'operation',
label: 'table.actions.operation',
width: 100,
align: 'center',
fixed: 'right',
useSlot: true
}
]
}
})
const {
dialogType,
dialogVisible,
dialogData,
showDialog,
deleteRow,
deleteSelectedRows,
handleSelectionChange,
selectedRows
} = useSaiAdmin()
</script>

View File

@@ -0,0 +1,126 @@
<template>
<el-dialog
v-model="visible"
:title="dialogType === 'add' ? $t('page.form.titleAdd') : $t('page.form.titleEdit')"
width="560px"
align-center
:close-on-click-modal="false"
@close="handleClose"
>
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
<el-form-item :label="$t('page.form.labelName')" prop="name">
<el-input v-model="formData.name" :placeholder="$t('page.form.placeholderName')" />
</el-form-item>
<el-form-item :label="$t('page.form.labelTitle')" prop="title">
<el-input v-model="formData.title" :placeholder="$t('page.form.placeholderTitle')" />
</el-form-item>
<el-form-item :label="$t('page.form.labelMult')" prop="mult">
<el-input-number v-model="formData.mult" :min="1" :step="1" style="width: 100%" />
</el-form-item>
<el-form-item :label="$t('page.form.labelIsDefault')" prop="is_default">
<el-radio-group v-model="formData.is_default">
<el-radio :value="1">{{ $t('page.table.defaultYes') }}</el-radio>
<el-radio :value="0">{{ $t('page.table.defaultNo') }}</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="handleClose">{{ $t('common.cancel') }}</el-button>
<el-button type="primary" @click="handleSubmit">{{ $t('table.form.submit') }}</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import api from '../../../api/ante_config/index'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
interface Props {
modelValue: boolean
dialogType: string
data?: Record<string, unknown>
}
interface Emits {
(e: 'update:modelValue', value: boolean): void
(e: 'success'): void
}
const props = withDefaults(defineProps<Props>(), {
modelValue: false,
dialogType: 'add',
data: undefined
})
const emit = defineEmits<Emits>()
const formRef = ref<FormInstance>()
const visible = computed({
get: () => props.modelValue,
set: (value) => emit('update:modelValue', value)
})
const rules = computed<FormRules>(() => ({
name: [{ required: true, message: t('page.form.ruleNameRequired'), trigger: 'blur' }],
title: [{ required: true, message: t('page.form.ruleTitleRequired'), trigger: 'blur' }],
mult: [{ required: true, message: t('page.form.ruleMultRequired'), trigger: 'blur' }],
is_default: [{ required: true, message: t('page.form.ruleDefaultRequired'), trigger: 'change' }]
}))
interface AnteFormData {
id: number | null
name: string
title: string
mult: number
is_default: number
}
const initialFormData: AnteFormData = {
id: null,
name: '',
title: '',
mult: 1,
is_default: 0
}
const formData = reactive({ ...initialFormData })
watch(
() => props.modelValue,
async (newVal) => {
if (!newVal) return
Object.assign(formData, initialFormData)
if (!props.data) return
await nextTick()
if (typeof props.data.id === 'number') formData.id = props.data.id
if (typeof props.data.name === 'string') formData.name = props.data.name
if (typeof props.data.title === 'string') formData.title = props.data.title
formData.mult = Number(props.data.mult ?? 1) || 1
formData.is_default = Number(props.data.is_default ?? 0) === 1 ? 1 : 0
}
)
function handleClose() {
visible.value = false
formRef.value?.resetFields()
}
async function handleSubmit() {
if (!formRef.value) return
try {
await formRef.value.validate()
if (props.dialogType === 'add') {
await api.save(formData)
ElMessage.success(t('page.form.addSuccess'))
} else {
await api.update(formData)
ElMessage.success(t('page.form.editSuccess'))
}
emit('success')
handleClose()
} catch (error) {
console.log(error)
}
}
</script>

View File

@@ -0,0 +1,68 @@
<template>
<sa-search-bar
ref="searchBarRef"
v-model="formData"
label-width="100px"
:showExpand="false"
@reset="handleReset"
@search="handleSearch"
>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.name')" prop="name">
<el-input v-model="formData.name" :placeholder="$t('page.search.placeholderName')" clearable />
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.title')" prop="title">
<el-input v-model="formData.title" :placeholder="$t('page.search.placeholderTitle')" clearable />
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.isDefault')" prop="is_default">
<el-select v-model="formData.is_default" :placeholder="$t('page.search.placeholderIsDefault')" clearable>
<el-option :label="$t('page.table.defaultYes')" :value="1" />
<el-option :label="$t('page.table.defaultNo')" :value="0" />
</el-select>
</el-form-item>
</el-col>
</sa-search-bar>
</template>
<script setup lang="ts">
interface Props {
modelValue: Record<string, unknown>
}
interface Emits {
(e: 'update:modelValue', value: Record<string, unknown>): void
(e: 'search', params: Record<string, unknown>): void
(e: 'reset'): void
}
const props = defineProps<Props>()
const emit = defineEmits<Emits>()
const searchBarRef = ref()
const formData = computed({
get: () => props.modelValue,
set: (val) => emit('update:modelValue', val)
})
function handleReset() {
searchBarRef.value?.ref.resetFields()
emit('reset')
}
function handleSearch() {
emit('search', formData.value)
}
const setSpan = (span: number) => {
return {
span,
xs: 24,
sm: span >= 12 ? span : 12,
md: span >= 8 ? span : 8,
lg: span,
xl: span
}
}
</script>

View File

@@ -0,0 +1,40 @@
import request from '@/utils/http'
/**
* 底注配置 API
*/
export default {
list(params: Record<string, unknown>) {
return request.get<Api.Common.ApiPage>({
url: '/core/dice/ante_config/DiceAnteConfig/index',
params
})
},
read(id: number | string) {
return request.get<Api.Common.ApiData>({
url: '/core/dice/ante_config/DiceAnteConfig/read?id=' + id
})
},
save(params: Record<string, unknown>) {
return request.post({
url: '/core/dice/ante_config/DiceAnteConfig/save',
data: params
})
},
update(params: Record<string, unknown>) {
return request.put({
url: '/core/dice/ante_config/DiceAnteConfig/update',
data: params
})
},
delete(params: Record<string, unknown>) {
return request.del({
url: '/core/dice/ante_config/DiceAnteConfig/destroy',
data: params
})
}
}