[色子游戏]配置
This commit is contained in:
65
saiadmin-artd/src/views/plugin/dice/api/config/index.ts
Normal file
65
saiadmin-artd/src/views/plugin/dice/api/config/index.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import request from '@/utils/http'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 摇色子配置 API接口
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
/**
|
||||||
|
* 获取数据列表
|
||||||
|
* @param params 搜索参数
|
||||||
|
* @returns 数据列表
|
||||||
|
*/
|
||||||
|
list(params: Record<string, any>) {
|
||||||
|
return request.get<Api.Common.ApiPage>({
|
||||||
|
url: '/dice/config/DiceConfig/index',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取数据
|
||||||
|
* @param id 数据ID
|
||||||
|
* @returns 数据详情
|
||||||
|
*/
|
||||||
|
read(id: number | string) {
|
||||||
|
return request.get<Api.Common.ApiData>({
|
||||||
|
url: '/dice/config/DiceConfig/read?id=' + id
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建数据
|
||||||
|
* @param params 数据参数
|
||||||
|
* @returns 执行结果
|
||||||
|
*/
|
||||||
|
save(params: Record<string, any>) {
|
||||||
|
return request.post<any>({
|
||||||
|
url: '/dice/config/DiceConfig/save',
|
||||||
|
data: params
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新数据
|
||||||
|
* @param params 数据参数
|
||||||
|
* @returns 执行结果
|
||||||
|
*/
|
||||||
|
update(params: Record<string, any>) {
|
||||||
|
return request.put<any>({
|
||||||
|
url: '/dice/config/DiceConfig/update',
|
||||||
|
data: params
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除数据
|
||||||
|
* @param id 数据ID
|
||||||
|
* @returns 执行结果
|
||||||
|
*/
|
||||||
|
delete(params: Record<string, any>) {
|
||||||
|
return request.del<any>({
|
||||||
|
url: '/dice/config/DiceConfig/destroy',
|
||||||
|
data: params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
132
saiadmin-artd/src/views/plugin/dice/config/index/index.vue
Normal file
132
saiadmin-artd/src/views/plugin/dice/config/index/index.vue
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
<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:config:index:save'" @click="showDialog('add')" v-ripple>-->
|
||||||
|
<!-- <template #icon>-->
|
||||||
|
<!-- <ArtSvgIcon icon="ri:add-fill" />-->
|
||||||
|
<!-- </template>-->
|
||||||
|
<!-- 新增-->
|
||||||
|
<!-- </ElButton>-->
|
||||||
|
<!-- <ElButton-->
|
||||||
|
<!-- v-permission="'dice:config:index:destroy'"-->
|
||||||
|
<!-- :disabled="selectedRows.length === 0"-->
|
||||||
|
<!-- @click="deleteSelectedRows(api.delete, refreshData)"-->
|
||||||
|
<!-- v-ripple-->
|
||||||
|
<!-- >-->
|
||||||
|
<!-- <template #icon>-->
|
||||||
|
<!-- <ArtSvgIcon icon="ri:delete-bin-5-line" />-->
|
||||||
|
<!-- </template>-->
|
||||||
|
<!-- 删除-->
|
||||||
|
<!-- </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 #operation="{ row }">
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<SaButton
|
||||||
|
v-permission="'dice:config:index:update'"
|
||||||
|
type="secondary"
|
||||||
|
@click="showDialog('edit', row)"
|
||||||
|
/>
|
||||||
|
<!-- <SaButton-->
|
||||||
|
<!-- v-permission="'dice: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/config/index'
|
||||||
|
import TableSearch from './modules/table-search.vue'
|
||||||
|
import EditDialog from './modules/edit-dialog.vue'
|
||||||
|
|
||||||
|
// 搜索表单
|
||||||
|
const searchForm = ref({
|
||||||
|
group: undefined,
|
||||||
|
title: undefined,
|
||||||
|
name: undefined
|
||||||
|
})
|
||||||
|
|
||||||
|
// 搜索处理
|
||||||
|
const handleSearch = (params: Record<string, any>) => {
|
||||||
|
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: 'group', label: '分组', minWidth: 140 },
|
||||||
|
{ prop: 'title', label: '标题', minWidth: 160 },
|
||||||
|
{ prop: 'name', label: '配置名称' },
|
||||||
|
{ prop: 'value', label: '值', minWidth: 240 },
|
||||||
|
{ prop: 'operation', label: '操作', width: 100, fixed: 'right', useSlot: true }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 编辑配置
|
||||||
|
const {
|
||||||
|
dialogType,
|
||||||
|
dialogVisible,
|
||||||
|
dialogData,
|
||||||
|
showDialog,
|
||||||
|
deleteRow,
|
||||||
|
deleteSelectedRows,
|
||||||
|
handleSelectionChange,
|
||||||
|
selectedRows
|
||||||
|
} = useSaiAdmin()
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
v-model="visible"
|
||||||
|
:title="dialogType === 'add' ? '新增摇色子配置' : '编辑摇色子配置'"
|
||||||
|
width="600px"
|
||||||
|
align-center
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
@close="handleClose"
|
||||||
|
>
|
||||||
|
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
|
||||||
|
<el-form-item label="分组" prop="group">
|
||||||
|
<el-input v-model="formData.group" placeholder="请输入分组" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="标题" prop="title">
|
||||||
|
<el-input v-model="formData.title" placeholder="请输入标题" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="配置名称" prop="name">
|
||||||
|
<el-input v-model="formData.name" placeholder="请输入配置名称" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="值" prop="value">
|
||||||
|
<el-input v-model="formData.value" type="textarea" :rows="5" placeholder="请输入值" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="handleClose">取消</el-button>
|
||||||
|
<el-button type="primary" @click="handleSubmit">提交</el-button>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import api from '../../../api/config/index'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import type { FormInstance, FormRules } from 'element-plus'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
modelValue: boolean
|
||||||
|
dialogType: string
|
||||||
|
data?: Record<string, any>
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = reactive<FormRules>({
|
||||||
|
group: [{ required: true, message: '分组必需填写', trigger: 'blur' }],
|
||||||
|
title: [{ required: true, message: '标题必需填写', trigger: 'blur' }],
|
||||||
|
name: [{ required: true, message: '配置名称必需填写', trigger: 'blur' }],
|
||||||
|
value: [{ required: true, message: '值必需填写', trigger: 'blur' }]
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始数据
|
||||||
|
*/
|
||||||
|
const initialFormData = {
|
||||||
|
id: null,
|
||||||
|
value: '',
|
||||||
|
name: '',
|
||||||
|
group: '',
|
||||||
|
title: ''
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表单数据
|
||||||
|
*/
|
||||||
|
const formData = reactive({ ...initialFormData })
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监听弹窗打开,初始化表单数据
|
||||||
|
*/
|
||||||
|
watch(
|
||||||
|
() => props.modelValue,
|
||||||
|
(newVal) => {
|
||||||
|
if (newVal) {
|
||||||
|
initPage()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化页面数据
|
||||||
|
*/
|
||||||
|
const initPage = async () => {
|
||||||
|
// 先重置为初始值
|
||||||
|
Object.assign(formData, initialFormData)
|
||||||
|
// 如果有数据,则填充数据
|
||||||
|
if (props.data) {
|
||||||
|
await nextTick()
|
||||||
|
initForm()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化表单数据
|
||||||
|
*/
|
||||||
|
const initForm = () => {
|
||||||
|
if (props.data) {
|
||||||
|
for (const key in formData) {
|
||||||
|
if (props.data[key] != null && props.data[key] != undefined) {
|
||||||
|
;(formData as any)[key] = props.data[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭弹窗并重置表单
|
||||||
|
*/
|
||||||
|
const handleClose = () => {
|
||||||
|
visible.value = false
|
||||||
|
formRef.value?.resetFields()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交表单
|
||||||
|
*/
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
if (!formRef.value) return
|
||||||
|
try {
|
||||||
|
await formRef.value.validate()
|
||||||
|
if (props.dialogType === 'add') {
|
||||||
|
await api.save(formData)
|
||||||
|
ElMessage.success('新增成功')
|
||||||
|
} else {
|
||||||
|
await api.update(formData)
|
||||||
|
ElMessage.success('修改成功')
|
||||||
|
}
|
||||||
|
emit('success')
|
||||||
|
handleClose()
|
||||||
|
} catch (error) {
|
||||||
|
console.log('表单验证失败:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
<template>
|
||||||
|
<sa-search-bar
|
||||||
|
ref="searchBarRef"
|
||||||
|
v-model="formData"
|
||||||
|
label-width="100px"
|
||||||
|
:showExpand="false"
|
||||||
|
@reset="handleReset"
|
||||||
|
@search="handleSearch"
|
||||||
|
@expand="handleExpand"
|
||||||
|
>
|
||||||
|
<el-col v-bind="setSpan(6)">
|
||||||
|
<el-form-item label="分组" prop="group">
|
||||||
|
<el-input v-model="formData.group" placeholder="请输入分组" clearable />
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col v-bind="setSpan(6)">
|
||||||
|
<el-form-item label="标题" prop="title">
|
||||||
|
<el-input v-model="formData.title" placeholder="请输入标题" clearable />
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col v-bind="setSpan(6)">
|
||||||
|
<el-form-item label="配置名称" prop="name">
|
||||||
|
<el-input v-model="formData.name" placeholder="请输入配置名称" clearable />
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
</sa-search-bar>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
interface Props {
|
||||||
|
modelValue: Record<string, any>
|
||||||
|
}
|
||||||
|
interface Emits {
|
||||||
|
(e: 'update:modelValue', value: Record<string, any>): void
|
||||||
|
(e: 'search', params: Record<string, any>): void
|
||||||
|
(e: 'reset'): void
|
||||||
|
}
|
||||||
|
const props = defineProps<Props>()
|
||||||
|
const emit = defineEmits<Emits>()
|
||||||
|
// 展开/收起
|
||||||
|
const isExpanded = ref<boolean>(false)
|
||||||
|
|
||||||
|
// 表单数据双向绑定
|
||||||
|
const searchBarRef = ref()
|
||||||
|
const formData = computed({
|
||||||
|
get: () => props.modelValue,
|
||||||
|
set: (val) => emit('update:modelValue', val)
|
||||||
|
})
|
||||||
|
|
||||||
|
// 重置
|
||||||
|
function handleReset() {
|
||||||
|
searchBarRef.value?.ref.resetFields()
|
||||||
|
emit('reset')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 搜索
|
||||||
|
async function handleSearch() {
|
||||||
|
emit('search', formData.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 展开/收起
|
||||||
|
function handleExpand(expanded: boolean) {
|
||||||
|
isExpanded.value = expanded
|
||||||
|
}
|
||||||
|
|
||||||
|
// 栅格占据的列数
|
||||||
|
const setSpan = (span: number) => {
|
||||||
|
return {
|
||||||
|
span: span,
|
||||||
|
xs: 24, // 手机:满宽显示
|
||||||
|
sm: span >= 12 ? span : 12, // 平板:大于等于12保持,否则用半宽
|
||||||
|
md: span >= 8 ? span : 8, // 中等屏幕:大于等于8保持,否则用三分之一宽
|
||||||
|
lg: span,
|
||||||
|
xl: span
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
123
server/app/dice/controller/config/DiceConfigController.php
Normal file
123
server/app/dice/controller/config/DiceConfigController.php
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | saiadmin [ saiadmin快速开发框架 ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: your name
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
namespace app\dice\controller\config;
|
||||||
|
|
||||||
|
use plugin\saiadmin\basic\BaseController;
|
||||||
|
use app\dice\logic\config\DiceConfigLogic;
|
||||||
|
use app\dice\validate\config\DiceConfigValidate;
|
||||||
|
use plugin\saiadmin\service\Permission;
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 摇色子配置控制器
|
||||||
|
*/
|
||||||
|
class DiceConfigController extends BaseController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 构造函数
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->logic = new DiceConfigLogic();
|
||||||
|
$this->validate = new DiceConfigValidate;
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据列表
|
||||||
|
* @param Request $request
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
#[Permission('摇色子配置列表', 'dice:config:index:index')]
|
||||||
|
public function index(Request $request): Response
|
||||||
|
{
|
||||||
|
$where = $request->more([
|
||||||
|
['name', ''],
|
||||||
|
['group', ''],
|
||||||
|
['title', ''],
|
||||||
|
]);
|
||||||
|
$query = $this->logic->search($where);
|
||||||
|
$data = $this->logic->getList($query);
|
||||||
|
return $this->success($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取数据
|
||||||
|
* @param Request $request
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
#[Permission('摇色子配置读取', 'dice:config:index:read')]
|
||||||
|
public function read(Request $request): Response
|
||||||
|
{
|
||||||
|
$id = $request->input('id', '');
|
||||||
|
$model = $this->logic->read($id);
|
||||||
|
if ($model) {
|
||||||
|
$data = is_array($model) ? $model : $model->toArray();
|
||||||
|
return $this->success($data);
|
||||||
|
} else {
|
||||||
|
return $this->fail('未查找到信息');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存数据
|
||||||
|
* @param Request $request
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
#[Permission('摇色子配置添加', 'dice:config:index:save')]
|
||||||
|
public function save(Request $request): Response
|
||||||
|
{
|
||||||
|
$data = $request->post();
|
||||||
|
$this->validate('save', $data);
|
||||||
|
$result = $this->logic->add($data);
|
||||||
|
if ($result) {
|
||||||
|
return $this->success('添加成功');
|
||||||
|
} else {
|
||||||
|
return $this->fail('添加失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新数据
|
||||||
|
* @param Request $request
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
#[Permission('摇色子配置修改', 'dice:config:index:update')]
|
||||||
|
public function update(Request $request): Response
|
||||||
|
{
|
||||||
|
$data = $request->post();
|
||||||
|
$this->validate('update', $data);
|
||||||
|
$result = $this->logic->edit($data['id'], $data);
|
||||||
|
if ($result) {
|
||||||
|
return $this->success('修改成功');
|
||||||
|
} else {
|
||||||
|
return $this->fail('修改失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除数据
|
||||||
|
* @param Request $request
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
#[Permission('摇色子配置删除', 'dice:config:index:destroy')]
|
||||||
|
public function destroy(Request $request): Response
|
||||||
|
{
|
||||||
|
$ids = $request->post('ids', '');
|
||||||
|
if (empty($ids)) {
|
||||||
|
return $this->fail('请选择要删除的数据');
|
||||||
|
}
|
||||||
|
$result = $this->logic->destroy($ids);
|
||||||
|
if ($result) {
|
||||||
|
return $this->success('删除成功');
|
||||||
|
} else {
|
||||||
|
return $this->fail('删除失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
27
server/app/dice/logic/config/DiceConfigLogic.php
Normal file
27
server/app/dice/logic/config/DiceConfigLogic.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | saiadmin [ saiadmin快速开发框架 ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: your name
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
namespace app\dice\logic\config;
|
||||||
|
|
||||||
|
use plugin\saiadmin\basic\eloquent\BaseLogic;
|
||||||
|
use plugin\saiadmin\exception\ApiException;
|
||||||
|
use plugin\saiadmin\utils\Helper;
|
||||||
|
use app\dice\model\config\DiceConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 摇色子配置逻辑层
|
||||||
|
*/
|
||||||
|
class DiceConfigLogic extends BaseLogic
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 构造函数
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->model = new DiceConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
75
server/app/dice/model/config/DiceConfig.php
Normal file
75
server/app/dice/model/config/DiceConfig.php
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | saiadmin [ saiadmin快速开发框架 ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: your name
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
namespace app\dice\model\config;
|
||||||
|
|
||||||
|
use plugin\saiadmin\basic\eloquent\BaseModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 摇色子配置模型
|
||||||
|
*
|
||||||
|
* dice_config 摇色子配置
|
||||||
|
*
|
||||||
|
* @property $id ID
|
||||||
|
* @property $name 配置名称
|
||||||
|
* @property $group 分组
|
||||||
|
* @property $title 标题
|
||||||
|
* @property $value 值
|
||||||
|
* @property $create_time 创建时间
|
||||||
|
* @property $update_time 修改时间
|
||||||
|
*/
|
||||||
|
class DiceConfig extends BaseModel
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 数据表主键
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库表名称
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'dice_config';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 属性转换
|
||||||
|
*/
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return array_merge(parent::casts(), [
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 配置名称 搜索
|
||||||
|
*/
|
||||||
|
public function searchNameAttr($query, $value)
|
||||||
|
{
|
||||||
|
$query->where('name', 'like', '%'.$value.'%');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组 搜索
|
||||||
|
*/
|
||||||
|
public function searchGroupAttr($query, $value)
|
||||||
|
{
|
||||||
|
if ($value === '' || $value === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$query->where('group', '=', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标题 搜索
|
||||||
|
*/
|
||||||
|
public function searchTitleAttr($query, $value)
|
||||||
|
{
|
||||||
|
if ($value === '' || $value === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$query->where('title', 'like', '%' . $value . '%');
|
||||||
|
}
|
||||||
|
}
|
||||||
54
server/app/dice/validate/config/DiceConfigValidate.php
Normal file
54
server/app/dice/validate/config/DiceConfigValidate.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | saiadmin [ saiadmin快速开发框架 ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: your name
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
namespace app\dice\validate\config;
|
||||||
|
|
||||||
|
use plugin\saiadmin\basic\BaseValidate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 摇色子配置验证器
|
||||||
|
*/
|
||||||
|
class DiceConfigValidate extends BaseValidate
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义验证规则
|
||||||
|
*/
|
||||||
|
protected $rule = [
|
||||||
|
'name' => 'require',
|
||||||
|
'group' => 'require',
|
||||||
|
'title' => 'require',
|
||||||
|
'value' => 'require',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定义错误信息
|
||||||
|
*/
|
||||||
|
protected $message = [
|
||||||
|
'name' => '配置名称必须填写',
|
||||||
|
'group' => '分组必须填写',
|
||||||
|
'title' => '标题必须填写',
|
||||||
|
'value' => '值必须填写',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定义场景
|
||||||
|
*/
|
||||||
|
protected $scene = [
|
||||||
|
'save' => [
|
||||||
|
'name',
|
||||||
|
'group',
|
||||||
|
'title',
|
||||||
|
'value',
|
||||||
|
],
|
||||||
|
'update' => [
|
||||||
|
'name',
|
||||||
|
'group',
|
||||||
|
'title',
|
||||||
|
'value',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user