addApp.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. (function(vc){
  2. vc.extends({
  3. propTypes: {
  4. callBackListener:vc.propTypes.string, //父组件名称
  5. callBackFunction:vc.propTypes.string //父组件监听方法
  6. },
  7. data:{
  8. addAppInfo:{
  9. appId:'',
  10. name:'',
  11. securityCode:'',
  12. whileListIp:'',
  13. blackListIp:'',
  14. remark:'',
  15. }
  16. },
  17. _initMethod:function(){
  18. },
  19. _initEvent:function(){
  20. vc.on('addApp','openAddAppModal',function(){
  21. $('#addAppModel').modal('show');
  22. });
  23. },
  24. methods:{
  25. addAppValidate(){
  26. return vc.validate.validate({
  27. addAppInfo:vc.component.addAppInfo
  28. },{
  29. 'addAppInfo.name':[
  30. {
  31. limit:"required",
  32. param:"",
  33. errInfo:"应用名称不能为空"
  34. },
  35. {
  36. limit:"maxin",
  37. param:"2,50",
  38. errInfo:"应用名称必须在2至50字符之间"
  39. },
  40. ],
  41. 'addAppInfo.securityCode':[
  42. {
  43. limit:"maxLength",
  44. param:"64",
  45. errInfo:"秘钥太长超过64位"
  46. },
  47. ],
  48. 'addAppInfo.whileListIp':[
  49. {
  50. limit:"maxLength",
  51. param:"200",
  52. errInfo:"白名单内容不能超过200"
  53. },
  54. ],
  55. 'addAppInfo.blackListIp':[
  56. {
  57. limit:"maxLength",
  58. param:"200",
  59. errInfo:"黑名单内容不能超过200"
  60. },
  61. ],
  62. 'addAppInfo.remark':[
  63. {
  64. limit:"maxLength",
  65. param:"200",
  66. errInfo:"备注内容不能超过200"
  67. },
  68. ],
  69. });
  70. },
  71. saveAppInfo:function(){
  72. if(!vc.component.addAppValidate()){
  73. vc.message(vc.validate.errInfo);
  74. return ;
  75. }
  76. vc.component.addAppInfo.communityId = vc.getCurrentCommunity().communityId;
  77. //不提交数据将数据 回调给侦听处理
  78. if(vc.notNull($props.callBackListener)){
  79. vc.emit($props.callBackListener,$props.callBackFunction,vc.component.addAppInfo);
  80. $('#addAppModel').modal('hide');
  81. return ;
  82. }
  83. vc.http.post(
  84. 'addApp',
  85. 'save',
  86. JSON.stringify(vc.component.addAppInfo),
  87. {
  88. emulateJSON:true
  89. },
  90. function(json,res){
  91. //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
  92. if(res.status == 200){
  93. //关闭model
  94. $('#addAppModel').modal('hide');
  95. vc.component.clearAddAppInfo();
  96. vc.emit('appManage','listApp',{});
  97. return ;
  98. }
  99. vc.message(json);
  100. },
  101. function(errInfo,error){
  102. console.log('请求失败处理');
  103. vc.message(errInfo);
  104. });
  105. },
  106. clearAddAppInfo:function(){
  107. vc.component.addAppInfo = {
  108. name:'',
  109. securityCode:'',
  110. whileListIp:'',
  111. blackListIp:'',
  112. remark:'',
  113. };
  114. }
  115. }
  116. });
  117. })(window.vc);