set.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. @Name:layuiAdmin(iframe版) 设置
  3. @Author:贤心
  4. @Site:http://www.layui.com/admin/
  5. @License: LPPL
  6. */
  7. layui.define(['form', 'upload'], function(exports){
  8. var $ = layui.$
  9. ,layer = layui.layer
  10. ,laytpl = layui.laytpl
  11. ,setter = layui.setter
  12. ,view = layui.view
  13. ,admin = layui.admin
  14. ,form = layui.form
  15. ,upload = layui.upload;
  16. var $body = $('body');
  17. //自定义验证
  18. form.verify({
  19. nickname: function(value, item){ //value:表单的值、item:表单的DOM对象
  20. if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
  21. return '用户名不能有特殊字符';
  22. }
  23. if(/(^\_)|(\__)|(\_+$)/.test(value)){
  24. return '用户名首尾不能出现下划线\'_\'';
  25. }
  26. if(/^\d+\d+\d$/.test(value)){
  27. return '用户名不能全为数字';
  28. }
  29. }
  30. //我们既支持上述函数式的方式,也支持下述数组的形式
  31. //数组的两个值分别代表:[正则匹配、匹配不符时的提示文字]
  32. ,pass: [
  33. /^[\S]{6,12}$/
  34. ,'密码必须6到12位,且不能出现空格'
  35. ]
  36. //确认密码
  37. ,repass: function(value){
  38. if(value !== $('#LAY_password').val()){
  39. return '两次密码输入不一致';
  40. }
  41. }
  42. });
  43. //网站设置
  44. form.on('submit(set_website)', function(obj){
  45. layer.msg(JSON.stringify(obj.field));
  46. //提交修改
  47. /*
  48. admin.req({
  49. url: ''
  50. ,data: obj.field
  51. ,success: function(){
  52. }
  53. });
  54. */
  55. return false;
  56. });
  57. //邮件服务
  58. form.on('submit(set_system_email)', function(obj){
  59. layer.msg(JSON.stringify(obj.field));
  60. //提交修改
  61. /*
  62. admin.req({
  63. url: ''
  64. ,data: obj.field
  65. ,success: function(){
  66. }
  67. });
  68. */
  69. return false;
  70. });
  71. //设置我的资料
  72. form.on('submit(setmyinfo)', function(obj){
  73. layer.msg(JSON.stringify(obj.field));
  74. //提交修改
  75. /*
  76. admin.req({
  77. url: ''
  78. ,data: obj.field
  79. ,success: function(){
  80. }
  81. });
  82. */
  83. return false;
  84. });
  85. //上传头像
  86. var avatarSrc = $('#LAY_avatarSrc');
  87. upload.render({
  88. url: '/api/upload/'
  89. ,elem: '#LAY_avatarUpload'
  90. ,done: function(res){
  91. if(res.status == 0){
  92. avatarSrc.val(res.url);
  93. } else {
  94. layer.msg(res.msg, {icon: 5});
  95. }
  96. }
  97. });
  98. //查看头像
  99. admin.events.avartatPreview = function(othis){
  100. var src = avatarSrc.val();
  101. layer.photos({
  102. photos: {
  103. "title": "查看头像" //相册标题
  104. ,"data": [{
  105. "src": src //原图地址
  106. }]
  107. }
  108. ,shade: 0.01
  109. ,closeBtn: 1
  110. ,anim: 5
  111. });
  112. };
  113. //设置密码
  114. form.on('submit(setmypass)', function(obj){
  115. layer.msg(JSON.stringify(obj.field));
  116. //提交修改
  117. /*
  118. admin.req({
  119. url: ''
  120. ,data: obj.field
  121. ,success: function(){
  122. }
  123. });
  124. */
  125. return false;
  126. });
  127. //对外暴露的接口
  128. exports('set', {});
  129. });