TaoLer/public/static/admin/modules/addons.js

273 lines
9.1 KiB
JavaScript
Raw Normal View History

2020-10-19 17:23:55 +08:00
//网站app版本发布
2022-11-25 22:44:04 +08:00
layui.define(["table", "form", "upload","notify","hxNav"], function (exports) {
2021-12-15 15:46:04 +08:00
var $ = layui.jquery,
table = layui.table,
form = layui.form,
upload = layui.upload;
2022-11-25 22:44:04 +08:00
var notify = layui.notify;
2020-10-19 17:23:55 +08:00
2022-11-27 23:13:06 +08:00
function getAddonsList(type,selector ) {
2021-12-15 15:46:04 +08:00
$.ajax({
type: "post",
url: addonsList,
2022-11-27 23:13:06 +08:00
data: { type: type, selector: selector },
2021-12-15 15:46:04 +08:00
dataType: "json",
success: function (res) {
//渲染表格
table.render({
elem: "#addons-list",
toolbar: "#toolbar",
defaultToolbar: [],
2022-11-27 23:13:06 +08:00
url: addonsList + "?type=" + type + "&selector=" + selector,
2021-12-15 15:46:04 +08:00
cols: [res["col"]],
page: true,
limit: 10,
height: "full-220",
text: "对不起,加载出现异常!",
});
},
});
}
2022-11-27 23:13:06 +08:00
getAddonsList("onlineAddons","all");
var api = {
userinfo: {
get: function () {
var userinfo = localStorage.getItem("taoleradmin_userinfo");
return userinfo ? JSON.parse(userinfo) : null;
},
set: function (data) {
if (data) {
localStorage.setItem("taoleradmin_userinfo", JSON.stringify(data));
} else {
localStorage.removeItem("taoleradmin_userinfo");
}
}
}
}
2021-10-12 16:46:49 +08:00
2021-12-15 15:46:04 +08:00
//头工具栏事件
table.on("toolbar(addons-list)", function (obj) {
var checkStatus = table.checkStatus(obj.config.id);
switch (obj.event) {
case "installed":
2022-11-27 23:13:06 +08:00
getAddonsList("installed",'');
break;
case "allAddons":
getAddonsList("onlineAddons","all");
2021-12-15 15:46:04 +08:00
break;
2022-11-27 23:13:06 +08:00
case "freeAddons":
getAddonsList("onlineAddons","free");
break;
case "payAddons":
getAddonsList("onlineAddons","pay");
2021-12-15 15:46:04 +08:00
break;
}
});
//监听工具条
table.on("tool(addons-list)", function (obj) {
2020-10-19 17:23:55 +08:00
var data = obj.data;
2022-11-25 22:44:04 +08:00
var event = obj.event;
var url = $(this).data('url')
2022-12-25 17:13:13 +08:00
// 安装
var install = function (data,url,userLoginUrl,userIsPayUrl){
var userinfo = api.userinfo.get(); // 检测权限
2022-11-27 23:13:06 +08:00
if(userinfo) {
notify.confirm("确认安装吗?", "vcenter",function(){
var index = layer.load(1);
$.post(url, { name: data.name, version: data.version, uid: userinfo.uid, token: userinfo.token }, function (res) {
2022-12-25 17:13:13 +08:00
// 需要支付
if (res.code === -2) {
layer.close(index);
layer.open({
type: 2,
area: ['700px', '650px'],
fixed: false, //不固定
maxmin: true,
content: 'pay.html'+ "?id=" + data.id+ "&name=" + data.name + "&version=" + data.version + "&uid=" + userinfo.uid + "&price=" + data.price,
success: function (layero, index){
// 订单沦陷
var intervalPay = setInterval(function() {
$.post(userIsPayUrl,{name:data.name, userinfo:userinfo},function (res){
if(res.code === 0) {
layer.close(index);
clearInterval(intervalPay);
install(data,url,userLoginUrl,userIsPayUrl);
}
});
},3000);
}
});
}
// 安装成功
if (res.code === 0) {
layer.close(index);
2022-11-27 23:13:06 +08:00
notify.success(res.msg, "topRight");
2022-12-25 17:13:13 +08:00
}
// 安装失败
if (res.code === -1) {
layer.close(index);
2022-11-27 23:13:06 +08:00
notify.error(res.msg, "topRight");
}
});
});
} else {
2022-12-25 17:13:13 +08:00
// 未登录时
2022-11-27 23:13:06 +08:00
layer.confirm('你当前还未登录TaoLer社区账号,请登录后操作!', {
title : '温馨提示',
btnAlign: 'c',
btn: ['立即登录'] //按钮
},function (index){
2022-11-25 22:44:04 +08:00
layer.close(index);
2022-11-27 23:13:06 +08:00
// 登录窗口
layer.open({
type: 1,
shadeClose: true,
title: '登录账号',
content: $("#user-info").html(),
area: ['400px','300px'],
btn: ['登录','注册'],
yes:function (index, layero) {
var url = userLoginUrl;
var data = {
name: $("#username", layero).val(),
password: $("#password", layero).val(),
};
if (!data.name || !data.password) {
notify.error('Account Or Password Cannot Empty');
return false;
}
$.ajax({
url: url, type: 'post', data: data, dataType: "json", success: function (res) {
if (res.code === 0) {
layer.close(index);
api.userinfo.set(res.data);
notify.success("登录成功", function (){
location.reload();
});
} else {
notify.alert(res.msg);
}
}, error: function (res) {
notify.error(res.msg);
}
})
},
btn2: function () {
return false;
},
success: function (layero, index) {
$(".layui-layer-btn1", layero).prop("href", "https://www.aieok.com/article/reg.html").prop("target", "_blank");
},
end: function () {
$("#login").hide();
},
});
});
}
2022-11-25 22:44:04 +08:00
}
2022-12-25 17:13:13 +08:00
//安装插件
if (event === "install") {
var userLoginUrl = $(this).data('userlogin');
var userIsPayUrl = $(this).data('ispay');
install(data,url,userLoginUrl,userIsPayUrl);
2022-11-25 22:44:04 +08:00
}
// 卸载插件
if (event === "uninstall") {
notify.confirm("确认框", "vcenter",function() {
var index = layer.load(1);
$.post(url, { name: data.name }, function (res) {
2022-12-25 17:13:13 +08:00
if (res.code === 0) {
2022-11-25 22:44:04 +08:00
notify.success(res.msg, "topRight");
2021-12-15 15:46:04 +08:00
} else {
2022-11-25 22:44:04 +08:00
notify.error(res.msg, "topRight");
2021-12-15 15:46:04 +08:00
}
2022-11-25 22:44:04 +08:00
});
table.reload("addons-list");
layer.close(index);
2021-12-15 15:46:04 +08:00
});
2022-11-25 22:44:04 +08:00
}
2022-09-23 11:03:10 +08:00
2022-11-25 22:44:04 +08:00
// 配置插件
if (event === "config") {
2022-11-27 23:13:06 +08:00
$.post(url,{name:data.name},function (res){
// 无配置项拦截
2022-12-25 17:13:13 +08:00
if (res.code === -1) {
2022-11-27 23:13:06 +08:00
notify.alert(res.msg);
return false;
}
layer.open({
type: 2,
title: '配置插件',
content: url + "?name=" + data.name,
maxmin: true,
area: ["780px", "90%"],
btn: ["确定", "取消"],
yes: function (index, layero) {
2022-12-25 17:13:13 +08:00
var iframeWindow = window["layui-layer-iframe" + index], submitID = "LAY-addons-config-submit", submit = layero.find("iframe").contents().find("#" + submitID);
2022-11-27 23:13:06 +08:00
//监听提交
iframeWindow.layui.form.on("submit(" + submitID + ")",
function (data) {
var field = data.field; //获取提交的字段
$.ajax({
type: "post",
url: url,
data: field,
daType: "json",
success: function (res) {
2022-12-25 17:13:13 +08:00
if (res.code === 0) {
2022-11-27 23:13:06 +08:00
notify.success(res.msg, "topRight");
} else {
notify.error(res.msg, "topRight");
}
},
});
layer.close(index); //关闭弹层
}
);
submit.trigger("click");
},
success: function (layero, index) {
var forms = layero.find("iframe").contents().find(".layui-form");
var button = forms.find("button");
//事件委托
forms.on("click", "button", function (data) {
var even = this.getAttribute("lay-event");
var names = this.dataset.name;
// if (even == "addInput") {
// var html = '<div class="layui-form-item">\n' +
// '<label class="layui-form-label"></label>\n' +
// '<div class="layui-input-inline">\n' +
// ' <input type="text" name="'+ names +'[key][]" value="" placeholder="key" autocomplete="off" class="layui-input input-double-width">\n' +
// '</div>\n' +
// '<div class="layui-input-inline">\n' +
// ' <input type="text" name="'+ names +'[value][]" value="" placeholder="value" autocomplete="off" class="layui-input input-double-width">\n' +
// '</div>\n' +
// '<button data-name="'+ names +'" type="button" class="layui-btn layui-btn-danger layui-btn-sm removeInupt" lay-event="removeInupt">\n' +
// ' <i class="layui-icon"></i>\n' +
// '</button>\n' +
// '</div>';
// $(this).parent().parent().append(html);
// } else {
// $(this).parent().remove();
// }
});
},
});
2022-11-25 22:44:04 +08:00
});
2022-11-27 23:13:06 +08:00
2022-11-25 22:44:04 +08:00
}
2020-10-19 17:23:55 +08:00
});
2021-12-15 15:46:04 +08:00
exports("addons", {});
});