修改微信关键词管理

This commit is contained in:
邹景立 2022-08-11 14:38:38 +08:00
parent 64d2bbb230
commit 68b6306c59
5 changed files with 31 additions and 52 deletions

View File

@ -20,6 +20,7 @@ use app\wechat\model\WechatAuto;
use think\admin\Controller; use think\admin\Controller;
use think\admin\extend\CodeExtend; use think\admin\extend\CodeExtend;
use think\admin\helper\QueryHelper; use think\admin\helper\QueryHelper;
use think\admin\service\SystemService;
/** /**
* 关注自动回复 * 关注自动回复
@ -98,8 +99,7 @@ class Auto extends Controller
$data['code'] = CodeExtend::uniqidNumber(18, 'AM'); $data['code'] = CodeExtend::uniqidNumber(18, 'AM');
} }
if ($this->request->isGet()) { if ($this->request->isGet()) {
$public = dirname($this->request->basefile(true)); $this->defaultImage = SystemService::uri('/static/theme/img/image.png', '__FULL__');
$this->defaultImage = "{$public}/static/theme/img/image.png";
} else { } else {
$data['content'] = strip_tags($data['content'] ?? '', '<a>'); $data['content'] = strip_tags($data['content'] ?? '', '<a>');
} }

View File

@ -20,6 +20,7 @@ use app\wechat\model\WechatKeys;
use app\wechat\service\WechatService; use app\wechat\service\WechatService;
use think\admin\Controller; use think\admin\Controller;
use think\admin\helper\QueryHelper; use think\admin\helper\QueryHelper;
use think\admin\service\SystemService;
use think\exception\HttpResponseException; use think\exception\HttpResponseException;
/** /**
@ -125,7 +126,6 @@ class Keys extends Controller
/** /**
* 配置订阅回复 * 配置订阅回复
* @auth true * @auth true
* @menu true
*/ */
public function subscribe() public function subscribe()
{ {
@ -136,7 +136,6 @@ class Keys extends Controller
/** /**
* 配置默认回复 * 配置默认回复
* @auth true * @auth true
* @menu true
*/ */
public function defaults() public function defaults()
{ {
@ -153,28 +152,10 @@ class Keys extends Controller
{ {
if ($this->request->isPost()) { if ($this->request->isPost()) {
$map = [['keys', '=', $data['keys']], ['id', '<>', $data['id'] ?? 0]]; $map = [['keys', '=', $data['keys']], ['id', '<>', $data['id'] ?? 0]];
if (WechatKeys::mk()->where($map)->count() > 0) { if (WechatKeys::mk()->where($map)->count() > 0) $this->error('关键字已经存在!');
$this->error('该关键字已经存在!');
}
$data['content'] = strip_tags($data['content'] ?? '', '<a>'); $data['content'] = strip_tags($data['content'] ?? '', '<a>');
} elseif ($this->request->isGet()) { } elseif ($this->request->isGet()) {
$public = dirname($this->request->basefile(true)); $this->defaultImage = SystemService::uri('/static/theme/img/image.png', '__FULL__');
$this->defaultImage = "{$public}/static/theme/img/image.png";
}
}
/**
* 表单结果处理
* @param boolean $result
*/
protected function _form_result(bool $result)
{
if ($result !== false) {
$iskeys = in_array(input('keys'), ['subscribe', 'default']);
$location = $iskeys ? 'javascript:$.form.reload()' : 'javascript:history.back()';
$this->success('恭喜, 关键字保存成功!', $location);
} else {
$this->error('关键字保存失败, 请稍候再试!');
} }
} }
} }

View File

@ -1,6 +1,3 @@
{extend name="../../admin/view/main"}
{block name="style"}
<style> <style>
.keys-container .layui-card { .keys-container .layui-card {
width: 580px; width: 580px;
@ -26,9 +23,7 @@
margin-left: 100px; margin-left: 100px;
} }
</style> </style>
{/block}
{block name="content"}
<div class="nowrap think-box-shadow" style="width:910px"> <div class="nowrap think-box-shadow" style="width:910px">
<div class='mobile-preview inline-block'> <div class='mobile-preview inline-block'>
<div class='mobile-header'>公众号</div> <div class='mobile-header'>公众号</div>
@ -41,7 +36,7 @@
<div class="layui-card-body"> <div class="layui-card-body">
<!--{if !isset($vo.keys) or ($vo.keys neq 'default' and $vo.keys neq 'subscribe')}--> <!--{if !isset($vo.keys) or ($vo.keys neq 'default' and $vo.keys neq 'subscribe')}-->
<div class="layui-form-item margin-top-10"> <div class="layui-form-item margin-top-10">
<label class="layui-form-label"> </label> <label class="layui-form-label">&ensp;&ensp;</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input required placeholder='请输入关键字' maxlength='20' name='keys' class="layui-input" value='{$vo.keys|default=""}'> <input required placeholder='请输入关键字' maxlength='20' name='keys' class="layui-input" value='{$vo.keys|default=""}'>
</div> </div>
@ -166,25 +161,21 @@
<input value="{$vo.video_desc|default='视频描述'}" name="video_desc" maxlength="50" class="layui-input"> <input value="{$vo.video_desc|default='视频描述'}" name="video_desc" maxlength="50" class="layui-input">
</div> </div>
</div> </div>
<div class="text-center absolute full-width" style="bottom:0">
<div class="hr-line-dashed margin-top-10 margin-bottom-15"></div>
<button class="layui-btn menu-submit">保存数据</button>
<!--{if !isset($vo.keys) || !in_array($vo.keys,['default','subscribe'])}-->
<button data-history-back class="layui-btn layui-btn-danger" type='button'>取消编辑</button>
<!--{/if}-->
{if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'>{/if}
</div>
</div> </div>
</div> </div>
<div class="text-center absolute full-width" style="bottom:0">
<div class="hr-line-dashed margin-bottom-10"></div>
{if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'>{/if}
{if isset($vo['code'])}<input type='hidden' value='{$vo.code}' name='code'>{/if}
<button class="layui-btn menu-submit">保存数据</button>
<button data-history-back class="layui-btn layui-btn-danger" type='button'>取消编辑</button>
</div>
</form> </form>
</div> </div>
</div> </div>
{/block}
{block name="script"}
<script> <script>
(function ($body) { $(function () {
/*! 刷新预览显示 */ /*! 刷新预览显示 */
function showReview(params, location) { function showReview(params, location) {
@ -197,7 +188,7 @@
$('[data-iframe-box]').empty().append($(iframe).attr('src', location)); $('[data-iframe-box]').empty().append($(iframe).attr('src', location));
} }
$body.off('change', '[name="news_id"]').on('change', '[name="news_id"]', function () { $('body').off('change', '[name="news_id"]').on('change', '[name="news_id"]', function () {
/*! 图文显示预览 */ /*! 图文显示预览 */
showReview({type: 'news', content: this.value}); showReview({type: 'news', content: this.value});
}).off('change', '[name="content"]').on('change', '[name="content"]', function () { }).off('change', '[name="content"]').on('change', '[name="content"]', function () {
@ -213,7 +204,7 @@
/*! 音乐显示预览 */ /*! 音乐显示预览 */
var musicSelector = '[name="music_url"],[name="music_title"],[name="music_desc"],[name="music_image"]'; var musicSelector = '[name="music_url"],[name="music_title"],[name="music_desc"],[name="music_image"]';
$body.off('change', musicSelector).on('change', musicSelector, function () { $('body').off('change', musicSelector).on('change', musicSelector, function () {
var params = {type: 'music'}, $parent = $(this).parents('form'); var params = {type: 'music'}, $parent = $(this).parents('form');
params.url = $parent.find('[name="music_url"]').val(); params.url = $parent.find('[name="music_url"]').val();
params.desc = $parent.find('[name="music_desc"]').val(); params.desc = $parent.find('[name="music_desc"]').val();
@ -224,7 +215,7 @@
/*! 视频显示预览 */ /*! 视频显示预览 */
var videoSelector = '[name="video_title"],[name="video_url"],[name="video_desc"]'; var videoSelector = '[name="video_title"],[name="video_url"],[name="video_desc"]';
$body.off('change', videoSelector).on('change', videoSelector, function () { $('body').off('change', videoSelector).on('change', videoSelector, function () {
var params = {type: 'video'}, $parent = $(this).parents('form'); var params = {type: 'video'}, $parent = $(this).parents('form');
params.url = $parent.find('[name="video_url"]').val(); params.url = $parent.find('[name="video_url"]').val();
params.desc = $parent.find('[name="video_desc"]').val(); params.desc = $parent.find('[name="video_desc"]').val();
@ -233,7 +224,7 @@
}); });
/*! 默认类型事件 */ /*! 默认类型事件 */
$body.off('click', 'input[name=type]').on('click', 'input[name=type]', function () { $('body').off('click', 'input[name=type]').on('click', 'input[name=type]', function () {
var value = $(this).val(), $form = $(this).parents('form'); var value = $(this).val(), $form = $(this).parents('form');
if (value === 'customservice') value = 'text'; if (value === 'customservice') value = 'text';
var $current = $form.find('[data-keys-type="' + value + '"]').removeClass('layui-hide'); var $current = $form.find('[data-keys-type="' + value + '"]').removeClass('layui-hide');
@ -259,7 +250,5 @@
$('input[name=type]:checked').map(function () { $('input[name=type]:checked').map(function () {
$(this).trigger('click'); $(this).trigger('click');
}); });
});
})($('body')); </script>
</script>
{/block}

View File

@ -1,8 +1,16 @@
{extend name="../../admin/view/table"} {extend name="../../admin/view/table"}
{block name="button"} {block name="button"}
<!--{if auth("defaults") and $type eq 'index'}-->
<button class='layui-btn layui-btn-sm layui-btn-primary' data-width="950px" data-modal='{:url("defaults")}'>回复回复</button>
<!--{/if}-->
<!--{if auth("subscribe") and $type eq 'index'}-->
<button class='layui-btn layui-btn-sm layui-btn-primary' data-width="950px" data-modal='{:url("subscribe")}'>订阅回复</button>
<!--{/if}-->
<!--{if auth("add") and $type eq 'index'}--> <!--{if auth("add") and $type eq 'index'}-->
<button class='layui-btn layui-btn-sm layui-btn-primary' data-open='{:url("add")}'>添加规则</button> <button class='layui-btn layui-btn-sm layui-btn-primary' data-width="950px" data-modal='{:url("add")}'>添加规则</button>
<!--{/if}--> <!--{/if}-->
<!--{if auth("state") and $type eq 'index'}--> <!--{if auth("state") and $type eq 'index'}-->
@ -109,7 +117,7 @@
<!-- 操作面板模板 --> <!-- 操作面板模板 -->
<script type="text/html" id="toolbar"> <script type="text/html" id="toolbar">
<!--{if auth("edit") and isset($type) and $type eq 'index'}--> <!--{if auth("edit") and isset($type) and $type eq 'index'}-->
<a class="layui-btn layui-btn-sm" data-open="{:url('edit')}?id={{d.id}}" data-title="编辑回复规则"> </a> <a class="layui-btn layui-btn-sm" data-width="950px" data-modal="{:url('edit')}?id={{d.id}}" data-title="编辑回复规则"> </a>
<!--{/if}--> <!--{/if}-->
<!--{if auth("remove") and isset($type) and $type neq 'index'}--> <!--{if auth("remove") and isset($type) and $type neq 'index'}-->
<a class="layui-btn layui-btn-sm layui-btn-danger" data-action="{:url('remove')}" data-value="id#{{d.id}}" data-confirm="确定要删除该用户吗?"> </a> <a class="layui-btn layui-btn-sm layui-btn-danger" data-action="{:url('remove')}" data-value="id#{{d.id}}" data-confirm="确定要删除该用户吗?"> </a>

View File

@ -122,6 +122,7 @@
$.form.load('{:url("index")}', {output: 'json'}, 'get', function (ret) { $.form.load('{:url("index")}', {output: 'json'}, 'get', function (ret) {
return $rootScope.$apply(function () { return $rootScope.$apply(function () {
$rootScope.keys = ret.data.keysdata || [], $rootScope.list = ret.data.menudata || []; $rootScope.keys = ret.data.keysdata || [], $rootScope.list = ret.data.menudata || [];
console.log($rootScope.keys)
if ($rootScope.list.length < 1) $rootScope.list = [{name: '请输入名称', type: 'click', sub_button: []}]; if ($rootScope.list.length < 1) $rootScope.list = [{name: '请输入名称', type: 'click', sub_button: []}];
for (var i in $rootScope.list) $rootScope.list[i].sub_button = $rootScope.list[i].sub_button || []; for (var i in $rootScope.list) $rootScope.list[i].sub_button = $rootScope.list[i].sub_button || [];
$rootScope.list[0].show = true, $rootScope.list[0].active = true, $rootScope.item = $rootScope.list[0]; $rootScope.list[0].show = true, $rootScope.list[0].active = true, $rootScope.item = $rootScope.list[0];