addService.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. (function(vc){
  2. vc.extends({
  3. propTypes: {
  4. callBackListener:vc.propTypes.string, //父组件名称
  5. callBackFunction:vc.propTypes.string //父组件监听方法
  6. },
  7. data:{
  8. addServiceInfo:{
  9. serviceId:'',
  10. name:'',
  11. serviceCode:'',
  12. businessTypeCd:'API',
  13. seq:'1',
  14. messageQueueName:'',
  15. isInstance:'Y',
  16. url:'http://order-service/orderApi/service',
  17. method:'',
  18. timeout:'60',
  19. retryCount:'3',
  20. provideAppId:'8000418002',
  21. }
  22. },
  23. _initMethod:function(){
  24. },
  25. _initEvent:function(){
  26. vc.on('addService','openAddServiceModal',function(){
  27. $('#addServiceModel').modal('show');
  28. });
  29. },
  30. methods:{
  31. addServiceValidate(){
  32. return vc.validate.validate({
  33. addServiceInfo:vc.component.addServiceInfo
  34. },{
  35. 'addServiceInfo.name':[
  36. {
  37. limit:"required",
  38. param:"",
  39. errInfo:"服务名称不能为空"
  40. },
  41. {
  42. limit:"maxLength",
  43. param:"50",
  44. errInfo:"服务名称不能超过50"
  45. },
  46. ],
  47. 'addServiceInfo.serviceCode':[
  48. {
  49. limit:"required",
  50. param:"",
  51. errInfo:"服务编码不能为空"
  52. },
  53. {
  54. limit:"maxin",
  55. param:"2,50",
  56. errInfo:"服务编码必须在2至50字符之间"
  57. },
  58. ],
  59. 'addServiceInfo.businessTypeCd':[
  60. {
  61. limit:"required",
  62. param:"",
  63. errInfo:"秘钥不能为空"
  64. },
  65. {
  66. limit:"maxin",
  67. param:"2,4",
  68. errInfo:"业务类型必须为API"
  69. },
  70. ],
  71. 'addServiceInfo.seq':[
  72. {
  73. limit:"required",
  74. param:"",
  75. errInfo:"序列不能为空"
  76. },
  77. {
  78. limit:"maxLength",
  79. param:"1",
  80. errInfo:"序列格式错误"
  81. },
  82. ],
  83. 'addServiceInfo.messageQueueName':[
  84. {
  85. limit:"maxLength",
  86. param:"50",
  87. errInfo:"消息队列不能超过50"
  88. },
  89. ],
  90. 'addServiceInfo.isInstance':[
  91. {
  92. limit:"required",
  93. param:"",
  94. errInfo:"是否实例不能为空"
  95. },
  96. {
  97. limit:"maxLength",
  98. param:"50",
  99. errInfo:"实例不能超过50"
  100. },
  101. ],
  102. 'addServiceInfo.url':[
  103. {
  104. limit:"maxLength",
  105. param:"200",
  106. errInfo:"调用地址不能超过200"
  107. },
  108. ],
  109. 'addServiceInfo.method':[
  110. {
  111. limit:"required",
  112. param:"",
  113. errInfo:"调用方式不能为空"
  114. },
  115. {
  116. limit:"maxLength",
  117. param:"50",
  118. errInfo:"调用方式不能超过50"
  119. },
  120. ],
  121. 'addServiceInfo.timeout':[
  122. {
  123. limit:"required",
  124. param:"",
  125. errInfo:"超时时间不能为空"
  126. },
  127. {
  128. limit:"num",
  129. param:"",
  130. errInfo:"超时时间必须为数字"
  131. },
  132. ],
  133. 'addServiceInfo.retryCount':[
  134. {
  135. limit:"required",
  136. param:"",
  137. errInfo:"重试次数不能为空"
  138. },
  139. {
  140. limit:"num",
  141. param:"",
  142. errInfo:"重试次数必须为数字"
  143. },
  144. ],
  145. 'addServiceInfo.provideAppId':[
  146. {
  147. limit:"required",
  148. param:"",
  149. errInfo:"提供服务不能为空"
  150. },
  151. {
  152. limit:"num",
  153. param:"",
  154. errInfo:"重试次数必须为数字"
  155. },
  156. ],
  157. });
  158. },
  159. saveServiceInfo:function(){
  160. if(!vc.component.addServiceValidate()){
  161. vc.toast(vc.validate.errInfo);
  162. return ;
  163. }
  164. //vc.component.addServiceInfo.communityId = vc.getCurrentCommunity().communityId;
  165. //不提交数据将数据 回调给侦听处理
  166. if(vc.notNull($props.callBackListener)){
  167. vc.emit($props.callBackListener,$props.callBackFunction,vc.component.addServiceInfo);
  168. $('#addServiceModel').modal('hide');
  169. return ;
  170. }
  171. vc.http.post(
  172. 'addService',
  173. 'save',
  174. JSON.stringify(vc.component.addServiceInfo),
  175. {
  176. emulateJSON:true
  177. },
  178. function(json,res){
  179. //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
  180. if(res.status == 200){
  181. //关闭model
  182. $('#addServiceModel').modal('hide');
  183. vc.component.clearAddServiceInfo();
  184. vc.emit('serviceManage','listService',{});
  185. return ;
  186. }
  187. vc.message(json);
  188. },
  189. function(errInfo,error){
  190. console.log('请求失败处理');
  191. vc.message(errInfo);
  192. });
  193. },
  194. clearAddServiceInfo:function(){
  195. vc.component.addServiceInfo = {
  196. name:'',
  197. serviceCode:'',
  198. businessTypeCd:'API',
  199. seq:'1',
  200. messageQueueName:'',
  201. isInstance:'Y',
  202. url:'http://order-service/orderApi/service',
  203. method:'',
  204. timeout:'60',
  205. retryCount:'3',
  206. provideAppId:'8000418002',
  207. };
  208. }
  209. }
  210. });
  211. })(window.vc);