wechat.js
5.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'weixin/template/wechat/index' + location.search,
add_url: 'weixin/template/wechat/add',
edit_url: 'weixin/template/wechat/edit',
del_url: 'weixin/template/wechat/del',
multi_url: 'weixin/template/wechat/multi',
table: 'weixin_template',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'tempkey', title: __('Tempkey')},
{field: 'name', title: __('Name')},
// {field: 'content', title: __('Content')},
{field: 'tempid', title: __('Tempid')},
{field: 'add_time', title: __('Add_time'),sortable: true ,operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'status', title: __('Status'), operate: false, formatter: Controller.api.formatter.status},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
{
name: 'detail',
title: __('发送模板消息'),
classname: 'btn btn-xs btn-primary btn-dialog',
icon: 'fa fa-list',
url: 'weixin/template/wechat/sendmsg',
// callback: function (data) {
// Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
// }
}
]}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
// 推送示例
$(document).on("click", ".btn-demo", function () {
var _html = "<pre class='layui-code'>" +
"use addons\\weixin\\library\\WechatTemplateService;\r\n"+
"$message = array(\r\n" +
"\t'first' => '亲,您的订单已发货,请注意查收',\r\n" +
"\t'keyword1' => '012345678',\r\n" +
"\t'keyword2' => '100',\r\n" +
"\t'keyword3' => date('Y-m-d H:i:s', time()),\r\n" +
"\t'remark' => '点击查看订单详情'\r\n" +
");\r\n" +
"$res = WechatTemplateService::sendTemplate(\r\n" +
"\t'o-LXrv3whDgMsHZ3sTn5AmXRwO9Y',\r\n" +
"\t'OPENTM410119152',\r\n" +
"\t$message,\r\n" +
"\t'http://fastadmin.westts.cn'\r\n" +
");" +
"</pre>";
Layer.open({
type: 1
,title: '模板消息推送PHP示例' //不显示标题栏
,closeBtn: false
,area: '600px;'
,shade: 0.8
,id: 'LAY_layuipro' //设定一个id,防止重复弹出
,btn: ['确定', '取消']
,btnAlign: 'c'
,moveType: 1 //拖拽模式,0或者1
,content: _html
});
});
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
sendmsg: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
},
formatter: {//渲染的方法
status: function (value, row, index) {
if(row.status == "1"){
return '<a class="btn-change text-success" data-url="weixin/template/wechat/multi" data-params="status=0" data-id="' + row.id + '"><i class="fa fa-toggle-on fa-2x"></i></a>';
}else{
return '<a class="btn-change text-success" data-url="weixin/template/wechat/multi" data-params="status=1" data-id="' + row.id + '"><i class="fa fa-toggle-on fa-flip-horizontal text-gray fa-2x"></i></a>';
}
}
}
}
};
return Controller;
});