Files
peko-admin-web/src/views/app/AppUpdateView.vue
2024-04-22 10:45:13 +08:00

441 lines
20 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<section class="content">
<div class="box box-primary">
<div class="box-body">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1 id="itemTitle"></h1>
</section>
<div id="toolbar">
<div class="col-sm-12">
<button id="btnAddModal" class="btn btn-default">
<i class="glyphicon glyphicon-plus"></i>新增
</button>
</div>
</div>
</div>
<!-- .content -->
<div id="table"></div>
</div>
</section>
<!-- 增加弹框 -->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title" id="addModalLabel">新增</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" id="addModalForm">
<div class="form-group">
<label for="modal_name" class="col-sm-3 control-label">策略名称<font color="red">*</font></label>
<div class="col-sm-9">
<input type="text" class="form-control" name="name" id="modal_name" placeholder="">
</div>
</div>
<div class="form-group">
<label for="modal_forceUpdate" class="col-sm-3 control-label">是否强制更新<font color="red">*</font>
</label>
<div class="col-sm-9">
<select name="forceUpdate" id="modal_forceUpdate">
<option value="true">强制</option>
<option value="false">非强制</option>
</select>
</div>
</div>
<div class="form-group">
<label for="modal_channel" class="col-sm-3 control-label">渠道<font color="red">*</font></label>
<div class="col-sm-9">
<input type="text" class="form-control" name="channel" id="modal_channel" placeholder="">
</div>
</div>
<div class="form-group">
<label for="modal_version" class="col-sm-3 control-label">版本号<font color="red">*</font></label>
<div class="col-sm-9">
<input type="text" class="form-control" name="version" id="modal_version" placeholder="">
</div>
</div>
<div class="form-group">
<label for="modal_jumpLink" class="col-sm-3 control-label">跳转链接<font color="red">*</font>
</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="jumpLink" id="modal_jumpLink" placeholder="">
</div>
</div>
<div class="form-group">
<label for="modal_message" class="col-sm-3 control-label">更新文案<font color="red">*</font>
</label>
<div class="col-sm-9">
<textarea class="form-control" name="message" id="modal_message"
style="height:150px;"></textarea>
</div>
</div>
<div class="form-group">
<label for="modal_status" class="col-sm-3 control-label">状态<font color="red">*</font></label>
<div class="col-sm-9">
<select name="status" id="modal_status">
<option value="0">生效</option>
<option value="1">失效</option>
</select>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary" id="btnAddModalConfirm">确定</button>
</div>
</div>
</div>
</div>
<!-- 编辑弹框 -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title" id="editModalLabel">编辑</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" id="addForm">
<input type="hidden" name="id" id="id" />
<div class="form-group">
<label for="name" class="col-sm-3 control-label">策略名称<font color="red">*</font></label>
<div class="col-sm-9">
<input type="text" class="form-control" name="name" id="name" placeholder="">
</div>
</div>
<div class="form-group">
<label for="forceUpdate" class="col-sm-3 control-label">是否强制更新<font color="red">*</font>
</label>
<div class="col-sm-9">
<select name="forceUpdate" id="forceUpdate">
<option value="true">强制</option>
<option value="false">非强制</option>
</select>
</div>
</div>
<div class="form-group">
<label for="channel" class="col-sm-3 control-label">渠道<font color="red">*</font></label>
<div class="col-sm-9">
<input type="text" class="form-control" name="channel" id="channel" placeholder="">
</div>
</div>
<div class="form-group">
<label for="version" class="col-sm-3 control-label">版本号<font color="red">*</font></label>
<div class="col-sm-9">
<input type="text" class="form-control" name="version" id="version" placeholder="">
</div>
</div>
<div class="form-group">
<label for="jumpLink" class="col-sm-3 control-label">跳转链接<font color="red">*</font></label>
<div class="col-sm-9">
<input type="text" class="form-control" name="jumpLink" id="jumpLink" placeholder="">
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-3 control-label">更新文案<font color="red">*</font></label>
<div class="col-sm-9">
<textarea class="form-control" name="message" id="message" style="height:150px;"></textarea>
</div>
</div>
<div class="form-group">
<label for="status" class="col-sm-3 control-label">状态<font color="red">*</font></label>
<div class="col-sm-9">
<select name="status" id="status">
<option value="0">生效</option>
<option value="1">失效</option>
</select>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary" id="btnEditModalConfirm">确定</button>
</div>
</div>
</div>
</div>
</template>
<script>
import TableHelper from '@/utils/bootstrap-table-helper';
export default {
name: "AppUpdateView",
setup() {
return {};
},
created() {
this.$nextTick(function () {
this.initData();
});
},
methods: {
initData() {
$(function () {
$('.datetime').datetimepicker({
format: 'yyyy-mm-dd hh:ii:00',
autoclose: true
});
$('#table').bootstrapTable('destroy');
$('#table').bootstrapTable({
columns: [
{ field: 'id', title: 'ID', align: 'center', width: '5%' },
{ field: 'name', title: '策略名称', align: 'center', width: '10%' },
{
field: 'forceUpdate', title: '升级方式', align: 'center', width: '5%',
formatter: function (val, row, index) {
return val ? "强制" : "非强制";
}
},
{ field: 'channel', title: '面向渠道', align: 'center', width: '5%' },
{ field: 'version', title: '面向版本', align: 'center', width: '10%' },
{ field: 'jumpLink', title: '跳转链接', align: 'center', width: '5%' },
{ field: 'message', title: '升级文案', align: 'center', width: '10%' },
{
field: 'status', title: '状态', align: 'center', width: '5%',
formatter: function (val, row, index) {
if (val) {
return "失效";
} else {
return '<font color="green">生效</font>';
}
}
},
{
field: 'id',
title: '操作',
align: 'center',
width: '10%',
formatter: function (val, row, index) {
return '<button id="btnEdit" name="btnEdit" class="btn btn-sm btn-success opt-edit" data-id=' + val + '>' +
'<i class="glyphicon glyphicon-edit"></i> 编辑</button>';
}
}
],
undefinedText: "0",
cache: false,
striped: true,
showRefresh: false,
pageSize: 20,
pagination: true,
pageList: [20, 50, 100, 200, 300, 500],
search: false,
sidePagination: "server", //表示服务端请求
queryParamsType: "undefined",
queryParams: function queryParams(params) { //设置查询参数
var param = {
page: params.pageNumber,
pageSize: params.pageSize,
};
return param;
},
ajax: function (request) { //使用ajax请求
$.ajax({
type: "GET",
url: '/admin/appUpdate/list',
contentType: 'application/json;charset=utf-8',
dataType: 'json',
data: request.data,
success: function (res) {
apiResult(res);
request.success({
rows: res.data.rows,
total: res.data.total
});
},
error: function (req) {
serverError(req);
}
})
},
toolbar: '#toolbar',
onLoadSuccess: function () { //加载成功时执行
console.log("load success");
},
onLoadError: function () { //加载失败时执行
console.log("load fail");
}
});
// 查询刷新
$('#btnSearch').on('click', function () {
TableHelper.doRefresh('#table');
});
// 添加打开弹窗
$("#btnAddModal").on('click', function () {
//清除数据
$('#addModal').find('input').val('');
$('#addModal').find('textarea').val('');
$('#addModal').modal('show');
});
// 添加
$("#btnAddModalConfirm").click(function () {
if ($("#addModalForm").validationEngine('validate')) {
$.ajax({
type: "post",
url: "/admin/appUpdate/save",
data: {
name: $("#modal_name").val(),
forceUpdate: $("#modal_forceUpdate").val(),
channel: $("#modal_channel").val(),
version: $("#modal_version").val(),
jumpLink: $("#modal_jumpLink").val(),
message: $("#modal_message").val(),
status: $("#modal_status").val(),
os: 'iOS',
},
dataType: "json",
success: function (json) {
if (apiResult(json)) {
$("#tipMsg").text("保存成功");
$("#tipModal").modal('show');
$("#addModal").modal('hide');
TableHelper.doRefresh('#table');
} else {
$("#tipMsg").text("保存失败." + json.data.msg);
$("#tipModal").modal('show');
$("#addModal").modal('hide');
}
},
error: function (req) {
serverError(req);
}
});
}
});
// 编辑
$("#btnEditModalConfirm").click(function () {
if ($("#editForm").validationEngine('validate')) {
$.ajax({
type: "post",
url: "/admin/appUpdate/save",
data: {
id: $("#id").val(),
name: $("#name").val(),
forceUpdate: $("#forceUpdate").val(),
channel: $("#channel").val(),
version: $("#version").val(),
jumpLink: $("#jumpLink").val(),
message: $("#message").val(),
status: $("#status").val(),
os: 'iOS',
},
dataType: "json",
success: function (json) {
if (apiResult(json)) {
$("#tipMsg").text("保存成功");
$("#tipModal").modal('show');
$("#editModal").modal('hide');
TableHelper.doRefresh('#table');
} else {
$("#tipMsg").text("保存失败." + json.data.msg);
$("#tipModal").modal('show');
$("#editModal").modal('hide');
}
},
error: function (req) {
serverError(req);
}
});
}
});
// 编辑获取信息
$("#table").on("click", '.opt-edit', function () {
var id = $(this).attr("data-id");
console.log(id);
$.ajax({
type: "get",
url: "/admin/appUpdate/get",
data: { id: id },
dataType: "json",
success: function (ret) {
if (apiResult(ret)) {
var json = ret.data;
$("#id").val(id);
$("#name").val(json.name);
if (json.forceUpdate) {
$("#forceUpdate").val("true");
} else {
$("#forceUpdate").val("false");
}
$("#channel").val(json.channel);
$("#version").val(json.version);
$("#jumpLink").val(json.jumpLink);
$("#message").val(json.message);
$("#status").val(json.status);
// 打开编辑弹窗
$("#editModal").modal('show');
} else {
$("#tipMsg").text("获取信息出错");
$("#tipModal").modal('show');
}
},
error: function (req) {
serverError(req);
}
});
});
function serverError(req) {
$("#tipMsg").text(req.responseJSON.message);
$("#tipModal").modal('show');
}
function apiResult(json) {
if (json.code == 200 && json.message == 'success') {
return true;
}
$("#tipMsg").text("请求失败,错误信息:" + json.message);
$("#tipModal").modal('show');
return false;
}
});
}
},
};
</script>
<style scoped></style>