345 行
14 KiB
JavaScript
345 行
14 KiB
JavaScript
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
|
|
|
|
var Controller = {
|
|
index: function () {
|
|
var vue = new Vue({
|
|
el: '#vue',
|
|
data: {
|
|
// app版本号
|
|
appCode: '',
|
|
// 表格当前页数据
|
|
tableData: [],
|
|
// 多选数组
|
|
multipleSelection: [],
|
|
// 搜索条件
|
|
key: '',
|
|
// 默认每页数据量
|
|
pageSize: 50,
|
|
// 当前页码
|
|
currentPage: 1,
|
|
// 默认数据总数
|
|
totalCount: 0,
|
|
// 列表加载遮罩
|
|
listLoading: false,
|
|
formData: {},
|
|
addDialog: false,
|
|
submitLoading: false,
|
|
title: '',
|
|
// 搜索字段
|
|
search: {
|
|
startTime: '',
|
|
endTime: '',
|
|
keyword: '',
|
|
type: '',
|
|
sort: 'id',
|
|
status: '',
|
|
cid: 0,
|
|
},
|
|
searchOpt: [{
|
|
id: 1,
|
|
value: '版本名称号'
|
|
}, {
|
|
id: 2,
|
|
value: 'app版本号'
|
|
}, {
|
|
id: 3,
|
|
value: '更新内容'
|
|
}],
|
|
statusOpt: [{
|
|
id: 1,
|
|
value: '启用'
|
|
}, {
|
|
id: 2,
|
|
value: '禁用'
|
|
}],
|
|
// 表单验证规则
|
|
rules: {
|
|
name: [{
|
|
required: true,
|
|
message: '请您输入版本名称号',
|
|
trigger: 'blur'
|
|
}],
|
|
url: [{
|
|
required: true,
|
|
message: '请您输入APP下载链接',
|
|
trigger: 'blur'
|
|
}],
|
|
},
|
|
sendStartTime: '',
|
|
sendEndTime: '',
|
|
// 时间格式化
|
|
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.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort);
|
|
},
|
|
methods: {
|
|
// 刷新页面
|
|
refreshPage() {
|
|
this.search = {
|
|
startTime: '',
|
|
endTime: '',
|
|
keyword: '',
|
|
type: '',
|
|
sort: 'id',
|
|
status: ''
|
|
};
|
|
|
|
this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort);
|
|
},
|
|
handleSeeDownUrl(url) {
|
|
window.open(url, '_blank');
|
|
},
|
|
addContent() {
|
|
this.formData.content.push({
|
|
content: '',
|
|
})
|
|
},
|
|
handleDelContent(index) {
|
|
this.$confirm('你是否要删除该内容?, 是否继续?', '温馨提示', {
|
|
confirmButtonText: '确定',
|
|
cancelButtonText: '取消',
|
|
type: 'info'
|
|
}).then(() => {
|
|
this.formData.content.splice(index, 1);
|
|
}).catch(() => {
|
|
|
|
});
|
|
},
|
|
// 添加/编辑
|
|
openAddDialog(type, item) {
|
|
this.addDialog = true;
|
|
if (type === 'add') {
|
|
this.title = '添加';
|
|
this.formData = {
|
|
id: 0,
|
|
code: this.appCode,
|
|
name: '',
|
|
content: [],
|
|
status: 1,
|
|
};
|
|
} else {
|
|
this.title = '编辑';
|
|
this.formData = {
|
|
id: item.id,
|
|
code: item.code,
|
|
name: item.name,
|
|
content: item.content,
|
|
url: item.url,
|
|
status: item.status,
|
|
};
|
|
}
|
|
},
|
|
// 从服务器读取数据
|
|
loadData(key, currentPage, pageSize, sort) {
|
|
this.listLoading = true;
|
|
$.getJSON('Upgrade/index', {
|
|
keyword: key,
|
|
type: this.search.type,
|
|
start_time: this.sendStartTime,
|
|
end_time: this.sendEndTime,
|
|
page: currentPage,
|
|
rows: pageSize,
|
|
sort: sort,
|
|
status: this.search.status,
|
|
}, data => {
|
|
this.totalCount = data.total;
|
|
this.tableData = data.list;
|
|
this.appCode = data.appCode;
|
|
this.listLoading = false;
|
|
});
|
|
},
|
|
submit() {
|
|
this.$refs.form.validate(valid => {
|
|
if (!valid) {
|
|
return false;
|
|
}
|
|
|
|
if (!this.formData.content.length) {
|
|
this.$message.warning('请您添加更新内容');
|
|
return false;
|
|
}
|
|
|
|
for (item of this.formData.content) {
|
|
if (!item.content) {
|
|
this.$message.warning('请您完善更新内容');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// 正在提交中
|
|
if (this.submitLoading) {
|
|
return false;
|
|
}
|
|
|
|
this.submitLoading = true;
|
|
|
|
$.ajax({
|
|
url: 'Upgrade/add',
|
|
type: 'POST',
|
|
data: this.formData,
|
|
success: res => {
|
|
this.submitLoading = false;
|
|
if (res.code === 200) {
|
|
this.$message.success(res.msg);
|
|
this.addDialog = false;
|
|
this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort);
|
|
} else {
|
|
this.$message.warning(res.msg);
|
|
}
|
|
}
|
|
})
|
|
});
|
|
},
|
|
// 排序
|
|
sortChange(e) {
|
|
|
|
},
|
|
// 搜索
|
|
searchData() {
|
|
this.sendStartTime = this.search.startTime !== '' ? +this.search.startTime / 1000 : '';
|
|
this.sendEndTime = this.search.endTime !== '' ? +this.search.endTime / 1000 : '';
|
|
this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort);
|
|
},
|
|
// 每页显示数据量变更
|
|
handleSizeChange(val) {
|
|
this.pageSize = val;
|
|
this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort);
|
|
},
|
|
// 页码变更
|
|
handleCurrentChange(val) {
|
|
this.currentPage = val;
|
|
this.loadData(this.search.keyword, 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: 'Upgrade/dell',
|
|
data: "id=" + array,
|
|
type: "POST",
|
|
dataType: 'json',
|
|
success: res => {
|
|
if (res.code === 200) {
|
|
this.$message.success(res.msg);
|
|
this.loadData(this.search.keyword, 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: 'Upgrade/dell',
|
|
data: {
|
|
id
|
|
},
|
|
type: "POST",
|
|
dataType: 'json',
|
|
success: res => {
|
|
if (res.code === 200) {
|
|
this.$message.success(res.msg);
|
|
this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort);
|
|
} else {
|
|
this.$message.warning(res.msg);
|
|
}
|
|
},
|
|
error: function (er) {
|
|
|
|
}
|
|
});
|
|
}).catch(() => {
|
|
|
|
});
|
|
},
|
|
// 状态改变
|
|
statusChange(row) {
|
|
// 提交
|
|
let loading = this.$loading({
|
|
lock: true,
|
|
text: '正在更改中...',
|
|
spinner: 'el-icon-loading',
|
|
background: 'rgba(0, 0, 0, 0.3)'
|
|
});
|
|
$.ajax({
|
|
url: 'Upgrade/status',
|
|
data: {
|
|
id: row.id,
|
|
status: row.status
|
|
},
|
|
type: 'GET',
|
|
success: res => {
|
|
loading.close();
|
|
if (res.code === 200) {
|
|
this.$message.success(res.msg);
|
|
} else {
|
|
this.$message.warning(res.msg);
|
|
}
|
|
},
|
|
error: function (er) {
|
|
|
|
}
|
|
});
|
|
},
|
|
handleClearSelect(field) {
|
|
// 重新加载
|
|
this.$set(this.search, field, '');
|
|
this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort);
|
|
},
|
|
handleClearSearchInp() {
|
|
if (this.search.type) {
|
|
// 重新加载
|
|
this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort);
|
|
}
|
|
},
|
|
}
|
|
});
|
|
},
|
|
edit: function () {
|
|
Controller.api.bindevent();
|
|
},
|
|
api: {
|
|
bindevent: function () {
|
|
Form.api.bindevent($("form[role=form]"));
|
|
}
|
|
}
|
|
};
|
|
return Controller;
|
|
});
|