From 959fa6687cf6df425b603247db8d3722ab2ede2b Mon Sep 17 00:00:00 2001 From: wolfcode <37436228+wolf-leo@users.noreply.github.com> Date: Fri, 1 Dec 2023 00:03:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96CURD=E5=8F=AF=E8=A7=86?= =?UTF-8?q?=E5=8C=96=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/system/CurdGenerate.php | 10 +++- .../static/admin/js/system/curd_generate.js | 54 ++++++++++--------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/app/admin/controller/system/CurdGenerate.php b/app/admin/controller/system/CurdGenerate.php index 48507ae..a2486d2 100644 --- a/app/admin/controller/system/CurdGenerate.php +++ b/app/admin/controller/system/CurdGenerate.php @@ -11,6 +11,7 @@ use app\Request; use think\db\exception\PDOException; use think\exception\FileException; use think\facade\Db; +use think\helper\Str; use think\response\Json; /** @@ -66,7 +67,14 @@ class CurdGenerate extends AdminController $fileList = $build->getFileList(); if (empty($fileList)) return $this->error('这里什么都没有'); $result = $build->create(); - return $this->success('生成成功', compact('result')); + $_file = $result[0] ?? ''; + $link = ''; + if (!empty($_file)) { + $_fileExp = explode(DIRECTORY_SEPARATOR, $_file); + $_fileExp_last = array_slice($_fileExp, -2); + $link = '/' . env('EASYADMIN.ADMIN', 'admin') . '/' . $_fileExp_last[0] . '.' . Str::snake(explode('.php', end($_fileExp_last))[0] ?? '') . '/index'; + } + return $this->success('生成成功', compact('result', 'link')); } catch (FileException $exception) { return json(['code' => -1, 'msg' => $exception->getMessage()]); } diff --git a/public/static/admin/js/system/curd_generate.js b/public/static/admin/js/system/curd_generate.js index d1d6ed6..0499180 100644 --- a/public/static/admin/js/system/curd_generate.js +++ b/public/static/admin/js/system/curd_generate.js @@ -1,4 +1,4 @@ -define(["jquery", "easy-admin"], function ($, ea, Vue) { +define(["jquery", "easy-admin", "miniTab"], function ($, ea, miniTab) { var form = layui.form; var table = layui.table; @@ -9,7 +9,8 @@ define(["jquery", "easy-admin"], function ($, ea, Vue) { var Controller = { index: function () { - + miniTab.listen(); + let createStatus = false let tb_prefix let tb_name form.on('submit(search)', function (data) { @@ -17,11 +18,7 @@ define(["jquery", "easy-admin"], function ($, ea, Vue) { tb_prefix = field.tb_prefix tb_name = field.tb_name ea.request.get({url: $(this).attr('lay-submit'), prefix: true, data: field}, function (res) { - let code = res.code || '0' - if (code != '1') { - ea.msg.error(res.msg) - return - } + createStatus = true $('.tableShow').removeClass('layui-hide') $('.table-text').text(field.tb_prefix + field.tb_name) let _data = res.data @@ -35,15 +32,14 @@ define(["jquery", "easy-admin"], function ($, ea, Vue) { {field: 'null', title: '是否为空', minWidth: 80}, {field: 'desc', title: '描述', minWidth: 80}, ] - ], - data: _data.data, - page: false, + ], data: _data.data, page: false, }); - + }, function () { + createStatus = false }) form.on('submit(add)', function (data) { let table = $('.table-text').text() - if (!table) { + if (!table || !createStatus) { ea.msg.error('请先查询数据') return } @@ -51,29 +47,24 @@ define(["jquery", "easy-admin"], function ($, ea, Vue) { let options = {url: url, prefix: true, data: {tb_prefix: tb_prefix, tb_name: tb_name}} layer.confirm('确定要自动生成【' + table + '】对应的CURD?', function (index) { ea.request.post(options, function (res) { + createStatus = true ea.msg.success(res.msg) - let html = '' - $.each(res['data']['result'], function (idx, item) { - html += '
  • ' + item + '
  • ' - }) - $('.file-list').html(html) + appendHtml(res['data']['result'], res['data']['link']) }, function (error) { + createStatus = false let code = error.code if (code != '1') { if (code < 0) { + createStatus = true layer.confirm(error.msg, { - btn: ['确定强制覆盖生成'], title: '提示', icon: 0, + btn: ['确定强制覆盖生成', '取消'], title: '提示', icon: 0, yes: function () { options.prefix = false options.data.force = 1 ea.request.post(options, function (rs) { + createStatus = true ea.msg.success(rs.msg) - $('.file-list').empty() - let html = '' - $.each(rs['data']['result'], function (idx, item) { - html += '
  • ' + item + '
  • ' - }) - $('.file-list').html(html) + appendHtml(rs['data']['result'], rs['data']['link']) }) } }); @@ -88,7 +79,7 @@ define(["jquery", "easy-admin"], function ($, ea, Vue) { form.on('submit(delete)', function (data) { let table = $('.table-text').text() - if (!table) { + if (!table || !createStatus) { ea.msg.error('请先查询数据') return } @@ -99,11 +90,24 @@ define(["jquery", "easy-admin"], function ($, ea, Vue) { ea.msg.success(res.msg) $('.table-text').text('') $('.file-list').empty() + createStatus = false }) }) }) return }) + + function appendHtml(array, link) { + $('.file-list').empty() + let html = '' + $.each(array, function (idx, item) { + html += '
  • ' + item + '
  • ' + }) + html += '' + + '' + + '' + $('.file-list').html(html) + } } }; return Controller;