Skip to content

Commit

Permalink
更新2.0版本
Browse files Browse the repository at this point in the history
  • Loading branch information
lvyuedong committed Jun 15, 2022
1 parent 3f503ac commit 414a2f0
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 183 deletions.
72 changes: 36 additions & 36 deletions src/Controller/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ public function generate(Request $request)
$editRes = $this->createEditView($data, $controllerName);
$responseMessage .= ($editRes === true ? "edit视图生成成功\n" : "$editRes\n") . '</br>';
$dir = Loader::parseName($controllerName);
$this->createMeta($showName, $dir);
$response['router'] = '<p>{title: \'' . $showName . '\',to: \'/' . $dir . '\'}</p>';
}
} else {
Expand Down Expand Up @@ -797,6 +796,7 @@ class {$controllerName} extends {$baseController}
protected \$cache = true; //是否使用缓存
protected \$modelName = '{$modelName}'; //模型名
protected \$indexField = [{$indexField}]; //查,字段名
protected \$listIndexField = [{$indexField}]; //查,字段名
protected \$addField = [{$addField}]; //增,字段名
protected \$editField = [{$editField}]; //改,字段名
/**
Expand All @@ -806,7 +806,9 @@ class {$controllerName} extends {$baseController}
* @var array
*/
protected \$searchField = [{$searchField}];
protected \$listSearchField = [];
protected \$orderField = '$orderField'; //排序字段
protected \$listOrderField = ''; //排序字段
protected \$pageLimit = 10; //分页数
//增,数据检测规则
Expand Down Expand Up @@ -846,9 +848,7 @@ private function createIndexView($data, $controllerName)
}

$searchHtml = '';
$searchRules = '';
$tableColumnsHtml = '';
$searchField = [];
$tpl = Config::get('curd.');
// dump($data['pageData']);exit();
foreach ($data['pageData'] as $k => $v) {
Expand All @@ -862,22 +862,22 @@ private function createIndexView($data, $controllerName)
$tmpTpl = $tpl['search'][$v['business']];
}
$searchHtml .= str_replace(['{{name}}', '{{label}}', '{{value}}'], [$v['name'], $v['label'], $v['name']], $tmpTpl) . "\n";
$searchRules .= "{$v['name']}: []" . "\n";
$searchField[$v['name']] = '';
}
}

$templatePath = Config::get('curd.index_template');
if (empty($templatePath)) {
$templatePath = __DIR__ . '/../Templates/index.vue';
$templatePath = __DIR__ . '/../Templates/index1.vue';
}
if (!file_exists($templatePath)) {
return '模板文件不存在:' . $templatePath;
}
$code = file_get_contents($templatePath);
$searchField = empty($searchField) ? '{}' : json_encode($searchField, JSON_UNESCAPED_UNICODE);
$componentName = "{$viewDirName}-index";
$code = str_replace(['{{ search_form }}', '{{ table_colum_html }}', '{{search_field}}', '{{controller_name}}', '{{component_name}}', '{{search_rules}}'], [$searchHtml, $tableColumnsHtml, $searchField, $viewDirName, $componentName, $searchRules], $code);
$toAddPath = '/' . $viewDirName . '/add';
$toEditPath = '/' . $viewDirName . '/edit';
$indexUrl = '/admin/' . $viewDirName . '/index';
$deleteUrl = '/admin/' . $viewDirName . '/delete';
$code = str_replace(['{{ search_form }}', '{{ to_add }}', '{{ to_edit }}', '{{ table_colum_html }}', '{{ index_url }}', '{{ delete_url }}'], [$searchHtml, $toAddPath, $toEditPath, $tableColumnsHtml, $indexUrl, $deleteUrl], $code);
$this->createPath($viewDir);
file_put_contents($viewPath, $code);
return true;
Expand Down Expand Up @@ -923,15 +923,15 @@ private function createAddView($data, $controllerName)
}
$templatePath = Config::get('curd.add_template');
if (empty($templatePath)) {
$templatePath = __DIR__ . '/../Templates/add.vue';
$templatePath = __DIR__ . '/../Templates/add1.vue';
}
if (!file_exists($templatePath)) {
return '模板文件不存在:' . $templatePath;
}
$code = file_get_contents($templatePath);
$formField = empty($formField) ? '{}' : json_encode($formField, JSON_UNESCAPED_UNICODE);
$componentName = "{$viewDirName}-add";
$code = str_replace(['{{ curd_form_group }}', '{{curd_form_field}}', '{{controller_name}}', '{{component_name}}'], [$html, $formField, $viewDirName, $componentName], $code);
$savePath = '/admin/' . $viewDirName . '/add';
$code = str_replace(['{{ curd_form_group }}', '{{curd_form_field}}', '{{ save_url}}'], [$html, $formField, $savePath], $code);
$this->createPath($viewDir);
file_put_contents($viewPath, $code);
return true;
Expand Down Expand Up @@ -985,35 +985,35 @@ private function createEditView($data, $controllerName)
}
$code = file_get_contents($templatePath);
$formField = empty($formField) ? '{}' : json_encode($formField, JSON_UNESCAPED_UNICODE);
$componentName = "{$viewDirName}-edit";
$code = str_replace(['{{ curd_form_group }}', '{{curd_form_field}}', '{{controller_name}}', '{{component_name}}'], [$html, $formField, $viewDirName, $componentName], $code);
$savePath = '/admin/' . $viewDirName . '/edit';
$code = str_replace(['{{ curd_form_group }}', '{{curd_form_field}}', '{{ save_path }}'], [$html, $formField, $savePath], $code);
$this->createPath($viewDir);
file_put_contents($viewPath, $code);
return true;
}

private function createMeta($showName, $dir)
{
if (!empty($this->config['view_root'])) {
$viewDir = $this->config['view_root'] . "/{$dir}/";
$viewPath = $viewDir . 'meta.json';
} else {
return '配置错误';
}
if (file_exists($viewPath)) {
return 'meta.json文件已存在';
}
$meta = <<<META
{
"index": "{$showName}",
"add": "添加{$showName}",
"edit": "修改{$showName}"
}
META;
$this->createPath($viewDir);
file_put_contents($viewPath, $meta);
return true;
}
// private function createMeta($showName, $dir)
// {
// if (!empty($this->config['view_root'])) {
// $viewDir = $this->config['view_root'] . "/{$dir}/";
// $viewPath = $viewDir . 'meta.json';
// } else {
// return '配置错误';
// }
// if (file_exists($viewPath)) {
// return 'meta.json文件已存在';
// }
// $meta = <<<META
//{
// "index": "{$showName}",
// "add": "添加{$showName}",
// "edit": "修改{$showName}"
//}
//META;
// $this->createPath($viewDir);
// file_put_contents($viewPath, $meta);
// return true;
// }

/**
* 生成模型
Expand Down
21 changes: 7 additions & 14 deletions src/Controller/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<head>
<meta charset="UTF-8" />
<title>ThinkPHP代码生成工具</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js"></script>
<link rel="stylesheet" href="//unpkg.com/iview/dist/styles/iview.css" />
<script src="https://unpkg.com/iview@3.4.2/dist/iview.min.js"></script>
<script src="https://unpkg.com/axios@0.19.0/dist/axios.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.min.js"></script>
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/iview/3.5.4/styles/iview.css" />
<script src="https://cdn.bootcdn.net/ajax/libs/iview/3.5.4/iview.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.min.js"></script>
<style>
.header {
color: white;
Expand Down Expand Up @@ -70,16 +70,6 @@ <h3>代码生成工具</h3>
></Checkbox>
</checkbox-group>
</div>
<div
style="margin-bottom: 20px"
v-if="create.fruit.includes('视图') && create.selectVal == '后台'"
>
<radio-group v-model="create.view_type">
创建:
<Radio label="跳页"></Radio>
<Radio label="弹窗"></Radio>
</radio-group>
</div>
<div style="margin-bottom: 20px">
控制器名称:
<i-input
Expand Down Expand Up @@ -156,6 +146,9 @@ <h3>代码生成工具</h3>
<i-option value="uploadImage">上传图片</i-option>
<i-option value="ueditor">富文本编辑器</i-option>
<i-option value="textarea">多行文本</i-option>
<i-option value="radio">单选</i-option>
<i-option value="checkbox">多选</i-option>
<i-option value="switch">开关</i-option>
</i-select>
</template>
<template slot-scope="{ row, index }" slot="sort">
Expand Down
58 changes: 26 additions & 32 deletions src/Templates/add.vue
Original file line number Diff line number Diff line change
@@ -1,42 +1,36 @@
<template>
<v-content>
<el-form
:model="formData"
:rules="rules"
class="el-form"
ref="form"
label-position="right"
label-width="80px"
>
<el-form :rules="rules" ref="form" :model="formData">
{{ curd_form_group }}
<el-form-item>
<el-button type="primary" @click="submit">保存</el-button>
</el-form-item>
</el-form>
<template #footer>
<el-button v-ripple type="danger" icon="Back" @click="toPage(-1)">返回</el-button>
<el-button v-ripple type="warning" icon="Delete" :disabled="disabled" @click="deleteTemporary">
删除暂存数据
</el-button>
<el-button
v-ripple
:loading="temporaryLoading"
type="primary"
icon="Brush"
:disabled="disabled"
@click="temporary"
>
暂存
</el-button>
<el-button v-ripple :loading="loading" type="success" icon="Check" :disabled="disabled" @click="submit">
保存
</el-button>
</template>
</v-content>
</template>

<script>
import { defineComponent } from "vue"
import addMixin from "/add"
export default defineComponent({
mixins: [addMixin],
data() {
return {
module: '{{controller_name}}',
formData: {{curd_form_field}},
rules: {},
}
},
methods: {},
<script setup>
const rules = {}
const {toPage, loading, temporaryLoading, disabled, form, formData, submit, temporary, deleteTemporary } = useAdd({
submitUrl: "{{ save_url}}",
formData: {{curd_form_field}},
})
</script>

<style lang="scss" scoped>
.el-form-item {
&.input {
width: 780px;
}
}
</style>
<style lang="scss" scoped></style>
59 changes: 27 additions & 32 deletions src/Templates/edit.vue
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
<template>
<v-content>
<el-form
:model="formData"
:rules="rules"
class="el-form"
ref="form"
label-position="right"
label-width="80px"
>
<el-form :rules="rules" ref="form" :model="formData">
{{ curd_form_group }}
<el-form-item>
<el-button type="primary" @click="submit">保存</el-button>
</el-form-item>
</el-form>
<template #footer>
<el-button v-ripple type="danger" icon="Back" @click="toPage(-1)">返回</el-button>
<el-button v-ripple type="warning" icon="Delete" :disabled="disabled" @click="deleteTemporary">
删除暂存数据
</el-button>
<el-button
v-ripple
:loading="temporaryLoading"
type="primary"
icon="Brush"
:disabled="disabled"
@click="temporary"
>
暂存
</el-button>
<el-button v-ripple :loading="loading" type="success" icon="Check" :disabled="disabled" @click="submit">
保存
</el-button>
</template>
</v-content>
</template>

<script>
import { defineComponent } from "vue"
import editMixin from "/edit"
export default defineComponent({
mixins: [editMixin],
data() {
return {
module: '{{controller_name}}',
formData: {{curd_form_field}},
rules: {},
}
},
methods: {},
<script setup>
const rules = {}
const { toPage,loading, temporaryLoading, disabled, form, formData, submit, temporary, deleteTemporary } = useEdit({
url: "/demo/tmpDemoGenerate/info",
submitUrl: "/demo/tmpDemoGenerate/edit",
formData: {{curd_form_field}},
})
</script>

<style lang="scss" scoped>
.el-form-item {
&.input {
width: 780px;
}
}
</style>
<style lang="scss" scoped></style>

0 comments on commit 414a2f0

Please sign in to comment.