FormUtil.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. Ext.define('saas.util.FormUtil', {
  2. BaseUtil: Ext.create('saas.util.BaseUtil'),
  3. // 请求页面组件接口模板
  4. baseUrl: 'http://192.168.0.181:8560/api/ui/co_view/config?name={xtype}',
  5. // 模板替换正则
  6. urlRe: /(.*){xtype}(.*)/g,
  7. /**
  8. * 获得form的字段配置
  9. * @param form: form组件
  10. * @param url: url
  11. */
  12. setItems: function(form) {
  13. var me = this,
  14. xtype = form.xtype,
  15. url = me.baseUrl.replace(me.urlRe, '$1' + xtype);
  16. this.BaseUtil.request({url, })
  17. .then(function(response) {
  18. var res = Ext.decode(response.responseText);
  19. if(res.success) {
  20. var config = res.data, items = [];
  21. if(config) {
  22. items = config.items,
  23. bindFields = items.filter(function(item) {
  24. return !!item.bind;
  25. }).map(function(item) {
  26. return item.bind.replace(/[{ | }]/g, '');
  27. }),
  28. viewModel = form.getViewModel();
  29. form.bindFields = bindFields;
  30. form.add(items);
  31. }
  32. form.fireEvent('afterSetItems', form, items);
  33. }
  34. })
  35. .catch(function(response) {
  36. console.error(response);
  37. });
  38. },
  39. loadData: function(form) {
  40. }
  41. });