user.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. define(['jquery', 'bootstrap', 'frontend', 'form', 'template'], function ($, undefined, Frontend, Form, Template) {
  2. var validatoroptions = {
  3. invalid: function (form, errors) {
  4. $.each(errors, function (i, j) {
  5. Layer.msg(j);
  6. });
  7. }
  8. };
  9. var Controller = {
  10. login: function () {
  11. //本地验证未通过时提示
  12. $("#login-form").data("validator-options", validatoroptions);
  13. //为表单绑定事件
  14. Form.api.bindevent($("#login-form"), function (data, ret) {
  15. setTimeout(function () {
  16. location.href = ret.url ? ret.url : "/";
  17. }, 1000);
  18. });
  19. //忘记密码
  20. $(document).on("click", ".btn-forgot", function () {
  21. var id = "resetpwdtpl";
  22. var content = Template(id, {});
  23. Layer.open({
  24. type: 1,
  25. title: __('Reset password'),
  26. area: [$(window).width() < 450 ? ($(window).width() - 10) + "px" : "450px", "355px"],
  27. content: content,
  28. success: function (layero) {
  29. var rule = $("#resetpwd-form input[name='captcha']").data("rule");
  30. Form.api.bindevent($("#resetpwd-form", layero), function (data) {
  31. Layer.closeAll();
  32. });
  33. $(layero).on("change", "input[name=type]", function () {
  34. var type = $(this).val();
  35. $("div.form-group[data-type]").addClass("hide");
  36. $("div.form-group[data-type='" + type + "']").removeClass("hide");
  37. $('#resetpwd-form').validator("setField", {
  38. captcha: rule.replace(/remote\((.*)\)/, "remote(" + $(this).data("check-url") + ", event=resetpwd, " + type + ":#" + type + ")")
  39. });
  40. $(".btn-captcha").data("url", $(this).data("send-url")).data("type", type);
  41. });
  42. }
  43. });
  44. });
  45. },
  46. register: function () {
  47. //本地验证未通过时提示
  48. $("#register-form").data("validator-options", validatoroptions);
  49. //为表单绑定事件
  50. Form.api.bindevent($("#register-form"), function (data, ret) {
  51. setTimeout(function () {
  52. location.href = ret.url ? ret.url : "/";
  53. }, 1000);
  54. }, function (data) {
  55. $("input[name=captcha]").next(".input-group-btn").find("img").trigger("click");
  56. });
  57. },
  58. changepwd: function () {
  59. //本地验证未通过时提示
  60. $("#changepwd-form").data("validator-options", validatoroptions);
  61. //为表单绑定事件
  62. Form.api.bindevent($("#changepwd-form"), function (data, ret) {
  63. setTimeout(function () {
  64. location.href = ret.url ? ret.url : "/";
  65. }, 1000);
  66. });
  67. },
  68. profile: function () {
  69. // 给上传按钮添加上传成功事件
  70. $("#faupload-avatar").data("upload-success", function (data) {
  71. var url = Fast.api.cdnurl(data.url);
  72. $(".profile-user-img").prop("src", url);
  73. Toastr.success(__('Uploaded successful'));
  74. });
  75. Form.api.bindevent($("#profile-form"));
  76. $(document).on("click", ".btn-change", function () {
  77. var that = this;
  78. var id = $(this).data("type") + "tpl";
  79. var content = Template(id, {});
  80. Layer.open({
  81. type: 1,
  82. title: "修改",
  83. area: [$(window).width() < 450 ? ($(window).width() - 10) + "px" : "450px", "355px"],
  84. content: content,
  85. success: function (layero) {
  86. var form = $("form", layero);
  87. Form.api.bindevent(form, function (data) {
  88. location.reload();
  89. Layer.closeAll();
  90. });
  91. }
  92. });
  93. });
  94. },
  95. attachment: function () {
  96. require(['table'], function (Table) {
  97. // 初始化表格参数配置
  98. Table.api.init({
  99. extend: {
  100. index_url: 'user/attachment',
  101. }
  102. });
  103. var urlArr = [];
  104. var multiple = Fast.api.query('multiple');
  105. multiple = multiple == 'true' ? true : false;
  106. var table = $("#table");
  107. table.on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table', function (e, row) {
  108. if (e.type == 'check' || e.type == 'uncheck') {
  109. row = [row];
  110. } else {
  111. urlArr = [];
  112. }
  113. $.each(row, function (i, j) {
  114. if (e.type.indexOf("uncheck") > -1) {
  115. var index = urlArr.indexOf(j.url);
  116. if (index > -1) {
  117. urlArr.splice(index, 1);
  118. }
  119. } else {
  120. urlArr.indexOf(j.url) == -1 && urlArr.push(j.url);
  121. }
  122. });
  123. });
  124. // 初始化表格
  125. table.bootstrapTable({
  126. url: $.fn.bootstrapTable.defaults.extend.index_url,
  127. sortName: 'id',
  128. showToggle: false,
  129. showExport: false,
  130. fixedColumns: true,
  131. fixedRightNumber: 1,
  132. columns: [
  133. [
  134. {field: 'state', checkbox: multiple, visible: multiple, operate: false},
  135. {field: 'id', title: __('Id'), operate: false},
  136. {
  137. field: 'url', title: __('Preview'), formatter: function (value, row, index) {
  138. var html = '';
  139. if (row.mimetype.indexOf("image") > -1) {
  140. html = '<a href="' + row.fullurl + '" target="_blank"><img src="' + row.fullurl + row.thumb_style + '" alt="" style="max-height:60px;max-width:120px"></a>';
  141. } else {
  142. html = '<a href="' + row.fullurl + '" target="_blank"><img src="' + Fast.api.fixurl("ajax/icon") + "?suffix=" + row.imagetype + '" alt="" style="max-height:90px;max-width:120px"></a>';
  143. }
  144. return '<div style="width:120px;margin:0 auto;text-align:center;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;">' + html + '</div>';
  145. }
  146. },
  147. {
  148. field: 'filename', title: __('Filename'), formatter: function (value, row, index) {
  149. return '<div style="width:150px;margin:0 auto;text-align:center;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;">' + Table.api.formatter.search.call(this, value, row, index) + '</div>';
  150. }, operate: 'like'
  151. },
  152. {field: 'imagewidth', title: __('Imagewidth'), operate: false},
  153. {field: 'imageheight', title: __('Imageheight'), operate: false},
  154. {field: 'mimetype', title: __('Mimetype'), formatter: Table.api.formatter.search},
  155. {field: 'createtime', title: __('Createtime'), width: 120, formatter: Table.api.formatter.datetime, datetimeFormat: 'YYYY-MM-DD', operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  156. {
  157. field: 'operate', title: __('Operate'), width: 85, events: {
  158. 'click .btn-chooseone': function (e, value, row, index) {
  159. Fast.api.close({url: row.url, multiple: multiple});
  160. },
  161. }, formatter: function () {
  162. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  163. }
  164. }
  165. ]
  166. ]
  167. });
  168. // 选中多个
  169. $(document).on("click", ".btn-choose-multi", function () {
  170. Fast.api.close({url: urlArr.join(","), multiple: multiple});
  171. });
  172. // 为表格绑定事件
  173. Table.api.bindevent(table);
  174. require(['upload'], function (Upload) {
  175. Upload.api.upload($("#toolbar .faupload"), function () {
  176. $(".btn-refresh").trigger("click");
  177. });
  178. });
  179. });
  180. }
  181. };
  182. return Controller;
  183. });