调整微信图文

This commit is contained in:
Anyon 2020-11-20 10:56:09 +08:00
parent 21ab984a40
commit e8410cb277
14 changed files with 45 additions and 110 deletions

View File

@ -223,7 +223,7 @@ class Push extends Controller
[$news, $articles] = [MediaService::instance()->news($data['news_id']), []];
if (empty($news['articles'])) return false;
foreach ($news['articles'] as $vo) array_push($articles, [
'url' => url("@wechat/api.review/view/id/{$vo['id']}", [], false, true)->build(),
'url' => url("@wechat/api.view/item/id/{$vo['id']}", [], false, true)->build(),
'title' => $vo['title'], 'picurl' => $vo['local_url'], 'description' => $vo['digest'],
]);
return $this->_sendMessage('news', ['articles' => $articles], $custom);

View File

@ -19,14 +19,15 @@ use app\wechat\service\MediaService;
use think\admin\Controller;
/**
* Class Review
* 微信图文显示
* Class View
* @package app\wechat\controller\api
*/
class Review extends Controller
class View extends Controller
{
/**
* 图文展示
* 图文列表展示
* @param integer $id 图文ID
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
@ -40,13 +41,13 @@ class Review extends Controller
}
/**
* 文章展示
* 文章内容展示
* @param integer $id 文章ID
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function view($id = 0)
public function item($id = 0)
{
$map = ['id' => $id ?: input('id', 0)];
$this->app->db->name('WechatNewsArticle')->where($map)->update([

View File

@ -1,4 +1,4 @@
{extend name='api/review/main'}
{extend name='api/view/main'}
{block name='content'}
<div class="header"><span>{:date('H:i')}</span></div>

View File

@ -1,4 +1,4 @@
{extend name='api/review/main'}
{extend name='api/view/main'}
{block name='title'}{/block}

View File

@ -1,4 +1,4 @@
{extend name='api/review/main'}
{extend name='api/view/main'}
{block name='content'}
<div class="header"><span>{:date('H:i')}</span></div>

View File

@ -1,15 +1,15 @@
{extend name='api/review/main'}
{extend name='api/view/main'}
{block name='content'}
<div class="header"><span>{:date('H:i')}</span></div>
<div class="container">
{notempty name='news.articles'} {foreach $news.articles as $k => $v} {if $k < 1}
<a href="{:url('wechat/api.review/view')}?id={$v.id}" style='background-image:url("{$v.local_url}")'>
<a href="{:url('wechat/api.view/item')}?id={$v.id}" style='background-image:url("{$v.local_url}")'>
{if $v.title}<span>{$v.title}</span>{/if}
</a>
<div class="hr-line-dashed"></div>
{else}
<a href="{:url('wechat/api.review/view')}?id={$v.id}" class='other'>
<a href="{:url('wechat/api.view/item')}?id={$v.id}" class='other'>
<span>{$v.title}</span>
<span style='background-image:url("{$v.local_url}");'></span>
</a>

View File

@ -1,4 +1,4 @@
{extend name='api/review/main'}
{extend name='api/view/main'}
{block name='content'}
<div class="header"><span>{:date('H:i')}</span></div>

View File

@ -1,4 +1,4 @@
{extend name='api/review/main'}
{extend name='api/view/main'}
{block name='content'}
<div class="header"><span>{:date('H:i')}</span></div>

View File

@ -1,4 +1,4 @@
{extend name='api/review/main'}
{extend name='api/view/main'}
{block name='content'}
<div class="header"><span>{:date('H:i')}</span></div>

View File

@ -14,10 +14,20 @@
padding-right: 50px
}
.keys-container .layui-card [data-tips-image] {
.keys-container .layui-card .layui-card-body [data-tips-image] {
width: 112px;
height: auto
}
.keys-container .layui-card .layui-card-body .layui-form-label {
width: 60px;
color: #6c6c6c;
font-weight: 700;
}
.keys-container .layui-card .layui-card-body .layui-form-label + .layui-input-block {
margin-left: 100px;
}
</style>
{/block}
@ -73,9 +83,9 @@
</div>
<div class="layui-form-item" data-keys-type='text'>
<label class="layui-form-label">回复内容</label>
<label class="layui-form-label">回复文字</label>
<div class="layui-input-block">
<textarea name="content" maxlength="10000" class="layui-textarea">{$vo.content|raw|default='说点什么吧'}</textarea>
<textarea name="content" required placeholder="请输入回复文字" maxlength="10000" class="layui-textarea">{$vo.content|raw|default='说点什么吧'}</textarea>
</div>
</div>
@ -182,9 +192,9 @@
/*! 刷新预览显示 */
function showReview(params, location) {
if (params['type'] === 'news') {
location = '{:url("@wechat/api.review/news")}?id=_id_'.replace('_id_', params.content);
location = '{:url("@wechat/api.view/news")}?id=_id_'.replace('_id_', params.content);
} else {
location = '{:url("@wechat/api.review/_type_")}?'.replace('_type_', params.type) + $.param(params || {});
location = '{:url("@wechat/api.view/_type_")}?'.replace('_type_', params.type) + $.param(params || {});
}
var iframe = '<iframe id="phone-preview" frameborder="0" marginheight="0" marginwidth="0"></iframe>';
$('[data-iframe-box]').empty().append($(iframe).attr('src', location));

View File

@ -47,17 +47,17 @@
<td class="text-left nowrap">{$vo.type}</td>
<td class="text-left nowrap notselect">
{if $vo.type eq '音乐'}
<a data-phone-view='{:url("@wechat/api.review/music")}?title={$vo.music_title|urlencode}&desc={$vo.music_desc|urlencode}'>预览 <i class="fa fa-eye"></i></a>
<a data-phone-view='{:url("@wechat/api.view/music")}?title={$vo.music_title|urlencode}&desc={$vo.music_desc|urlencode}'>预览 <i class="fa fa-eye"></i></a>
{elseif in_array($vo.type,['文字','转客服'])}
<a data-phone-view='{:url("@wechat/api.review/text")}?content={$vo.content|urlencode}'>预览 <i class="fa fa-eye"></i></a>
<a data-phone-view='{:url("@wechat/api.view/text")}?content={$vo.content|urlencode}'>预览 <i class="fa fa-eye"></i></a>
{elseif $vo.type eq '图片'}
<a data-phone-view='{:url("@wechat/api.review/image")}?content={$vo.image_url|urlencode}'>预览 <i class="fa fa-eye"></i></a>
<a data-phone-view='{:url("@wechat/api.view/image")}?content={$vo.image_url|urlencode}'>预览 <i class="fa fa-eye"></i></a>
{elseif $vo.type eq '图文'}
<a data-phone-view='{:url("@wechat/api.review/news")}?id={$vo.news_id}'>预览 <i class="fa fa-eye"></i></a>
<a data-phone-view='{:url("@wechat/api.view/news")}?id={$vo.news_id}'>预览 <i class="fa fa-eye"></i></a>
{elseif $vo.type eq '视频'}
<a data-phone-view='{:url("@wechat/api.review/video")}?title={$vo.video_title|urlencode}&desc={$vo.video_desc|urlencode}&url={$vo.video_url|urlencode}'>预览 <i class="fa fa-eye"></i></a>
<a data-phone-view='{:url("@wechat/api.view/video")}?title={$vo.video_title|urlencode}&desc={$vo.video_desc|urlencode}&url={$vo.video_url|urlencode}'>预览 <i class="fa fa-eye"></i></a>
{elseif $vo.type eq '语音'}
<a data-phone-view='{:url("@wechat/api.review/voice")}?content={$vo.voice_url|urlencode}'>预览 <i class="fa fa-eye"></i></a>
<a data-phone-view='{:url("@wechat/api.view/voice")}?content={$vo.voice_url|urlencode}'>预览 <i class="fa fa-eye"></i></a>
{else} {$vo.content} {/if}
</td>
<td class="text-left nowrap">{$vo.create_at|format_datetime}</td>
@ -85,78 +85,4 @@
</table>
{empty name='list'}<span class="notdata">没有记录哦</span>{else}{$pagehtml|raw|default=''}{/empty}
</div>
{/block}
{block name="script"}
<script>
$(function () {
$('body').off('change', 'select[name=type]').on('change', 'select[name=type]', function () {
var value = $(this).val(), $form = $(this).parents('form');
var $current = $form.find('[data-keys-type="' + value + '"]').removeClass('hide');
$form.find('[data-keys-type]').not($current).addClass('hide');
if (value === 'news') return $('[name="news_id"]').trigger('change');
if (value === 'text') return $('[name="content"]').trigger('change');
if (value === 'image') return $('[name="image_url"]').trigger('change');
if (value === 'video') return $('[name="video_url"]').trigger('change');
if (value === 'voice') return $('[name="voice_url"]').trigger('change');
if (value === 'music') return $('[name="music_url"]').trigger('change');
});
function showReview(params) {
params = params || {};
$('#phone-preview').attr('src', '{"@wechat/review"|app_url}&' + $.param(params));
}
// 图文显示预览
$('body').off('change', '[name="news_id"]').on('change', '[name="news_id"]', function () {
showReview({type: 'news', content: this.value});
});
// 文字显示预览
$('body').off('change', '[name="content"]').on('change', '[name="content"]', function () {
showReview({type: 'text', content: this.value});
});
// 图片显示预览
$('body').off('change', '[name="image_url"]').on('change', '[name="image_url"]', function () {
showReview({type: 'image', content: this.value});
});
// 音乐显示预览
var musicSelector = '[name="music_url"],[name="music_title"],[name="music_desc"],[name="music_image"]';
$('body').off('change', musicSelector).on('change', musicSelector, function () {
var params = {type: 'music'}, $parent = $(this).parents('form');
params.title = $parent.find('[name="music_title"]').val();
params.image = $parent.find('[name="music_image"]').val();
params.desc = $parent.find('[name="music_desc"]').val();
params.url = $parent.find('[name="music_url"]').val();
showReview(params);
});
// 视频显示预览
var videoSelector = '[name="video_title"],[name="video_url"],[name="video_desc"]';
$('body').off('change', videoSelector).on('change', videoSelector, function () {
var params = {type: 'video'}, $parent = $(this).parents('form');
params.title = $parent.find('[name="video_title"]').val();
params.desc = $parent.find('[name="video_desc"]').val();
params.url = $parent.find('[name="video_url"]').val();
showReview(params);
});
// 默认事件触发
$('select[name=type]').map(function () {
$(this).trigger('change');
});
/*! 删除关键字 */
$('[data-delete]').on('click', function () {
var id = this.getAttribute('data-delete');
var url = this.getAttribute('data-action');
var dialogIndex = $.msg.confirm('确定要删除这条记录吗?', function () {
$.form.load(url, {id: id}, 'post', function (ret) {
if (ret.code === "SUCCESS") {
window.location.reload();
}
$.msg.close(dialogIndex);
});
})
});
});
</script>
{/block}
{/block}

View File

@ -12,13 +12,11 @@
<div class="layui-input-inline">
<select class="layui-select" name="type">
<option value="">-- 全部 --</option>
{foreach $types as $k=>$v}
{if $k.'' eq input('type')}
{foreach $types as $k => $v}{if $k.'' eq input('type')}
<option selected value="{$k}">{$v}</option>
{else}
<option value="{$k}">{$v}</option>
{/if}
{/foreach}
{/if}{/foreach}
</select>
</div>
</div>
@ -26,13 +24,13 @@
<label class="layui-form-label">使用状态</label>
<div class="layui-input-inline">
<select class="layui-select" name="status">
{foreach [''=>'-- 全部 --','0'=>'显示使用的规则','1'=>'显示禁止的规则'] as $k=>$v}
<option value="">-- 全部 --</option>
{foreach ['显示禁止的规则','显示使用的规则'] as $k=>$v}
{if $k.'' eq input('status')}
<option selected value="{$k}">{$v}</option>
{else}
<option value="{$k}">{$v}</option>
{/if}
{/foreach}
{/if}{/foreach}
</select>
</div>
</div>
@ -46,6 +44,6 @@
<button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i> 搜 索</button>
</div>
</form>
<script>window.form.render()</script>
</fieldset>
<script>window.form.render()</script>

View File

@ -14,7 +14,7 @@
{foreach $list as $vo}
<div class="news-item">
<div class='news-tools layui-hide'>
<a data-phone-view="{:url('wechat/api.review/news')}?id={$vo.id}" href='javascript:void(0)'>预览</a>
<a data-phone-view="{:url('wechat/api.view/news')}?id={$vo.id}" href='javascript:void(0)'>预览</a>
<a data-open='{:url("edit")}?id={$vo.id}' href='javascript:void(0)'>编辑</a>
<a data-news-del="{$vo.id}" href='javascript:void(0)'>删除</a>
</div>