新增自定义通知模板
This commit is contained in:
166
controllers/notify_tpl.go
Normal file
166
controllers/notify_tpl.go
Normal file
@@ -0,0 +1,166 @@
|
||||
/************************************************************
|
||||
** @Description: controllers
|
||||
** @Author: Bee
|
||||
** @Date: 2019-02-15 20:21
|
||||
** @Last Modified by: Bee
|
||||
** @Last Modified time: 2019-02-15 20:21
|
||||
*************************************************************/
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/george518/PPGo_Job/models"
|
||||
"strings"
|
||||
"time"
|
||||
"github.com/astaxie/beego"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type NotifyTplController struct {
|
||||
BaseController
|
||||
}
|
||||
|
||||
func (self *NotifyTplController) List() {
|
||||
self.Data["pageTitle"] = "通知模板"
|
||||
self.display()
|
||||
}
|
||||
|
||||
func (self *NotifyTplController) Add() {
|
||||
self.Data["pageTitle"] = "新增通知模板"
|
||||
self.Data["serverGroup"] = serverGroupLists(self.serverGroups, self.userId)
|
||||
self.display()
|
||||
}
|
||||
|
||||
func (self *NotifyTplController) Edit() {
|
||||
self.Data["pageTitle"] = "编辑通知模板"
|
||||
|
||||
id, _ := self.GetInt("id", 0)
|
||||
notifyTpl, _ := models.NotifyTplGetById(id)
|
||||
row := make(map[string]interface{})
|
||||
row["id"] = notifyTpl.Id
|
||||
row["tpl_name"] = notifyTpl.TplName
|
||||
row["tpl_type"] = notifyTpl.TplType
|
||||
row["title"] = notifyTpl.Title
|
||||
row["content"] = notifyTpl.Content
|
||||
row["status"] = notifyTpl.Status
|
||||
self.Data["notifyTpl"] = row
|
||||
self.display()
|
||||
}
|
||||
|
||||
func (self *NotifyTplController) AjaxSave() {
|
||||
tpl_id, _ := self.GetInt("id")
|
||||
if tpl_id == 0 {
|
||||
notifyTpl := new(models.NotifyTpl)
|
||||
notifyTpl.TplName = strings.TrimSpace(self.GetString("tpl_name"))
|
||||
notifyTpl.TplType, _ = self.GetInt("tpl_type")
|
||||
notifyTpl.Title = strings.TrimSpace(self.GetString("title"))
|
||||
notifyTpl.Content = strings.TrimSpace(self.GetString("content"))
|
||||
notifyTpl.CreateId = self.userId
|
||||
notifyTpl.CreateTime = time.Now().Unix()
|
||||
notifyTpl.Type = "default"
|
||||
notifyTpl.Status, _ = self.GetInt("status")
|
||||
|
||||
if notifyTpl.TplType == 1 {
|
||||
m := make(map[string]string)
|
||||
err := json.Unmarshal([]byte(notifyTpl.Content), &m)
|
||||
if err != nil {
|
||||
self.ajaxMsg("模板内容格式错误,"+err.Error(), MSG_ERR)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := models.NotifyTplAdd(notifyTpl); err != nil {
|
||||
self.ajaxMsg(err.Error(), MSG_ERR)
|
||||
}
|
||||
self.ajaxMsg("", MSG_OK)
|
||||
}
|
||||
|
||||
notifyTpl, _ := models.NotifyTplGetById(tpl_id)
|
||||
//修改
|
||||
notifyTpl.Id = tpl_id
|
||||
notifyTpl.UpdateId = self.userId
|
||||
notifyTpl.UpdateTime = time.Now().Unix()
|
||||
|
||||
notifyTpl.TplName = strings.TrimSpace(self.GetString("tpl_name"))
|
||||
notifyTpl.TplType, _ = self.GetInt("tpl_type")
|
||||
notifyTpl.Title = strings.TrimSpace(self.GetString("title"))
|
||||
notifyTpl.Content = strings.TrimSpace(self.GetString("content"))
|
||||
notifyTpl.Status, _ = self.GetInt("status")
|
||||
|
||||
if notifyTpl.TplType == 1 {
|
||||
m := make(map[string]string)
|
||||
err := json.Unmarshal([]byte(notifyTpl.Content), &m)
|
||||
if err != nil {
|
||||
self.ajaxMsg("模板内容格式错误,"+err.Error(), MSG_ERR)
|
||||
}
|
||||
}
|
||||
|
||||
if notifyTpl.Type == "system" {
|
||||
self.ajaxMsg("系统模板禁止更新", MSG_ERR)
|
||||
}
|
||||
|
||||
if err := notifyTpl.Update(); err != nil {
|
||||
self.ajaxMsg("更新失败,"+err.Error(), MSG_ERR)
|
||||
}
|
||||
self.ajaxMsg("", MSG_OK)
|
||||
}
|
||||
|
||||
func (self *NotifyTplController) AjaxDel() {
|
||||
id, _ := self.GetInt("id")
|
||||
notifyTpl, _ := models.NotifyTplGetById(id)
|
||||
|
||||
if notifyTpl.Type == "system" {
|
||||
self.ajaxMsg("系统模板禁止删除", MSG_ERR)
|
||||
}
|
||||
|
||||
if err := models.NotifyTplDelById(id); err != nil {
|
||||
self.ajaxMsg("删除失败,"+err.Error(), MSG_ERR)
|
||||
}
|
||||
self.ajaxMsg("操作成功", MSG_OK)
|
||||
}
|
||||
|
||||
func (self *NotifyTplController) Table() {
|
||||
//列表
|
||||
page, err := self.GetInt("page")
|
||||
if err != nil {
|
||||
page = 1
|
||||
}
|
||||
limit, err := self.GetInt("limit")
|
||||
if err != nil {
|
||||
limit = 30
|
||||
}
|
||||
tplName := strings.TrimSpace(self.GetString("tplName"))
|
||||
StatusText := []string{
|
||||
"<font color='red'>禁用</font>",
|
||||
"正常",
|
||||
}
|
||||
|
||||
TplTypeText := []string{
|
||||
"邮件",
|
||||
"信息",
|
||||
"钉钉",
|
||||
}
|
||||
|
||||
self.pageSize = limit
|
||||
//查询条件
|
||||
filters := make([]interface{}, 0)
|
||||
|
||||
if tplName != "" {
|
||||
filters = append(filters, "tpl_name__icontains", tplName)
|
||||
}
|
||||
result, count := models.NotifyTplGetList(page, self.pageSize, filters...)
|
||||
list := make([]map[string]interface{}, len(result))
|
||||
for k, v := range result {
|
||||
row := make(map[string]interface{})
|
||||
row["id"] = v.Id
|
||||
row["type"] = v.Type
|
||||
row["tpl_name"] = v.TplName
|
||||
row["tpl_type"] = v.TplType
|
||||
row["tpl_type_text"] = TplTypeText[v.TplType]
|
||||
row["status"] = v.Status
|
||||
row["status_text"] = StatusText[v.Status]
|
||||
row["create_time"] = beego.Date(time.Unix(v.CreateTime, 0), "Y-m-d H:i:s")
|
||||
row["update_time"] = beego.Date(time.Unix(v.UpdateTime, 0), "Y-m-d H:i:s")
|
||||
list[k] = row
|
||||
}
|
||||
|
||||
self.ajaxList("成功", MSG_OK, count, list)
|
||||
}
|
||||
@@ -81,6 +81,22 @@ func (self *TaskController) Edit() {
|
||||
}
|
||||
|
||||
self.Data["notify_user_ids"] = notifyUserIds
|
||||
|
||||
notifyTplList, _, err := models.NotifyTplGetByTplTypeList(task.NotifyType)
|
||||
tplList := make([]map[string]interface{}, len(notifyTplList))
|
||||
|
||||
if err == nil {
|
||||
for k, v := range notifyTplList {
|
||||
row := make(map[string]interface{})
|
||||
row["id"] = v.Id
|
||||
row["tpl_name"] = v.TplName
|
||||
row["tpl_type"] = v.TplType
|
||||
tplList[k] = row
|
||||
}
|
||||
}
|
||||
|
||||
self.Data["notifyTpl"] = tplList
|
||||
|
||||
self.display()
|
||||
}
|
||||
|
||||
@@ -197,8 +213,13 @@ func (self *TaskController) AjaxSave() {
|
||||
task.Timeout, _ = self.GetInt("timeout")
|
||||
task.IsNotify, _ = self.GetInt("is_notify")
|
||||
task.NotifyType, _ = self.GetInt("notify_type")
|
||||
task.NotifyTplId, _ = self.GetInt("notify_tpl_id")
|
||||
task.NotifyUserIds = strings.TrimSpace(self.GetString("notify_user_ids"))
|
||||
|
||||
if task.IsNotify == 1 && task.NotifyTplId <= 0 {
|
||||
self.ajaxMsg("请选择通知模板", MSG_ERR)
|
||||
}
|
||||
|
||||
msg, isBan := checkCommand(task.Command)
|
||||
if !isBan {
|
||||
self.ajaxMsg("含有禁止命令:"+msg, MSG_ERR)
|
||||
@@ -213,6 +234,7 @@ func (self *TaskController) AjaxSave() {
|
||||
if task.TaskName == "" || task.CronSpec == "" || task.Command == "" {
|
||||
self.ajaxMsg("请填写完整信息", MSG_ERR)
|
||||
}
|
||||
|
||||
if _, err := cron.Parse(task.CronSpec); err != nil {
|
||||
self.ajaxMsg("cron表达式无效", MSG_ERR)
|
||||
}
|
||||
@@ -237,9 +259,15 @@ func (self *TaskController) AjaxSave() {
|
||||
task.Timeout, _ = self.GetInt("timeout")
|
||||
task.IsNotify, _ = self.GetInt("is_notify")
|
||||
task.NotifyType, _ = self.GetInt("notify_type")
|
||||
task.NotifyTplId, _ = self.GetInt("notify_tpl_id")
|
||||
task.NotifyUserIds = strings.TrimSpace(self.GetString("notify_user_ids"))
|
||||
task.UpdateId = self.userId
|
||||
task.Status = 2 //审核中,超级管理员不需要
|
||||
|
||||
if task.IsNotify == 1 && task.NotifyTplId <= 0 {
|
||||
self.ajaxMsg("请选择通知模板", MSG_ERR)
|
||||
}
|
||||
|
||||
if self.userId == 1 {
|
||||
task.Status = 0
|
||||
}
|
||||
@@ -487,6 +515,23 @@ func (self *TaskController) AjaxDel() {
|
||||
self.ajaxMsg("操作成功", MSG_OK)
|
||||
}
|
||||
|
||||
func (self *TaskController) AjaxNotifyType() {
|
||||
notifyType, _ := self.GetInt("notify_type")
|
||||
result, count, _ := models.NotifyTplGetByTplTypeList(notifyType)
|
||||
|
||||
list := make([]map[string]interface{}, len(result))
|
||||
|
||||
for k, v := range result {
|
||||
row := make(map[string]interface{})
|
||||
row["id"] = v.Id
|
||||
row["tpl_name"] = v.TplName
|
||||
row["tpl_type"] = v.TplType
|
||||
list[k] = row
|
||||
}
|
||||
|
||||
self.ajaxList("成功", MSG_OK, count, list)
|
||||
}
|
||||
|
||||
func (self *TaskController) Table() {
|
||||
//列表
|
||||
page, err := self.GetInt("page")
|
||||
|
||||
@@ -146,6 +146,15 @@ func (self *TaskLogController) Detail() {
|
||||
self.Data["CreateTime"] = beego.Date(time.Unix(task.CreateTime, 0), "Y-m-d H:i:s")
|
||||
self.Data["UpdateTime"] = beego.Date(time.Unix(task.UpdateTime, 0), "Y-m-d H:i:s")
|
||||
self.Data["task"] = task
|
||||
|
||||
self.Data["NotifyTplName"] = "未知"
|
||||
if task.IsNotify == 1 {
|
||||
notifyTpl, err := models.NotifyTplGetById(task.NotifyTplId)
|
||||
if err == nil {
|
||||
self.Data["NotifyTplName"] = notifyTpl.TplName
|
||||
}
|
||||
}
|
||||
|
||||
// 分组列表
|
||||
self.Data["taskGroup"] = taskGroupLists(self.taskGroups, self.userId)
|
||||
|
||||
|
||||
99
jobs/job.go
99
jobs/job.go
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/george518/PPGo_Job/models"
|
||||
"github.com/george518/PPGo_Job/notify"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type Job struct {
|
||||
@@ -294,85 +295,59 @@ func (j *Job) Run() {
|
||||
toEmail = strings.TrimRight(toEmail, ";")
|
||||
|
||||
TextStatus := []string{
|
||||
"<font color='red'>超时</font>",
|
||||
"<font color='red'>错误</font>",
|
||||
"<font color='green'>正常</font>",
|
||||
"超时",
|
||||
"错误",
|
||||
"正常",
|
||||
}
|
||||
|
||||
status := log.Status + 2
|
||||
|
||||
var title = ""
|
||||
var content = ""
|
||||
notifyTpl, err := models.NotifyTplGetById(j.task.NotifyTplId)
|
||||
if err == nil {
|
||||
title = notifyTpl.Title
|
||||
content = notifyTpl.Content
|
||||
}
|
||||
|
||||
if title != "" {
|
||||
title = strings.Replace(title, "{TaskId}", strconv.Itoa(j.task.Id), -1)
|
||||
title = strings.Replace(title, "{TaskName}", j.task.TaskName, -1)
|
||||
title = strings.Replace(title, "{CreateTime}", beego.Date(time.Unix(log.CreateTime, 0), "Y-m-d H:i:s"), -1)
|
||||
title = strings.Replace(title, "{ProcessTime}", strconv.FormatFloat(float64(log.ProcessTime)/1000, 'f', 6, 64), -1)
|
||||
title = strings.Replace(title, "{Status}", TextStatus[status], -1)
|
||||
title = strings.Replace(title, "{TaskOut}", log.Error, -1)
|
||||
}
|
||||
|
||||
if content != "" {
|
||||
content = strings.Replace(content, "{TaskId}", strconv.Itoa(j.task.Id), -1)
|
||||
content = strings.Replace(content, "{TaskName}", j.task.TaskName, -1)
|
||||
content = strings.Replace(content, "{CreateTime}", beego.Date(time.Unix(log.CreateTime, 0), "Y-m-d H:i:s"), -1)
|
||||
content = strings.Replace(content, "{ProcessTime}", strconv.FormatFloat(float64(log.ProcessTime)/1000, 'f', 6, 64), -1)
|
||||
content = strings.Replace(content, "{Status}", TextStatus[status], -1)
|
||||
content = strings.Replace(content, "{TaskOut}", log.Error, -1)
|
||||
}
|
||||
|
||||
if j.task.NotifyType == 0 && toEmail != "" {
|
||||
//邮件
|
||||
//SendToChan(to, subject, body, mailtype string) bool
|
||||
subject := fmt.Sprintf("PPGo_Job定时任务异常:%s", j.task.TaskName)
|
||||
body := fmt.Sprintf(
|
||||
`Hello,定时任务出问题了:
|
||||
<p style="font-size:16px;">任务执行详情:</p>
|
||||
<p style="display:block; padding:10px; background:#efefef;border:1px solid #e4e4e4">
|
||||
任务 ID:%d<br/>
|
||||
任务名称:%s<br/>
|
||||
执行时间:%s<br/>
|
||||
执行耗时:%f秒<br/>
|
||||
执行状态:%s
|
||||
</p>
|
||||
<p style="font-size:16px;">任务执行输出</p>
|
||||
<p style="display:block; padding:10px; background:#efefef;border:1px solid #e4e4e4">
|
||||
%s
|
||||
</p>
|
||||
<br/>
|
||||
<br/>
|
||||
<p>-----------------------------------------------------------------<br />
|
||||
本邮件由PPGo_Job定时系统自动发出,请勿回复<br />
|
||||
如果要取消邮件通知,请登录到系统进行设置<br />
|
||||
</p>
|
||||
`, j.task.Id,
|
||||
j.task.TaskName,
|
||||
beego.Date(time.Unix(log.CreateTime, 0), "Y-m-d H:i:s"),
|
||||
float64(log.ProcessTime)/1000,
|
||||
TextStatus[status],
|
||||
log.Error)
|
||||
mailtype := "html"
|
||||
|
||||
ok := notify.SendToChan(toEmail, subject, body, mailtype)
|
||||
ok := notify.SendToChan(toEmail, title, content, mailtype)
|
||||
if !ok {
|
||||
fmt.Println("发送邮件错误", toEmail)
|
||||
}
|
||||
|
||||
} else if j.task.NotifyType == 1 && len(phone) > 0 {
|
||||
//信息
|
||||
TextStatus := []string{
|
||||
" 超时",
|
||||
" 错误",
|
||||
" 正常",
|
||||
}
|
||||
param := make(map[string]string)
|
||||
param["task_id"] = " " + strconv.Itoa(j.task.Id)
|
||||
param["task_name"] = " " + j.task.TaskName
|
||||
param["status"] = " " + TextStatus[status]
|
||||
err := json.Unmarshal([]byte(content), ¶m)
|
||||
if err != nil {
|
||||
fmt.Println("发送信息错误", err)
|
||||
}
|
||||
|
||||
notify.SendSmsToChan(phone, param)
|
||||
} else if j.task.NotifyType == 2 && len(dingtalk) > 0 {
|
||||
|
||||
TextStatus := []string{
|
||||
"超时",
|
||||
"错误",
|
||||
"正常",
|
||||
}
|
||||
content := fmt.Sprintf(
|
||||
`任务执行异常详情:
|
||||
任务 ID:%d
|
||||
任务名称:%s
|
||||
执行时间:%s
|
||||
执行耗时:%f秒
|
||||
执行状态:%s
|
||||
任务执行输出:
|
||||
%s`,
|
||||
j.task.Id,
|
||||
j.task.TaskName,
|
||||
beego.Date(time.Unix(log.CreateTime, 0), "Y-m-d H:i:s"),
|
||||
float64(log.ProcessTime)/1000,
|
||||
TextStatus[status],
|
||||
log.Error)
|
||||
|
||||
//钉钉
|
||||
notify.SendDingtalkToChan(dingtalk, content)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* @Author: haodaquan
|
||||
* @Date: 2017-06-20 09:44:44
|
||||
* @Last Modified by: haodaquan
|
||||
* @Last Modified time: 2017-06-21 12:21:37
|
||||
* @Last Modified by: Bee
|
||||
* @Last Modified time: 2019-02-15 22:12
|
||||
*/
|
||||
|
||||
package models
|
||||
@@ -47,6 +47,7 @@ func Init(startTime int64) {
|
||||
new(Group),
|
||||
new(Task),
|
||||
new(TaskLog),
|
||||
new(NotifyTpl),
|
||||
)
|
||||
|
||||
if beego.AppConfig.String("runmode") == "dev" {
|
||||
|
||||
102
models/notify_tpl.go
Normal file
102
models/notify_tpl.go
Normal file
@@ -0,0 +1,102 @@
|
||||
/************************************************************
|
||||
** @Description: models
|
||||
** @Author: Bee
|
||||
** @Date: 2019-02-15 20:21
|
||||
** @Last Modified by: Bee
|
||||
** @Last Modified time: 2019-02-15 20:21
|
||||
*************************************************************/
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type NotifyTpl struct {
|
||||
Id int
|
||||
Type string
|
||||
TplName string
|
||||
TplType int
|
||||
Title string
|
||||
Content string
|
||||
Status int
|
||||
CreateId int
|
||||
UpdateId int
|
||||
CreateTime int64
|
||||
UpdateTime int64
|
||||
}
|
||||
|
||||
func (t *NotifyTpl) TableName() string {
|
||||
return TableName("notify_tpl")
|
||||
}
|
||||
|
||||
func (t *NotifyTpl) Update(fields ...string) error {
|
||||
if t.TplName == "" {
|
||||
return fmt.Errorf("模板名称不能为空")
|
||||
}
|
||||
|
||||
if t.Content == "" {
|
||||
return fmt.Errorf("模板内容不能为空")
|
||||
}
|
||||
|
||||
if t.CreateTime == 0 {
|
||||
t.CreateTime = time.Now().Unix()
|
||||
}
|
||||
|
||||
if _, err := orm.NewOrm().Update(t, fields...); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NotifyTplAdd(obj *NotifyTpl) (int64, error) {
|
||||
if obj.TplName == "" {
|
||||
return 0, fmt.Errorf("模板名称不能为空")
|
||||
}
|
||||
if obj.Content == "" {
|
||||
return 0, fmt.Errorf("模板内容不能为空")
|
||||
}
|
||||
if obj.CreateTime == 0 {
|
||||
obj.CreateTime = time.Now().Unix()
|
||||
}
|
||||
return orm.NewOrm().Insert(obj)
|
||||
}
|
||||
|
||||
func NotifyTplGetById(id int) (*NotifyTpl, error) {
|
||||
obj := &NotifyTpl{
|
||||
Id: id,
|
||||
}
|
||||
err := orm.NewOrm().Read(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
func NotifyTplGetByTplTypeList(tpl_type int) ([]*NotifyTpl, int64, error) {
|
||||
list := make([]*NotifyTpl, 0)
|
||||
total, err := orm.NewOrm().QueryTable(TableName("notify_tpl")).Filter("tpl_type", tpl_type).Filter("status", 1).All(&list)
|
||||
return list, total, err
|
||||
}
|
||||
|
||||
func NotifyTplDelById(id int) error {
|
||||
_, err := orm.NewOrm().QueryTable(TableName("notify_tpl")).Filter("id", id).Delete()
|
||||
return err
|
||||
}
|
||||
|
||||
func NotifyTplGetList(page, pageSize int, filters ...interface{}) ([]*NotifyTpl, int64) {
|
||||
|
||||
offset := (page - 1) * pageSize
|
||||
list := make([]*NotifyTpl, 0)
|
||||
query := orm.NewOrm().QueryTable(TableName("notify_tpl"))
|
||||
if len(filters) > 0 {
|
||||
l := len(filters)
|
||||
for k := 0; k < l; k += 2 {
|
||||
query = query.Filter(filters[k].(string), filters[k+1])
|
||||
}
|
||||
}
|
||||
total, _ := query.Count()
|
||||
query.OrderBy("-id").Limit(pageSize, offset).All(&list)
|
||||
return list, total
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
** @Description: models
|
||||
** @Author: haodaquan
|
||||
** @Date: 2018-06-11 21:26
|
||||
** @Last Modified by: haodaquan
|
||||
** @Last Modified time: 2018-06-11 21:26
|
||||
** @Last Modified by: Bee
|
||||
** @Last Modified time: 2019-02-15 21:32
|
||||
*************************************************************/
|
||||
package models
|
||||
|
||||
@@ -35,6 +35,7 @@ type Task struct {
|
||||
Status int
|
||||
IsNotify int
|
||||
NotifyType int
|
||||
NotifyTplId int
|
||||
NotifyUserIds string
|
||||
CreateId int
|
||||
UpdateId int
|
||||
|
||||
@@ -329,4 +329,44 @@ BEGIN;
|
||||
ALTER TABLE `pp_uc_admin` ADD `dingtalk` VARCHAR(64) NULL COMMENT '钉钉' AFTER `email`;
|
||||
COMMIT;
|
||||
|
||||
BEGIN;
|
||||
ALTER TABLE `pp_task` ADD `notify_tpl_id` INT NOT NULL DEFAULT '0' COMMENT '通知模板id' AFTER `notify_type`;
|
||||
COMMIT;
|
||||
|
||||
BEGIN;
|
||||
INSERT INTO `pp_uc_auth` VALUES(61, 17, '通知模板', '/notifytpl/list', 5, 'fa-file-o', 1, 1, 0, 1, 1, 0, 1550237874);
|
||||
INSERT INTO `pp_uc_auth` VALUES(62, 61, '新增', '/notifytpl/add', 1, '', 0, 1, 0, 1, 1, 0, 1550237919);
|
||||
INSERT INTO `pp_uc_auth` VALUES(63, 61, '编辑', '/notifytpl/edit', 2, '', 0, 1, 1, 1, 1, 1550237957, 1550237957);
|
||||
INSERT INTO `pp_uc_auth` VALUES(64, 61, '删除', '/notifytpl/ajaxdel', 3, '', 0, 1, 1, 1, 1, 1550237987, 1550237987);
|
||||
INSERT INTO `pp_uc_auth` VALUES(65, 31, '通知类型', '/task/ajaxnotifytype', 10, '', 0, 1, 1, 1, 1, 1550258380, 1550258380);
|
||||
COMMIT;
|
||||
|
||||
--
|
||||
-- 表的结构 `pp_notify_tpl`
|
||||
--
|
||||
DROP TABLE IF EXISTS `pp_uc_role_auth`;
|
||||
CREATE TABLE `pp_notify_tpl` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '模板id',
|
||||
`type` enum('system','default') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'default',
|
||||
`tpl_name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '模板名称',
|
||||
`tpl_type` tinyint(1) NOT NULL COMMENT '模板类型 0:邮件;1:信息;2:钉钉;',
|
||||
`title` varchar(64) DEFAULT NULL COMMENT '标题',
|
||||
`content` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '模板内容',
|
||||
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态 0:禁用;1:启用;',
|
||||
`create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||
`create_id` int(11) NOT NULL DEFAULT '0' COMMENT '创建者ID',
|
||||
`update_time` int(11) NOT NULL DEFAULT '0' COMMENT '最后一次编辑时间',
|
||||
`update_id` int(11) NOT NULL DEFAULT '0' COMMENT '最后一次编辑者ID',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='通知模板';
|
||||
|
||||
--
|
||||
-- 转存表中的数据 `pp_notify_tpl`
|
||||
--
|
||||
BEGIN;
|
||||
INSERT INTO `pp_notify_tpl` VALUES(1, 'system', '系统邮箱通知模板', 0, '定时任务异常:{TaskName}', 'Hello,定时任务出问题了:\r\n<p style=\"font-size:16px;\">任务执行详情:</p>\r\n<p style=\"display:block; padding:10px; background:#efefef;border:1px solid #e4e4e4\">\r\n任务 ID:{TaskId}<br/>\r\n任务名称:{TaskName}<br/>\r\n执行时间:{CreateTime}<br/>\r\n执行耗时:{ProcessTime}秒<br/>\r\n执行状态:{Status}\r\n</p>\r\n<p style=\"font-size:16px;\">任务执行输出</p>\r\n<p style=\"display:block; padding:10px; background:#efefef;border:1px solid #e4e4e4\">\r\n{TaskOut}\r\n</p>\r\n<br/>\r\n<br/>\r\n<p>-----------------------------------------------------------------<br />\r\n本邮件由定时系统自动发出,请勿回复<br />\r\n如果要取消邮件通知,请登录到系统进行设置<br />\r\n</p>', 1, 1550255030, 1, 1550256410, 1);
|
||||
INSERT INTO `pp_notify_tpl` VALUES(2, 'system', '系统短信通知模板', 1, '', '{\r\n \"task_id\": \"{TaskId}\",\r\n \"task_name\": \"{TaskName}\",\r\n \"status\": \"{Status}\"\r\n}', 1, 1550255030, 1, 1550269363, 1);
|
||||
INSERT INTO `pp_notify_tpl` VALUES(3, 'system', '系统钉钉通知模板', 2, '', '任务执行异常详情:\r\n任务 ID:{TaskId}\r\n任务名称:{TaskName}\r\n执行时间:{CreateTime}\r\n执行耗时:{ProcessTime}秒\r\n执行状态:{Status}\r\n任务执行输出:\r\n{TaskOut}', 1, 1550255030, 1, 1550269952, 1);
|
||||
COMMIT;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
@@ -28,4 +28,5 @@ func init() {
|
||||
beego.AutoRouter(&controllers.AdminController{})
|
||||
beego.AutoRouter(&controllers.UserController{})
|
||||
|
||||
beego.AutoRouter(&controllers.NotifyTplController{})
|
||||
}
|
||||
|
||||
103
views/notifytpl/add.html
Normal file
103
views/notifytpl/add.html
Normal file
@@ -0,0 +1,103 @@
|
||||
<div class="layui-layout layui-layout-admin" style="padding-left: 40px;margin-top: 20px;">
|
||||
|
||||
<form class="layui-form" action="" method="post">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200">模板名称</label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<input type="text" name="tpl_name" id="tpl_name" lay-verify="required" autocomplete="off"
|
||||
placeholder="模板名称" class="layui-input" value="">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200">模板类型</label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<input type="radio" name="tpl_type" lay-verify="type" value="0" title="邮箱" checked>
|
||||
<input type="radio" name="tpl_type" lay-verify="type" value="1" title="短信" >
|
||||
<input type="radio" name="tpl_type" lay-verify="type" value="2" title="钉钉" >
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200">模板标题</label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<input type="text" name="title" id="title" autocomplete="off"
|
||||
placeholder="模板标题" class="layui-input" value="">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200">模板内容</label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<textarea rows="10" name="content" id="content" placeholder="请输入模板内容" class="layui-textarea"></textarea>
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux" style="padding: 0px 0px !important;">
|
||||
<pre class="layui-code" style="margin: 0;">
|
||||
|
||||
任务 ID {TaskId}
|
||||
任务名称 {TaskName}
|
||||
执行时间 {CreateTime}
|
||||
执行耗时 {ProcessTime}
|
||||
执行状态 {Status}
|
||||
任务输出 {TaskOut}
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200">状态</label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<input type="radio" name="status" lay-verify="type" value="0" title="禁用" checked>
|
||||
<input type="radio" name="status" lay-verify="type" value="1" title="启用" >
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="id" id="id" value="0">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200"></label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
var $;
|
||||
layui.use(['form', 'element', 'layer', 'jquery'], function () {
|
||||
var form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
|
||||
var $ = layui.jquery;
|
||||
|
||||
var error_info = "{{.flash.error}}";
|
||||
if (error_info) {
|
||||
layer.msg(error_info, {icon: 2, shade: 0.3}, function () {
|
||||
window.history.go(-1)
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
form.on('submit(sub)', function (data) {
|
||||
var form_data = $("form").serialize();
|
||||
$.post('{{urlfor "NotifyTplController.AjaxSave"}}', form_data, function (out) {
|
||||
if (out.status == 0) {
|
||||
layer.msg("操作成功", {icon: 1, shade: 0.3, time: 1000}, function () {
|
||||
// window.history.go(-1)//
|
||||
window.location.reload()
|
||||
})
|
||||
} else {
|
||||
layer.msg(out.message)
|
||||
}
|
||||
}, "json");
|
||||
return false;
|
||||
});
|
||||
|
||||
//但是,如果你的HTML是动态生成的,自动渲染就会失效
|
||||
//因此你需要在相应的地方,执行下述方法来手动渲染,跟这类似的还有 element.init();
|
||||
form.render();
|
||||
});
|
||||
</script>
|
||||
103
views/notifytpl/edit.html
Normal file
103
views/notifytpl/edit.html
Normal file
@@ -0,0 +1,103 @@
|
||||
<div class="layui-layout layui-layout-admin" style="padding-left: 40px;margin-top: 20px;">
|
||||
|
||||
<form class="layui-form" action="" method="post">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200">模板名称</label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<input type="text" name="tpl_name" id="tpl_name" lay-verify="required" autocomplete="off"
|
||||
placeholder="模板名称" class="layui-input" value="{{.notifyTpl.tpl_name}}">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200">模板类型</label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<input type="radio" name="tpl_type" lay-verify="type" value="0" title="邮箱" {{if eq .notifyTpl.tpl_type 0}}checked{{end}}>
|
||||
<input type="radio" name="tpl_type" lay-verify="type" value="1" title="短信" {{if eq .notifyTpl.tpl_type 1}}checked{{end}}>
|
||||
<input type="radio" name="tpl_type" lay-verify="type" value="2" title="钉钉" {{if eq .notifyTpl.tpl_type 2}}checked{{end}}>
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200">模板标题</label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<input type="text" name="title" id="title" autocomplete="off"
|
||||
placeholder="模板标题" class="layui-input" value="{{.notifyTpl.title}}">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200">模板内容</label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<textarea rows="10" name="content" id="content" lay-verify="required" placeholder="请输入模板内容"
|
||||
class="layui-textarea">{{.notifyTpl.content}}</textarea>
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux" style="padding: 0px 0px !important;">
|
||||
<pre class="layui-code" style="margin: 0;">
|
||||
|
||||
任务 ID {TaskId}
|
||||
任务名称 {TaskName}
|
||||
执行时间 {CreateTime}
|
||||
执行耗时 {ProcessTime}
|
||||
执行状态 {Status}
|
||||
任务输出 {TaskOut}
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200">状态</label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<input type="radio" name="status" lay-verify="type" value="0" title="禁用" {{if eq .notifyTpl.status 0}}checked{{end}}>
|
||||
<input type="radio" name="status" lay-verify="type" value="1" title="启用" {{if eq .notifyTpl.status 1}}checked{{end}}>
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="id" id="id" value="{{.notifyTpl.id}}">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200"></label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<button class="layui-btn" lay-submit="" lay-filter="sub">立即保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
var $;
|
||||
layui.use(['form', 'element', 'layer', 'jquery'], function () {
|
||||
var form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
|
||||
var $ = layui.jquery;
|
||||
var error_info = "{{.flash.error}}";
|
||||
if (error_info) {
|
||||
layer.msg(error_info, {icon: 2, shade: 0.3}, function () {
|
||||
window.history.go(-1)
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
form.on('submit(sub)', function (data) {
|
||||
var form_data = $("form").serialize();
|
||||
$.post('{{urlfor "NotifyTplController.AjaxSave"}}', form_data, function (out) {
|
||||
if (out.status == 0) {
|
||||
layer.msg("操作成功", {icon: 1, shade: 0.3, time: 1000}, function () {
|
||||
// window.history.go(-1)
|
||||
window.location.reload()
|
||||
})
|
||||
} else {
|
||||
layer.msg(out.message)
|
||||
}
|
||||
}, "json");
|
||||
return false;
|
||||
});
|
||||
|
||||
//但是,如果你的HTML是动态生成的,自动渲染就会失效
|
||||
//因此你需要在相应的地方,执行下述方法来手动渲染,跟这类似的还有 element.init();
|
||||
form.render();
|
||||
});
|
||||
</script>
|
||||
107
views/notifytpl/list.html
Normal file
107
views/notifytpl/list.html
Normal file
@@ -0,0 +1,107 @@
|
||||
<div class="layui-layout layui-layout-admin" style="padding-left: 20px;">
|
||||
<div class="layui-row" style="margin-top: 20px;">
|
||||
<div class="layui-col-xs6">
|
||||
<button class="layui-btn" data-type="tabAdd" id="add">新增</button>
|
||||
</div>
|
||||
<div class="layui-col-xs6 search_text">
|
||||
<form class="layui-form" action="" onsubmit="javascript:return false;">
|
||||
<div class="demoTable">
|
||||
<div class="layui-inline" style="width: 40%">
|
||||
<input class="layui-input" name="tplName" id="tplName" autocomplete="off" placeholder="模板名称">
|
||||
</div>
|
||||
<button class="layui-btn" data-type="reload">查询</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table class="layui-hide" id="table_list" lay-filter="table_filter">
|
||||
</table>
|
||||
|
||||
<script type="text/html" id="bar">
|
||||
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
|
||||
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
|
||||
</script>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
layui.use(['table', 'form', 'element'], function () {
|
||||
var table = layui.table;
|
||||
var form = layui.form;
|
||||
var element = layui.element;
|
||||
var error_info = "{{.flash.error}}";
|
||||
if (error_info) {
|
||||
layer.msg(error_info, {icon: 2, shade: 0.3}, function () {
|
||||
window.history.go(-1)
|
||||
})
|
||||
return;
|
||||
}
|
||||
//方法级渲染
|
||||
table.render({
|
||||
elem: '#table_list'
|
||||
, url: '/notifytpl/table'
|
||||
, cols: [[
|
||||
{checkbox: true, fixed: true},
|
||||
{field: 'id', title: 'ID', align: 'center', sort: true, width: 150},
|
||||
{field: 'type', title: '类型'},
|
||||
{field: 'tpl_name', title: '模板名称'},
|
||||
{field: 'tpl_type_text', title: '模板类型'},
|
||||
{field: 'create_time', title: '创建时间'},
|
||||
{field: 'update_time', title: '更新时间'},
|
||||
{field: 'status_text', title: '状态', sort: true,},
|
||||
{fixed: 'right', width: 160, align: 'center', toolbar: '#bar'}
|
||||
]]
|
||||
, id: 'listReload'
|
||||
, page: true
|
||||
, height: "full-130"
|
||||
});
|
||||
|
||||
var $ = layui.$, active = {
|
||||
reload: function () {
|
||||
table.reload('listReload', {
|
||||
where: {
|
||||
tplName: $('#tplName').val(),
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$("#add").on("click", function () {
|
||||
window.parent.openTab("/notifytpl/add", '新增模板', "notify_tpl_add-0", 'fa-plus');
|
||||
})
|
||||
|
||||
//监听工具条
|
||||
table.on('tool(table_filter)', function (obj) {
|
||||
var data = obj.data;
|
||||
var tplName = data.tpl_name
|
||||
if (obj.event === 'edit') {
|
||||
window.parent.openTab("/notifytpl/edit?id=" + data.id, tplName + '编辑', "notify_tpl_edit-" + data.id, 'fa-edit');
|
||||
} else if (obj.event === 'del') {
|
||||
layer.confirm('真的删除【' + data.tpl_name + '】模板么', function (index) {
|
||||
var jsData = {'id': data.id}
|
||||
$.post('{{urlfor "NotifyTplController.AjaxDel"}}', jsData, function (out) {
|
||||
if (out.status == 0) {
|
||||
layer.alert(out.message, {icon: 1}, function (index) {
|
||||
layer.close(index);
|
||||
window.location.reload();
|
||||
});
|
||||
} else {
|
||||
layer.msg(out.message)
|
||||
}
|
||||
}, "json");
|
||||
// obj.del();
|
||||
layer.close(index);
|
||||
})
|
||||
} else {
|
||||
layer.msg('操作不存在');
|
||||
}
|
||||
});
|
||||
|
||||
$('.demoTable .layui-btn').on('click', function () {
|
||||
var type = $(this).data('type');
|
||||
active[type] ? active[type].call(this) : '';
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
@@ -38,7 +38,7 @@
|
||||
<!-- 左侧导航区域(可配合layui已有的垂直导航) -->
|
||||
<ul class="layui-nav layui-nav-tree" lay-filter="nav-side">
|
||||
<li class="layui-nav-item layui-nav-itemed layui-this">
|
||||
<a data-url="start.html" data-icon="fa-home" data-title="系统首页" data-id="0" class="pointer">
|
||||
<a data-url="/home/start" data-icon="fa-home" data-title="系统首页" data-id="0" class="pointer">
|
||||
<i class="fa fa-home back_space1"></i><span>系统首页</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200">任务名称</label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<input type="text" name="task_name" id="task_name" lay-verify="required" autocomplete="off" placeholder="任务名称" class="layui-input" value="">
|
||||
<input type="text" name="task_name" id="task_name" lay-verify="required" autocomplete="off"
|
||||
placeholder="任务名称" class="layui-input" value="">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
@@ -46,7 +47,8 @@
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200">任务说明</label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<textarea name="description" id="description" rows="2" placeholder="请输入内容" class="layui-textarea"></textarea>
|
||||
<textarea name="description" id="description" rows="2" placeholder="请输入内容"
|
||||
class="layui-textarea"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -58,15 +60,19 @@
|
||||
<input type="radio" name="concurrent" lay-verify="required" value="1" title="否">
|
||||
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"><i class="fa fa-info-circle" aria-hidden="true" id="des"></i></div>
|
||||
<div class="layui-form-mid layui-word-aux"><i class="fa fa-info-circle" aria-hidden="true" id="des"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200">时间表达式</label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<input type="text" name="cron_spec" id="cron_spec" lay-verify="required" autocomplete="off" placeholder="时间表达式" class="layui-input" value="">
|
||||
<input type="text" name="cron_spec" id="cron_spec" lay-verify="required" autocomplete="off"
|
||||
placeholder="时间表达式" class="layui-input" value="">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"><a href="/help" target="_blank"><i class="fa fa-question-circle"
|
||||
aria-hidden="true"></i></a>
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"><a href="/help" target="_blank"><i class="fa fa-question-circle" aria-hidden="true"></i></a></div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
@@ -79,7 +85,8 @@
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200">超时设置</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="timeout" id="timeout" lay-verify="required" autocomplete="off" placeholder="单位:秒,默认一天" class="layui-input" value="">
|
||||
<input type="text" name="timeout" id="timeout" lay-verify="required" autocomplete="off"
|
||||
placeholder="单位:秒,默认一天" class="layui-input" value="">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
@@ -88,18 +95,28 @@
|
||||
<label class="layui-form-label mw200">出错通知</label>
|
||||
<div class="layui-input-inline ">
|
||||
<input type="radio" name="is_notify" lay-verify="required" value="1" lay-filter="is_notify" title="是">
|
||||
<input type="radio" name="is_notify" lay-verify="required" value="0" lay-filter="is_notify" title="否" checked>
|
||||
<input type="radio" name="is_notify" lay-verify="required" value="0" lay-filter="is_notify" title="否"
|
||||
checked>
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item notify">
|
||||
<hr>
|
||||
<label class="layui-form-label mw200">通知类型</label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<input type="radio" name="notify_type" lay-verify="required" value="0" title="邮件" checked>
|
||||
<input type="radio" name="notify_type" lay-verify="required" value="1" title="短信" >
|
||||
<input type="radio" name="notify_type" lay-verify="required" value="2" title="钉钉" >
|
||||
<input type="radio" name="notify_type" value="0" lay-filter="notify_type" title="邮件">
|
||||
<input type="radio" name="notify_type" value="1" lay-filter="notify_type" title="短信">
|
||||
<input type="radio" name="notify_type" value="2" lay-filter="notify_type" title="钉钉">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item notify">
|
||||
<label class="layui-form-label mw200">通知模板</label>
|
||||
<div class="layui-input-inline">
|
||||
<select name="notify_tpl_id" lay-filter="notify_tpl_id">
|
||||
<option value="0" selected>请选择</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
@@ -108,14 +125,14 @@
|
||||
<label class="layui-form-label mw200">通知用户</label>
|
||||
<div class="layui-input-inline mw400 ">
|
||||
{{range $k, $v := .adminInfo}}
|
||||
<input type="checkbox" name="notify_user" lay-filter="notify_user" title="{{$v.RealName}}" value="{{$v.Id}}" lay-skin="primary">
|
||||
<input type="checkbox" name="notify_user" lay-filter="notify_user" title="{{$v.RealName}}"
|
||||
value="{{$v.Id}}" lay-skin="primary">
|
||||
{{end}}
|
||||
<input type="hidden" name="notify_user_ids" id="notify_user_ids" value="">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<input type="hidden" name="id" id="id" value="0">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label mw200"></label>
|
||||
@@ -166,8 +183,6 @@
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
form.on('submit(sub)', function (data) {
|
||||
var form_data = data.field;
|
||||
$.post('{{urlfor "TaskController.AjaxSave"}}', form_data, function (out) {
|
||||
@@ -184,6 +199,22 @@
|
||||
return false;
|
||||
});
|
||||
|
||||
form.on('radio(notify_type)', function (data) {
|
||||
$.post('{{urlfor "TaskController.AjaxNotifyType"}}', {notify_type: data.value}, function (out) {
|
||||
if (out.code == 0) {
|
||||
$('select[name="notify_tpl_id"]').empty();
|
||||
$('<option value="0" selected>请选择</option>').appendTo('select[name="notify_tpl_id"]');
|
||||
for (var i = 0; i < out.data.length; i++) {
|
||||
$('<option value="' + out.data[i].id + '">' + out.data[i].tpl_name + '</option>').appendTo('select[name="notify_tpl_id"]');
|
||||
}
|
||||
|
||||
form.render();
|
||||
} else {
|
||||
layer.msg(out.message)
|
||||
}
|
||||
}, "json");
|
||||
});
|
||||
|
||||
//但是,如果你的HTML是动态生成的,自动渲染就会失效
|
||||
//因此你需要在相应的地方,执行下述方法来手动渲染,跟这类似的还有 element.init();
|
||||
form.render();
|
||||
|
||||
@@ -94,12 +94,24 @@
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item notify">
|
||||
<hr>
|
||||
<label class="layui-form-label mw200">通知类型</label>
|
||||
<div class="layui-input-inline mw400">
|
||||
<input type="radio" name="notify_type" lay-verify="required" value="0" title="邮件" {{if eq .task.NotifyType 0}}checked{{end}}>
|
||||
<input type="radio" name="notify_type" lay-verify="required" value="1" title="短信" {{if eq .task.NotifyType 1}}checked{{end}}>
|
||||
<input type="radio" name="notify_type" lay-verify="required" value="2" title="钉钉" {{if eq .task.NotifyType 2}}checked{{end}}>
|
||||
<input type="radio" name="notify_type" value="0" lay-filter="notify_type" title="邮件" {{if eq .task.NotifyType 0}}checked{{end}}>
|
||||
<input type="radio" name="notify_type" value="1" lay-filter="notify_type" title="短信" {{if eq .task.NotifyType 1}}checked{{end}}>
|
||||
<input type="radio" name="notify_type" value="2" lay-filter="notify_type" title="钉钉" {{if eq .task.NotifyType 2}}checked{{end}}>
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item notify">
|
||||
<label class="layui-form-label mw200">通知模板</label>
|
||||
<div class="layui-input-inline">
|
||||
<select name="notify_tpl_id" lay-filter="notify_tpl_id">
|
||||
<option value="0">请选择</option>
|
||||
{{range $k, $v := .notifyTpl}}
|
||||
<option value="{{$v.id}}" {{if eq $.task.NotifyTplId $v.id}} selected {{end}}>{{$v.tpl_name}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
@@ -202,6 +214,22 @@
|
||||
});
|
||||
});
|
||||
|
||||
form.on('radio(notify_type)', function (data) {
|
||||
$.post('{{urlfor "TaskController.AjaxNotifyType"}}', {notify_type: data.value}, function (out) {
|
||||
if (out.code == 0) {
|
||||
$('select[name="notify_tpl_id"]').empty();
|
||||
$('<option value="0" selected>请选择</option>').appendTo('select[name="notify_tpl_id"]');
|
||||
for (var i = 0; i < out.data.length; i++) {
|
||||
$('<option value="' + out.data[i].id + '">' + out.data[i].tpl_name + '</option>').appendTo('select[name="notify_tpl_id"]');
|
||||
}
|
||||
|
||||
form.render();
|
||||
} else {
|
||||
layer.msg(out.message)
|
||||
}
|
||||
}, "json");
|
||||
});
|
||||
|
||||
//但是,如果你的HTML是动态生成的,自动渲染就会失效
|
||||
//因此你需要在相应的地方,执行下述方法来手动渲染,跟这类似的还有 element.init();
|
||||
form.render();
|
||||
|
||||
@@ -153,7 +153,13 @@
|
||||
{{if eq .task.IsNotify 1}}
|
||||
<tr>
|
||||
<td>通知类型</td>
|
||||
<td>{{if eq .task.NotifyType 1}}短信{{end}} {{if eq .task.NotifyType 0}}邮件{{end}}</td>
|
||||
<td>{{if eq .task.NotifyType 1}}短信{{end}} {{if eq .task.NotifyType 0}}邮件{{end}} {{if eq .task.NotifyType 2}}钉钉{{end}}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>通知模板</td>
|
||||
<td>{{.NotifyTplName}}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user