user.js 8.5 KB

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