515
public/assets/js/backend/notice.js
普通文件
515
public/assets/js/backend/notice.js
普通文件
@@ -0,0 +1,515 @@
|
||||
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
|
||||
|
||||
var Controller = {
|
||||
index: function () {
|
||||
var vue = new Vue({
|
||||
el: '#vue',
|
||||
data: {
|
||||
showSearchBox: false,
|
||||
// 表格当前页数据
|
||||
tableData: [],
|
||||
// 多选数组
|
||||
multipleSelection: [],
|
||||
// 搜索条件
|
||||
key: '',
|
||||
// 默认每页数据量
|
||||
pageSize: 50,
|
||||
// 当前页码
|
||||
currentPage: 1,
|
||||
// 默认数据总数
|
||||
totalCount: 0,
|
||||
// 列表加载遮罩
|
||||
listLoading: false,
|
||||
// 搜索字段
|
||||
search: {
|
||||
dateTime: '',
|
||||
title: '',
|
||||
desc: '',
|
||||
content: '',
|
||||
sort: 'id',
|
||||
status: 0,
|
||||
},
|
||||
pickerOptions: {
|
||||
shortcuts: [{
|
||||
text: '昨日',
|
||||
onClick(picker) {
|
||||
const start = moment().subtract(1, 'days').startOf('day').toDate();
|
||||
const end = moment().subtract(1, 'days').endOf('day').toDate();
|
||||
|
||||
picker.$emit('pick', [start, end]);
|
||||
}
|
||||
}, {
|
||||
text: '今日',
|
||||
onClick(picker) {
|
||||
const start = moment().startOf('day').toDate();
|
||||
const end = moment()
|
||||
.endOf('day')
|
||||
.seconds(59)
|
||||
.minutes(59)
|
||||
.hours(23)
|
||||
.toDate();
|
||||
|
||||
picker.$emit('pick', [start, end]);
|
||||
}
|
||||
}, {
|
||||
text: '近7天',
|
||||
onClick(picker) {
|
||||
const start = moment().subtract(7, 'days').startOf('day').toDate();
|
||||
const end = moment()
|
||||
.endOf('day')
|
||||
.seconds(59)
|
||||
.minutes(59)
|
||||
.hours(23)
|
||||
.toDate();
|
||||
|
||||
picker.$emit('pick', [start, end]);
|
||||
}
|
||||
}, {
|
||||
text: '本月',
|
||||
onClick(picker) {
|
||||
const start = moment().startOf('month').startOf('day').toDate();
|
||||
const end = moment().endOf('month').endOf('day').toDate();
|
||||
picker.$emit('pick', [start, end]);
|
||||
}
|
||||
}, {
|
||||
text: '今年',
|
||||
onClick(picker) {
|
||||
const start = moment().startOf('year').startOf('day').toDate();
|
||||
const end = moment().endOf('year').endOf('day').toDate();
|
||||
picker.$emit('pick', [start, end]);
|
||||
}
|
||||
}]
|
||||
},
|
||||
// 时间格式化
|
||||
dateFormat: function (row, column) {
|
||||
var date = row[column.property];
|
||||
if (date === undefined || date === 0) {
|
||||
return '';
|
||||
}
|
||||
return moment(date * 1000).format("YYYY-MM-DD HH:mm:ss");
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.search.cid = $('#vue').data('cid');
|
||||
this.loadData(this.currentPage, this.pageSize, this.search.sort);
|
||||
},
|
||||
methods: {
|
||||
// 刷新页面
|
||||
refreshPage() {
|
||||
this.search = {
|
||||
dateTime: '',
|
||||
title: '',
|
||||
desc: '',
|
||||
content: '',
|
||||
sort: 'id',
|
||||
status: 0,
|
||||
};
|
||||
this.loadData(this.currentPage, this.pageSize, this.search.sort);
|
||||
},
|
||||
// 搜索组显示隐藏
|
||||
handleClickSearchBox() {
|
||||
this.showSearchBox = !this.showSearchBox;
|
||||
},
|
||||
handleChangeDateTime(e) {
|
||||
if (!e) {
|
||||
// 重新加载
|
||||
this.loadData(this.currentPage, this.pageSize, this.search.sort);
|
||||
} else if (e[0] === e[1]) {
|
||||
this.search.dateTime = [
|
||||
e[0],
|
||||
e[0].split(' ')[0] + ' 23:59:59'
|
||||
];
|
||||
}
|
||||
},
|
||||
// 添加
|
||||
add(cid, mode, type) {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '添加公告',
|
||||
shadeClose: false,
|
||||
scrollbar: false,
|
||||
maxmin: true,
|
||||
shade: 0.2,
|
||||
area: ['100%', '100%'],
|
||||
content: 'add'
|
||||
});
|
||||
},
|
||||
// 编辑
|
||||
edit(id) {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '编辑公告',
|
||||
shadeClose: false,
|
||||
scrollbar: false,
|
||||
maxmin: true,
|
||||
shade: 0.2,
|
||||
area: ['100%', '100%'],
|
||||
content: 'add?id=' + id,
|
||||
});
|
||||
},
|
||||
// 从服务器读取数据
|
||||
loadData(currentPage, pageSize, sort) {
|
||||
this.listLoading = true;
|
||||
$.getJSON('notice/index', {
|
||||
search: this.search,
|
||||
page: currentPage,
|
||||
rows: pageSize,
|
||||
sort: sort,
|
||||
}, data => {
|
||||
this.totalCount = data.total;
|
||||
this.tableData = data.list;
|
||||
this.listLoading = false;
|
||||
});
|
||||
},
|
||||
// 排序
|
||||
sortChange(e) {
|
||||
|
||||
},
|
||||
// 搜索
|
||||
searchData() {
|
||||
this.loadData(this.currentPage, this.pageSize, this.search.sort);
|
||||
},
|
||||
// 每页显示数据量变更
|
||||
handleSizeChange(val) {
|
||||
this.pageSize = val;
|
||||
this.loadData(this.currentPage, this.pageSize, this.search.sort);
|
||||
},
|
||||
// 页码变更
|
||||
handleCurrentChange(val) {
|
||||
this.currentPage = val;
|
||||
this.loadData(this.currentPage, this.pageSize, this.search.sort);
|
||||
},
|
||||
// 多选响应
|
||||
handleSelectionChange(val) {
|
||||
this.multipleSelection = val;
|
||||
},
|
||||
// 批量删除
|
||||
del() {
|
||||
if (this.multipleSelection.length === 0) {
|
||||
this.$message.warning('请选择至少一条公告进行删除!');
|
||||
return;
|
||||
}
|
||||
var array = [];
|
||||
this.multipleSelection.forEach((row) => {
|
||||
array.push(row.id);
|
||||
});
|
||||
|
||||
this.$confirm('您确定要删除所选的公告吗?, 是否继续?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
$.ajax({
|
||||
url: 'notice/dell',
|
||||
data: "id=" + array,
|
||||
type: "POST",
|
||||
dataType: 'json',
|
||||
success: res => {
|
||||
if (res.code === 200) {
|
||||
this.$message.success(res.msg);
|
||||
this.loadData(this.currentPage, this.pageSize, this.search.sort);
|
||||
} else {
|
||||
this.$message.warning(res.msg);
|
||||
}
|
||||
},
|
||||
error: function (er) {
|
||||
|
||||
}
|
||||
});
|
||||
}).catch(() => {
|
||||
|
||||
});
|
||||
},
|
||||
// 单条删除
|
||||
dell(id) {
|
||||
this.$confirm('您确定要删除此公告吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
$.ajax({
|
||||
url: 'notice/dell',
|
||||
data: {
|
||||
id
|
||||
},
|
||||
type: "POST",
|
||||
dataType: 'json',
|
||||
success: res => {
|
||||
if (res.code === 200) {
|
||||
this.$message.success(res.msg);
|
||||
this.loadData(this.currentPage, this.pageSize, this.search.sort);
|
||||
} else {
|
||||
this.$message.warning(res.msg);
|
||||
}
|
||||
},
|
||||
error: function (er) {
|
||||
|
||||
}
|
||||
});
|
||||
}).catch(() => {
|
||||
|
||||
});
|
||||
},
|
||||
// 状态改变
|
||||
statusChange(row) {
|
||||
let status = parseInt(row.status) === 1 ? 2 : 1;
|
||||
// 提交
|
||||
let loading = this.$loading({
|
||||
lock: true,
|
||||
text: '正在更改中...',
|
||||
spinner: 'el-icon-loading',
|
||||
background: 'rgba(0, 0, 0, 0.3)'
|
||||
});
|
||||
$.ajax({
|
||||
url: 'notice/status',
|
||||
data: {
|
||||
id: row.id,
|
||||
status
|
||||
},
|
||||
type: 'GET',
|
||||
success: res => {
|
||||
loading.close();
|
||||
if (res.code === 200) {
|
||||
this.$message.success(res.msg);
|
||||
let index = this.tableData.findIndex(v => v.id == row.id);
|
||||
this.$set(this.tableData[index], 'status', status)
|
||||
} else {
|
||||
this.$message.warning(res.msg);
|
||||
}
|
||||
},
|
||||
error: function (er) {
|
||||
|
||||
}
|
||||
});
|
||||
},
|
||||
handleClearSelect(field) {
|
||||
// 重新加载
|
||||
this.$set(this.search, field, '');
|
||||
this.loadData(this.currentPage, this.pageSize, this.search.sort);
|
||||
},
|
||||
handleClearSearchInp() {
|
||||
// 重新加载
|
||||
this.loadData(this.currentPage, this.pageSize, this.search.sort);
|
||||
},
|
||||
}
|
||||
});
|
||||
},
|
||||
add: function () {
|
||||
var ue = UE.getEditor('v-content', {});
|
||||
|
||||
let vue = new Vue({
|
||||
el: '#vue',
|
||||
data: {
|
||||
// 字段信息
|
||||
formData: {
|
||||
id: 0,
|
||||
title: '',
|
||||
cover: '',
|
||||
content: '',
|
||||
views: 0,
|
||||
status: '1',
|
||||
type: 1,
|
||||
desc: '',
|
||||
},
|
||||
// 表单验证规则
|
||||
rules: {
|
||||
title: [{
|
||||
required: true,
|
||||
message: '请您输入标题',
|
||||
trigger: 'blur'
|
||||
}],
|
||||
desc: [{
|
||||
required: true,
|
||||
message: '请您输入描述',
|
||||
trigger: 'blur'
|
||||
}],
|
||||
cover: [{
|
||||
required: true,
|
||||
message: '请您上传封面图',
|
||||
trigger: 'blur'
|
||||
}],
|
||||
sendStartTime: '',
|
||||
sendEndTime: ''
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
let vue = $('#vue');
|
||||
this.content();
|
||||
},
|
||||
methods: {
|
||||
// 获取修改数据
|
||||
content() {
|
||||
let id = $('#vue').data('id');
|
||||
if (id > 0) {
|
||||
let loading = this.$loading({
|
||||
lock: true,
|
||||
text: '正在获取数据...',
|
||||
spinner: 'el-icon-loading',
|
||||
background: 'rgba(0, 0, 0, 0.3)'
|
||||
});
|
||||
$.ajax({
|
||||
url: 'notice/getContent',
|
||||
type: 'GET',
|
||||
data: {
|
||||
id
|
||||
},
|
||||
success: res => {
|
||||
loading.close();
|
||||
if (res.code === 200) {
|
||||
let data = res.data;
|
||||
this.formData = {
|
||||
id: data.id,
|
||||
title: data.title,
|
||||
desc: data.desc,
|
||||
sort: data.sort,
|
||||
cover: data.cover,
|
||||
content: '',
|
||||
views: data.views,
|
||||
type: data.type,
|
||||
status: data.status.toString()
|
||||
};
|
||||
} else {
|
||||
this.$message.warning(res.msg);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
// 选择图片
|
||||
selectImage() {
|
||||
Fast.api.open("general/file?multiple=false&select=1", '选择图片', {
|
||||
callback: res => {
|
||||
this.$set(this.formData, 'cover', res.url);
|
||||
}
|
||||
});
|
||||
},
|
||||
// 关闭layer弹窗
|
||||
closeLayerDialog() {
|
||||
// 关闭弹窗
|
||||
var win = parent.layer.getFrameIndex(window.name);
|
||||
parent.layer.close(win);
|
||||
},
|
||||
// 提交
|
||||
submit() {
|
||||
this.$refs.form.validate(valid => {
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
// 获取编辑器公告
|
||||
let content = UE.getEditor('v-content').getContent();
|
||||
if (content === '') {
|
||||
this.$message.warning('请您输入详细公告内容');
|
||||
UE.getEditor('v-content').focus();
|
||||
return;
|
||||
}
|
||||
// 提交
|
||||
let loading = this.$loading({
|
||||
lock: true,
|
||||
text: '正在提交中...',
|
||||
spinner: 'el-icon-loading',
|
||||
background: 'rgba(0, 0, 0, 0.3)'
|
||||
});
|
||||
|
||||
this.formData.content = content;
|
||||
$.ajax({
|
||||
url: 'notice/add',
|
||||
type: 'POST',
|
||||
data: this.formData,
|
||||
success: res => {
|
||||
loading.close();
|
||||
if (res.code === 200) {
|
||||
parent.layer.msg(res.msg, {icon: 1, time: 2000, shade: 0.1}, function (index) {
|
||||
// 关闭弹窗
|
||||
var win = parent.layer.getFrameIndex(window.name);
|
||||
parent.layer.close(win);
|
||||
parent.window.location.reload();
|
||||
});
|
||||
} else {
|
||||
this.$message.warning(res.msg);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
page: function () {
|
||||
var ue = UE.getEditor('v-content', {});
|
||||
|
||||
let vue = new Vue({
|
||||
el: '#vue',
|
||||
data: {
|
||||
// 字段信息
|
||||
formData: {
|
||||
id: 0,
|
||||
title: '',
|
||||
content: '',
|
||||
views: 0,
|
||||
cid: 0,
|
||||
type: '',
|
||||
mode: 'page'
|
||||
},
|
||||
// 表单验证规则
|
||||
rules: {}
|
||||
},
|
||||
mounted() {
|
||||
let vue = $('#vue');
|
||||
this.formData.cid = vue.data('cid');
|
||||
this.formData.title = vue.data('title');
|
||||
this.formData.id = vue.data('id');
|
||||
this.formData.type = vue.data('type');
|
||||
this.formData.views = vue.data('views');
|
||||
},
|
||||
methods: {
|
||||
// 提交
|
||||
submit() {
|
||||
this.$refs.form.validate(valid => {
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
// 获取编辑器公告
|
||||
let content = UE.getEditor('v-content').getContent();
|
||||
if (content === '') {
|
||||
this.$message.warning('请您输入详细公告');
|
||||
UE.getEditor('v-content').focus();
|
||||
return;
|
||||
}
|
||||
// 提交
|
||||
let loading = this.$loading({
|
||||
lock: true,
|
||||
text: '正在提交中...',
|
||||
spinner: 'el-icon-loading',
|
||||
background: 'rgba(0, 0, 0, 0.3)'
|
||||
});
|
||||
|
||||
this.formData.content = content;
|
||||
$.ajax({
|
||||
url: 'notice/page',
|
||||
type: 'POST',
|
||||
data: this.formData,
|
||||
success: res => {
|
||||
loading.close();
|
||||
if (res.code === 200) {
|
||||
this.$message.success(res.msg);
|
||||
} else {
|
||||
this.$message.warning(res.msg);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
edit: function () {
|
||||
Controller.api.bindevent();
|
||||
},
|
||||
api: {
|
||||
bindevent: function () {
|
||||
Form.api.bindevent($("form[role=form]"));
|
||||
}
|
||||
}
|
||||
};
|
||||
return Controller;
|
||||
});
|
||||
在新工单中引用
屏蔽一个用户