fix: 修改生成
This commit is contained in:
parent
5d946ed3de
commit
d9e8c59651
@ -273,6 +273,7 @@ class Gen extends BaseController
|
|||||||
'className' => $params['className'],
|
'className' => $params['className'],
|
||||||
'tplCategory' => $params['tplCategory'],
|
'tplCategory' => $params['tplCategory'],
|
||||||
'moduleName' => $params['moduleName'],
|
'moduleName' => $params['moduleName'],
|
||||||
|
'isSort' => $params['isSort'],
|
||||||
'businessName' => $params['businessName'],
|
'businessName' => $params['businessName'],
|
||||||
'functionName' => $params['functionName'],
|
'functionName' => $params['functionName'],
|
||||||
'functionAuthor' => $params['functionAuthor'],
|
'functionAuthor' => $params['functionAuthor'],
|
||||||
@ -414,9 +415,9 @@ class Gen extends BaseController
|
|||||||
// 'tplCategory' => $tableInfo['tplCategory'],
|
// 'tplCategory' => $tableInfo['tplCategory'],
|
||||||
'tableName' => $tableInfo['Name'],
|
'tableName' => $tableInfo['Name'],
|
||||||
'tableComment' => $tableInfo['Comment'],
|
'tableComment' => $tableInfo['Comment'],
|
||||||
'className' => Tool::camelize($tableInfo['Name'],true),
|
'className' => Tool::camelize($tableInfo['Name'], true),
|
||||||
'businessName' => $tableInfo['Name'],
|
'businessName' => $tableInfo['Name'],
|
||||||
'moduleName' => Tool::camelize($tableInfo['Name'],true),
|
'moduleName' => Tool::camelize($tableInfo['Name'], true),
|
||||||
'functionName' => $tableInfo['Comment'],
|
'functionName' => $tableInfo['Comment'],
|
||||||
'functionAuthor' => 'admin',
|
'functionAuthor' => 'admin',
|
||||||
'genType' => 1,
|
'genType' => 1,
|
||||||
@ -633,8 +634,7 @@ class Gen extends BaseController
|
|||||||
if ($val['htmlType'] == 'fileUpload') $is_file_upload = true;
|
if ($val['htmlType'] == 'fileUpload') $is_file_upload = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($isSort){
|
if ($isSort) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//打开模板文件资源(只读)
|
//打开模板文件资源(只读)
|
||||||
@ -704,7 +704,7 @@ class Gen extends BaseController
|
|||||||
} else if ($table['tplCategory'] == "web_static") {
|
} else if ($table['tplCategory'] == "web_static") {
|
||||||
$temp_path = str_replace('/', DIRECTORY_SEPARATOR, "{$root}resources/view/business/webApiController.tpl");
|
$temp_path = str_replace('/', DIRECTORY_SEPARATOR, "{$root}resources/view/business/webApiController.tpl");
|
||||||
}
|
}
|
||||||
|
|
||||||
//控制器生成后的路径构建
|
//控制器生成后的路径构建
|
||||||
$gen_path = str_replace('/', DIRECTORY_SEPARATOR, "{$root}api/controller/{$module_name}/{$class_name}.php");
|
$gen_path = str_replace('/', DIRECTORY_SEPARATOR, "{$root}api/controller/{$module_name}/{$class_name}.php");
|
||||||
|
|
||||||
@ -777,7 +777,7 @@ class Gen extends BaseController
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Js版本 1.20
|
// Js版本 1.30
|
||||||
|
|
||||||
//生成JsVue页面
|
//生成JsVue页面
|
||||||
private function createJsVue($fields, $table)
|
private function createJsVue($fields, $table)
|
||||||
@ -810,6 +810,39 @@ class Gen extends BaseController
|
|||||||
$dict = '';
|
$dict = '';
|
||||||
$dictScope = '';
|
$dictScope = '';
|
||||||
$query = '';
|
$query = '';
|
||||||
|
$sortTemplate = '';
|
||||||
|
$sortTemplateFun = '';
|
||||||
|
$switchTemplate = '';
|
||||||
|
$switchTemplateFun = '';
|
||||||
|
|
||||||
|
$isSort = $table['isSort']; // 排序处理
|
||||||
|
foreach ($fields as $value) {
|
||||||
|
$columnName = $value['columnName'];
|
||||||
|
$className = $table['className'];
|
||||||
|
|
||||||
|
if ($isSort == 1) {
|
||||||
|
$sortTemplate = "
|
||||||
|
<!-- 排序 -->
|
||||||
|
<template #{$columnName}='scope'>
|
||||||
|
<el-input-number :disabled='loading' v-model='scope.row.{$columnName}' :min='1' controls-position='right'
|
||||||
|
@change='handleEditOrder(scope.row)'></el-input-number>
|
||||||
|
</template>
|
||||||
|
";
|
||||||
|
|
||||||
|
$sortTemplateFun = "
|
||||||
|
//排序
|
||||||
|
const loading = ref(false)
|
||||||
|
async function handleEditOrder(data) {
|
||||||
|
loading.value = true
|
||||||
|
const { code } = await edit{$className}(data);
|
||||||
|
if (code == 0) {
|
||||||
|
loading.value = false
|
||||||
|
tableRef.value.reload()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$btn_arr = $table['options']->CheckedBtn; // 勾选按钮
|
$btn_arr = $table['options']->CheckedBtn; // 勾选按钮
|
||||||
// return $btn_arr;
|
// return $btn_arr;
|
||||||
@ -947,7 +980,39 @@ class Gen extends BaseController
|
|||||||
<template v-else>暂无图片</template>
|
<template v-else>暂无图片</template>
|
||||||
</template>';
|
</template>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($value['htmlType'] == 'switch') {
|
||||||
|
$switchTemplate = "
|
||||||
|
<el-switch
|
||||||
|
:disabled=scope.row.{$value['columnName']}_bool
|
||||||
|
v-model=scope.row.{$value['columnName']}
|
||||||
|
class=mt-2
|
||||||
|
inline-prompt
|
||||||
|
:inactive-value=1
|
||||||
|
:active-value=2
|
||||||
|
style='--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949'
|
||||||
|
@click=handleEditShow(scope.row)
|
||||||
|
/>
|
||||||
|
";
|
||||||
|
|
||||||
|
$switchTemplateFun = "
|
||||||
|
// 展示切换
|
||||||
|
async function handleEditShow(data) {
|
||||||
|
if(data.{$value['columnName']} === 1) return;
|
||||||
|
|
||||||
|
loading.value = true
|
||||||
|
const { code } = await edit{$table['className']}(data);
|
||||||
|
if (code == 0) {
|
||||||
|
loading.value = false
|
||||||
|
tableRef.value.reload()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$columnsArr .= "
|
$columnsArr .= "
|
||||||
{
|
{
|
||||||
label: '操作',
|
label: '操作',
|
||||||
@ -956,7 +1021,6 @@ class Gen extends BaseController
|
|||||||
fixed: 'right'
|
fixed: 'right'
|
||||||
}";
|
}";
|
||||||
|
|
||||||
// return $imgTemplate;
|
|
||||||
|
|
||||||
// //模型的示例代码
|
// //模型的示例代码
|
||||||
$temp_path = str_replace('/', DIRECTORY_SEPARATOR, $root . 'resources/view/jsVue/index.tpl');
|
$temp_path = str_replace('/', DIRECTORY_SEPARATOR, $root . 'resources/view/jsVue/index.tpl');
|
||||||
@ -978,7 +1042,11 @@ class Gen extends BaseController
|
|||||||
'${btnFunName}',
|
'${btnFunName}',
|
||||||
'${btnFun}',
|
'${btnFun}',
|
||||||
'${query}',
|
'${query}',
|
||||||
'${dictScope}'
|
'${dictScope}',
|
||||||
|
'${sortTemplate}',
|
||||||
|
'${sortTemplateFun}',
|
||||||
|
'${switchTemplate}',
|
||||||
|
'${switchTemplateFun}',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
$table['functionName'],
|
$table['functionName'],
|
||||||
@ -994,7 +1062,11 @@ class Gen extends BaseController
|
|||||||
$btnFunName,
|
$btnFunName,
|
||||||
$btnFun,
|
$btnFun,
|
||||||
$query,
|
$query,
|
||||||
$dictScope
|
$dictScope,
|
||||||
|
$sortTemplate,
|
||||||
|
$sortTemplateFun,
|
||||||
|
$switchTemplate,
|
||||||
|
$switchTemplateFun,
|
||||||
],
|
],
|
||||||
$temp_str
|
$temp_str
|
||||||
);
|
);
|
||||||
@ -1750,7 +1822,7 @@ class Gen extends BaseController
|
|||||||
$col .= '
|
$col .= '
|
||||||
<el-col :span="12">
|
<el-col :span="12">
|
||||||
<el-form-item :label-width="labelWidth" label="' . $value['columnComment'] . '" prop="' . $value['columnName'] . '">' . '
|
<el-form-item :label-width="labelWidth" label="' . $value['columnComment'] . '" prop="' . $value['columnName'] . '">' . '
|
||||||
' . " <el-input-number v-model='formData." . $value['columnName'] . "' controls-position='right'></el-input-number>
|
' . " <el-input-number v-model='formData." . $value['columnName'] . "' controls-position='right' :min='1'></el-input-number>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>";
|
</el-col>";
|
||||||
}
|
}
|
||||||
@ -1763,6 +1835,31 @@ class Gen extends BaseController
|
|||||||
</el-col>
|
</el-col>
|
||||||
";
|
";
|
||||||
}
|
}
|
||||||
|
if ($value['htmlType'] == "switch") {
|
||||||
|
$col .= "
|
||||||
|
<el-col :span='12'>
|
||||||
|
<el-form-item :label-width='labelWidth' label='{$value['columnComment']}' prop='{$value['columnName']}'>
|
||||||
|
<el-switch
|
||||||
|
v-model='formData.{$value['columnName']}'
|
||||||
|
class='mt-2'
|
||||||
|
inline-prompt
|
||||||
|
:inactive-value=1
|
||||||
|
:active-value=2
|
||||||
|
style='--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949'
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
if ($value['htmlType'] == "rate") {
|
||||||
|
$col .= "
|
||||||
|
<el-col :span='12'>
|
||||||
|
<el-form-item :label-width='labelWidth' label='{$value['columnComment']}' prop='{$value['columnName']}'>
|
||||||
|
<el-rate style='padding-top: 6px!important;' v-model='formData.{$value['columnName']}' allow-half />
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
114
app/admin/controller/Test/Test.php
Normal file
114
app/admin/controller/Test/Test.php
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\controller\Test;
|
||||||
|
|
||||||
|
use app\BaseController;
|
||||||
|
use app\common\model\Test\Test as ModelTest;
|
||||||
|
use app\Request;
|
||||||
|
use think\Validate;
|
||||||
|
use think\exception\ValidateException;
|
||||||
|
use think\facade\Filesystem;
|
||||||
|
use app\common\arw\adjfut\src\Excel;
|
||||||
|
use app\common\arw\adjfut\src\UploadFile;
|
||||||
|
use app\common\exception\Tool;
|
||||||
|
use think\facade\Db;
|
||||||
|
use think\facade\Env;
|
||||||
|
|
||||||
|
|
||||||
|
class Test extends BaseController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 获取测试列表
|
||||||
|
*/
|
||||||
|
public function getTestList(Request $request): array
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$con = [];
|
||||||
|
|
||||||
|
$con = Tool::getOptionalQuery(['test_name','LIKE'],);
|
||||||
|
|
||||||
|
$query = ModelTest::where($con)
|
||||||
|
->field([
|
||||||
|
'test_id',
|
||||||
|
'test_guid',
|
||||||
|
'test_name',
|
||||||
|
'test_show_status',
|
||||||
|
'test_score',
|
||||||
|
'test_sort'
|
||||||
|
])
|
||||||
|
->order('test_sort', 'desc');
|
||||||
|
|
||||||
|
return msg("获取测试列表成功!",$query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑测试
|
||||||
|
*/
|
||||||
|
public function editTest(Request $request): array
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
|
'test_name|名称'=>'require',
|
||||||
|
'test_show_status|首页是否展示'=>'require',
|
||||||
|
'test_score|评分'=>'require',
|
||||||
|
'test_sort|排序'=>'require'
|
||||||
|
]);
|
||||||
|
$model = ModelTest::where('test_guid',$params['test_guid'])->find();
|
||||||
|
if (!$model) throwErrorMsg("该测试不存在", 1);
|
||||||
|
$model->allowField([
|
||||||
|
'test_update_user_guid',
|
||||||
|
'test_name',
|
||||||
|
'test_show_status',
|
||||||
|
'test_score',
|
||||||
|
'test_sort'
|
||||||
|
])->save($params);
|
||||||
|
return msg('编辑成功!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加测试
|
||||||
|
*/
|
||||||
|
public function addTest(Request $request): array
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
|
'test_name|名称'=>'require',
|
||||||
|
'test_show_status|首页是否展示'=>'require',
|
||||||
|
'test_score|评分'=>'require',
|
||||||
|
'test_sort|排序'=>'require'
|
||||||
|
]);
|
||||||
|
$model = ModelTest::create($params,[
|
||||||
|
'test_guid',
|
||||||
|
'test_create_user_guid',
|
||||||
|
'test_update_user_guid',
|
||||||
|
'test_name',
|
||||||
|
'test_show_status',
|
||||||
|
'test_score',
|
||||||
|
'test_sort'
|
||||||
|
]);
|
||||||
|
return msg('添加成功!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除测试
|
||||||
|
*/
|
||||||
|
public function deleteTest(Request $request): array
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
|
'test_guid' => 'require',
|
||||||
|
]);
|
||||||
|
$test = ModelTest::where([
|
||||||
|
'test_guid' => explode(',', $params['test_guid'])
|
||||||
|
])->select();
|
||||||
|
$test->delete();
|
||||||
|
return msg('删除成功!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
95
app/common/model/Test/Test.php
Normal file
95
app/common/model/Test/Test.php
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model\Test;
|
||||||
|
|
||||||
|
use app\common\arw\adjfut\src\Validate;
|
||||||
|
use app\BaseModel;
|
||||||
|
use think\model\concern\SoftDelete;
|
||||||
|
use app\common\arw\adjfut\src\Excel;
|
||||||
|
use app\Request;
|
||||||
|
use app\common\exception\Tool;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
|
class Test extends BaseModel
|
||||||
|
{
|
||||||
|
use SoftDelete;
|
||||||
|
// 删除字段
|
||||||
|
protected $deleteTime = 'test_delete_time';
|
||||||
|
// 设置主键名
|
||||||
|
protected $pk = 'test_guid';
|
||||||
|
// 设置废弃字段
|
||||||
|
protected $disuse = [];
|
||||||
|
// 设置字段信息
|
||||||
|
protected $schema = [
|
||||||
|
|
||||||
|
"test_id" => "int",
|
||||||
|
|
||||||
|
"test_guid" => "string",
|
||||||
|
|
||||||
|
"test_name" => "string",
|
||||||
|
|
||||||
|
"test_show_status" => "string",
|
||||||
|
|
||||||
|
"test_score" => "",
|
||||||
|
|
||||||
|
"test_sort" => "int",
|
||||||
|
|
||||||
|
"test_create_time" => "datetime",
|
||||||
|
|
||||||
|
"test_create_user_guid" => "string",
|
||||||
|
|
||||||
|
"test_update_time" => "datetime",
|
||||||
|
|
||||||
|
"test_update_user_guid" => "string",
|
||||||
|
|
||||||
|
"test_delete_time" => "datetime",
|
||||||
|
|
||||||
|
"test_delete_user_guid" => "string",
|
||||||
|
|
||||||
|
];
|
||||||
|
// 设置json类型字段
|
||||||
|
protected $json = [''];
|
||||||
|
// 开启自动写入时间戳字段
|
||||||
|
protected $autoWriteTimestamp = 'datetime';
|
||||||
|
// 创建时间
|
||||||
|
protected $createTime = 'test_create_time';
|
||||||
|
// 修改时间
|
||||||
|
protected $updateTime = 'test_update_time';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增前
|
||||||
|
*/
|
||||||
|
public static function onBeforeInsert(self $model): void
|
||||||
|
{
|
||||||
|
// self::checkRepeatData($model);
|
||||||
|
$model->completeCreateField();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新前
|
||||||
|
*/
|
||||||
|
public static function onBeforeUpdate(self $model): void
|
||||||
|
{
|
||||||
|
// self::checkRepeatData($model);
|
||||||
|
$model->completeUpdateField();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除前
|
||||||
|
*/
|
||||||
|
public static function onBeforeDelete(self $model): void
|
||||||
|
{
|
||||||
|
$model->completeDeleteField();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -39,6 +39,7 @@ const headers = {
|
|||||||
...store.headers,
|
...store.headers,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isBtnLod = ref(false);
|
||||||
const formRef = ref();
|
const formRef = ref();
|
||||||
const labelWidth = 90;
|
const labelWidth = 90;
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@ -76,18 +77,20 @@ const closeDialog = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleAddClick = async (formEl) => {
|
const handleAddClick = async (formEl) => {
|
||||||
console.log(formData);
|
|
||||||
if (!formEl) return;
|
if (!formEl) return;
|
||||||
formEl.validate(async (valid) => {
|
formEl.validate(async (valid) => {
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
isBtnLod.value = true;
|
||||||
|
|
||||||
${mapFun}
|
${mapFun}
|
||||||
const { code } = await add${className}(formData);
|
const { code } = await add${className}(formData);
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
closeDialog();
|
closeDialog();
|
||||||
props.done();
|
props.done();
|
||||||
}
|
}
|
||||||
|
isBtnLod.value = flase;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<span class="dialog-footer">
|
<span class="dialog-footer">
|
||||||
<el-button type="primary" @click="handleEditClick(formRef)">编辑</el-button>
|
<el-button type="primary" @click="handleEditClick(formRef)" :loading="isBtnLod">编辑</el-button>
|
||||||
<el-button @click="handleResetClick(formRef)">重置</el-button>
|
<el-button @click="handleResetClick(formRef)">重置</el-button>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
@ -37,6 +37,7 @@ const headers = {
|
|||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
...store.headers,
|
...store.headers,
|
||||||
};
|
};
|
||||||
|
const isBtnLod = ref(false);
|
||||||
const formRef = ref();
|
const formRef = ref();
|
||||||
const labelWidth = 100;
|
const labelWidth = 100;
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@ -81,12 +82,15 @@ const handleEditClick = async (formEl) => {
|
|||||||
if (!valid) {
|
if (!valid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
isBtnLod.value = true;
|
||||||
|
|
||||||
${mapFun}
|
${mapFun}
|
||||||
const { code } = await edit${className}(formData.value);
|
const { code } = await edit${className}(formData.value);
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
closeDialog();
|
closeDialog();
|
||||||
props.done();
|
props.done();
|
||||||
}
|
}
|
||||||
|
isBtnLod.value = false;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const handleResetClick = async (formEl) => {
|
const handleResetClick = async (formEl) => {
|
||||||
|
@ -47,6 +47,9 @@
|
|||||||
>
|
>
|
||||||
${imgTemplate}
|
${imgTemplate}
|
||||||
${dictScope}
|
${dictScope}
|
||||||
|
${sortTemplate}
|
||||||
|
${switchTemplate}
|
||||||
|
|
||||||
<template #chaoz="scope">
|
<template #chaoz="scope">
|
||||||
<el-space>
|
<el-space>
|
||||||
<el-button size="small" @click="handleUpdate(scope.row)">
|
<el-button size="small" @click="handleUpdate(scope.row)">
|
||||||
@ -148,6 +151,8 @@ function handleDetail(row) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
${btnFun}
|
${btnFun}
|
||||||
|
${sortTemplateFun}
|
||||||
|
${switchTemplateFun}
|
||||||
|
|
||||||
${dict}
|
${dict}
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user