define(['jquery', 'frontend', 'form'], function($, Frontend, Form) {
var Controller = {
login: function() {
//为表单绑定事件
Form.api.bindevent($("form.layui-form"), function(data, ret) {
setTimeout(function() {
location.href = ret.url ? ret.url : "/";
}, 1000);
}, function(res) {
//刷新验证码
$("#verify").click();
//layer.msg(res.msg, { icon: 5 });
});
//刷新验证码
$("#verify").click(function() {
var verifyimg = $("#verify").attr("src");
$("#verify").attr("src", verifyimg.replace(/\?.*$/, '') + '?' + Math.random());
});
},
register: function() {
//为表单绑定事件
Form.api.bindevent($("form.layui-form"), function(data, ret) {
setTimeout(function() {
location.href = ret.url ? ret.url : "/";
}, 1000);
}, function(res) {
//刷新验证码
$("#verify").click();
//layer.msg(res.msg, { icon: 5 });
});
//刷新验证码
$("#verify").click(function() {
var verifyimg = $("#verify").attr("src");
$("#verify").attr("src", verifyimg.replace(/\?.*$/, '') + '?' + Math.random());
});
},
forget: function() {
Form.api.bindevent($("form.layui-form"), function(data, ret) {
Layer.msg(res.msg, {
offset: '15px',
icon: 1,
time: 1000
}, function() {
window.location.href = res.url;
});
return false;
});
layui.form.on('radio(type)', function(data) {
var type = data.value;
if (type == 'email') {
$("input[name='mobile']").attr('lay-verify', '');
$("input[name='email']").attr('lay-verify', 'email|required');
}
if (type == 'mobile') {
$("input[name='email']").attr('lay-verify', '');
$("input[name='mobile']").attr('lay-verify', 'phone|required');
}
$("div.layui-form-item[data-type]").addClass("layui-hide");
$("div.layui-form-item[data-type='" + type + "']").removeClass("layui-hide");
$(".btn-captcha").data("url", $(this).data("send-url")).data("type", type);
});
},
index: function() {
},
changepwd: function() {
//为表单绑定事件
Form.api.bindevent($("#changepwd-form"), function(data, ret) {
setTimeout(function() {
location.href = ret.url ? ret.url : "/";
}, 1000);
});
},
profile: function() {
// 给上传按钮添加上传成功事件
$("#faupload-avatar").data("upload-success", function(data) {
var url = Yzn.api.cdnurl(data.url);
$(".profile-user-img,.fly-avatar").prop("src", url);
Toastr.success('上传成功');
});
Form.api.bindevent($("#profile-form"));
$(document).on("click", ".btn-change", function() {
var that = this;
var id = $(this).data("type") + "Tpl";
var content = layui.laytpl($("#" + id).html()).render()
Layer.open({
type: 1,
title: $(this).data("title"),
area: [$(window).width() < 450 ? ($(window).width() - 10) + "px" : "450px", "320px"],
content: content,
success: function(layero) {
var form = $("form", layero);
Form.api.bindevent(form, function(data) {
location.reload();
Layer.closeAll();
});
}
});
});
},
attachment: function() {
require(['table'], function(Table) {
var multiple = Yzn.api.query('multiple');
multiple = multiple == 'true' ? true : false;
var toolbar = ['refresh', {
html: ''
}];
if (multiple) {
toolbar.push({
html: ''
});
}
Table.init = {
table_elem: '#currentTable',
table_render_id: 'currentTable',
};
Table.render({
init: Table.init,
toolbar: toolbar,
renderDefault: true,
elem: '#currentTable',
url: 'user/attachment',
lineStyle: 'height: 60px;',
cols: [
[
{ type: 'checkbox', fixed: 'left', hide: (multiple ? false : true) },
{ field: 'id', width: 60, title: 'ID', sort: true, search: false },
{ field: 'name', title: '文件名' },
{
field: 'path',
width: 100,
align: "center",
title: '图片',
search: false,
templet: function(d) {
var html = '';
if (d.mime.indexOf("image") > -1) {
html = '';
} else {
html = '
';
}
return '