user.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. define(['jquery', 'frontend', 'form'], function($, Frontend, Form) {
  2. var Controller = {
  3. login: function() {
  4. //为表单绑定事件
  5. Form.api.bindevent($("form.layui-form"), function(data, ret) {
  6. setTimeout(function() {
  7. location.href = ret.url ? ret.url : "/";
  8. }, 1000);
  9. }, function(res) {
  10. //刷新验证码
  11. $("#verify").click();
  12. //layer.msg(res.msg, { icon: 5 });
  13. });
  14. //刷新验证码
  15. $("#verify").click(function() {
  16. var verifyimg = $("#verify").attr("src");
  17. $("#verify").attr("src", verifyimg.replace(/\?.*$/, '') + '?' + Math.random());
  18. });
  19. },
  20. register: function() {
  21. //为表单绑定事件
  22. Form.api.bindevent($("form.layui-form"), function(data, ret) {
  23. setTimeout(function() {
  24. location.href = ret.url ? ret.url : "/";
  25. }, 1000);
  26. }, function(res) {
  27. //刷新验证码
  28. $("#verify").click();
  29. //layer.msg(res.msg, { icon: 5 });
  30. });
  31. //刷新验证码
  32. $("#verify").click(function() {
  33. var verifyimg = $("#verify").attr("src");
  34. $("#verify").attr("src", verifyimg.replace(/\?.*$/, '') + '?' + Math.random());
  35. });
  36. },
  37. forget: function() {
  38. Form.api.bindevent($("form.layui-form"), function(data, ret) {
  39. Layer.msg(res.msg, {
  40. offset: '15px',
  41. icon: 1,
  42. time: 1000
  43. }, function() {
  44. window.location.href = res.url;
  45. });
  46. return false;
  47. });
  48. layui.form.on('radio(type)', function(data) {
  49. var type = data.value;
  50. if (type == 'email') {
  51. $("input[name='mobile']").attr('lay-verify', '');
  52. $("input[name='email']").attr('lay-verify', 'email|required');
  53. }
  54. if (type == 'mobile') {
  55. $("input[name='email']").attr('lay-verify', '');
  56. $("input[name='mobile']").attr('lay-verify', 'phone|required');
  57. }
  58. $("div.layui-form-item[data-type]").addClass("layui-hide");
  59. $("div.layui-form-item[data-type='" + type + "']").removeClass("layui-hide");
  60. $(".btn-captcha").data("url", $(this).data("send-url")).data("type", type);
  61. });
  62. },
  63. index: function() {
  64. },
  65. changepwd: function() {
  66. //为表单绑定事件
  67. Form.api.bindevent($("#changepwd-form"), function(data, ret) {
  68. setTimeout(function() {
  69. location.href = ret.url ? ret.url : "/";
  70. }, 1000);
  71. });
  72. },
  73. profile: function() {
  74. // 给上传按钮添加上传成功事件
  75. $("#faupload-avatar").data("upload-success", function(data) {
  76. var url = Yzn.api.cdnurl(data.url);
  77. $(".profile-user-img,.fly-avatar").prop("src", url);
  78. Toastr.success('上传成功');
  79. });
  80. Form.api.bindevent($("#profile-form"));
  81. $(document).on("click", ".btn-change", function() {
  82. var that = this;
  83. var id = $(this).data("type") + "Tpl";
  84. var content = layui.laytpl($("#" + id).html()).render()
  85. Layer.open({
  86. type: 1,
  87. title: $(this).data("title"),
  88. area: [$(window).width() < 450 ? ($(window).width() - 10) + "px" : "450px", "320px"],
  89. content: content,
  90. success: function(layero) {
  91. var form = $("form", layero);
  92. Form.api.bindevent(form, function(data) {
  93. location.reload();
  94. Layer.closeAll();
  95. });
  96. }
  97. });
  98. });
  99. },
  100. attachment: function() {
  101. require(['table'], function(Table) {
  102. var multiple = Yzn.api.query('multiple');
  103. multiple = multiple == 'true' ? true : false;
  104. var toolbar = ['refresh', {
  105. html: '<button type="button" class="layui-btn layui-btn-sm faupload" data-multiple="true" data-mimetype="' + Config.mimetype + '"><i class="iconfont icon-upload-line"></i> 上传</button>'
  106. }];
  107. if (multiple) {
  108. toolbar.push({
  109. html: '<button class="layui-btn layui-btn-danger layui-btn-sm btn-choose-multi"><i class="iconfont icon-check-line"></i> 选择</button>'
  110. });
  111. }
  112. Table.init = {
  113. table_elem: '#currentTable',
  114. table_render_id: 'currentTable',
  115. };
  116. Table.render({
  117. init: Table.init,
  118. toolbar: toolbar,
  119. renderDefault: true,
  120. elem: '#currentTable',
  121. url: 'user/attachment',
  122. lineStyle: 'height: 60px;',
  123. cols: [
  124. [
  125. { type: 'checkbox', fixed: 'left', hide: (multiple ? false : true) },
  126. { field: 'id', width: 60, title: 'ID', sort: true, search: false },
  127. { field: 'name', title: '文件名' },
  128. {
  129. field: 'path',
  130. width: 100,
  131. align: "center",
  132. title: '图片',
  133. search: false,
  134. templet: function(d) {
  135. var html = '';
  136. if (d.mime.indexOf("image") > -1) {
  137. html = '<a href="' + d.path + '" target="_blank"><img src="' + d.path + '" alt="" style="max-height:40px;max-width:70px"></a>';
  138. } else {
  139. html = '<a href="' + d.path + '" target="_blank"><img src="' + Yzn.api.fixurl("ajax/icon") + "?suffix=" + d.ext + '" alt="" style="max-height:40px;max-width:70px"></a>';
  140. }
  141. return '<div style="width:70px;margin:0 auto;text-align:center;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;">' + html + '</div>';
  142. }
  143. },
  144. { field: 'size', width: 100, title: '大小', sort: true, search: false },
  145. { field: 'mime', width: 100, title: 'Mime类型' },
  146. { field: 'create_time', width: 160, title: '上传时间', search: 'range' },
  147. { fixed: 'right', width: 70, title: '操作', toolbar: '#barTool' }
  148. ]
  149. ],
  150. page: {},
  151. done: function(res, curr, count) {
  152. require(['upload'], function(Upload) {
  153. Upload.api.upload('.faupload', function() {
  154. $(".btn-refresh").trigger("click");
  155. });
  156. });
  157. }
  158. });
  159. Table.api.bindevent();
  160. layui.table.on('checkbox', function(obj) {
  161. urlArr = [];
  162. var checkStatus = layui.table.checkStatus('currentTable').data;
  163. for (var i = 0; i < checkStatus.length; i++) {
  164. urlArr.push(checkStatus[i]['path']);
  165. }
  166. });
  167. //选择单个
  168. $(document).on('click', '.btn-chooseone', function() {
  169. var that = $(this),
  170. index = that.parents('tr').eq(0).data('index'),
  171. tr = $('.layui-table-body').find('tr[data-index="' + index + '"]'),
  172. href = !that.attr('data-href') ? that.attr('href') : that.attr('data-href');
  173. Yzn.api.close({ url: href, multiple: multiple });
  174. });
  175. // 选中多个 todo翻页失效
  176. $(document).on("click", ".btn-choose-multi", function() {
  177. Yzn.api.close({ url: urlArr.join(","), multiple: multiple });
  178. });
  179. })
  180. }
  181. };
  182. return Controller;
  183. });