Context.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /**
  2. *
  3. * @param {*} modelData 当前绑定的数据模型
  4. * @param {*} actions 操作集合
  5. * @returns
  6. */
  7. export default function(modelData, actions){
  8. this.modelData = modelData;
  9. /**
  10. * 获取数据记录的Id
  11. */
  12. this.getRecordId = function(){
  13. return this.modelData.id;
  14. },
  15. /**
  16. * 获取字段(文本、数字类型)的值
  17. * @param {string} fieldName 字段名称
  18. */
  19. this.getFieldValue = function(fieldName){
  20. return this.modelData.data[fieldName];
  21. };
  22. /**
  23. * 设置字段(文本、数字类型)的值
  24. * @param {string} fieldName 字段名称
  25. * @param { com.leanwo.prodog.restful.base.model.FieldValue } fieldValue 字段值
  26. */
  27. this.setFieldValue = function(fieldName, fieldValue){
  28. this.modelData.data[fieldName] = fieldValue;
  29. };
  30. /**
  31. * 获取字段(搜索框、下拉框类型)的id
  32. * @param {string} fieldName 字段名称
  33. */
  34. this.getFieldValueId = function(fieldName){
  35. return this.modelData.data[fieldName].id;
  36. };
  37. /**
  38. * 设置字段(搜索框、下拉框类型)的id
  39. * @param {string} fieldName 字段名称
  40. * @param {long} id
  41. */
  42. this.setFieldValueId = function(filedName, id){
  43. this.modelData.data[filedName].id = id;
  44. };
  45. /**
  46. * 获取显示的值,返回数组
  47. * @param {string} fieldName 字段名称
  48. */
  49. this.getDispalyValue = function(fieldName){
  50. return this.modelData.data[fieldName].displayValue;
  51. };
  52. /**
  53. * 设置显示的值(数组)
  54. * @param {string} fieldName 字段名称
  55. * @param {*} displayValue 数组
  56. */
  57. this.setDispalyValue = function(fieldName, displayValue){
  58. this.modelData.data[fieldName].displayValue = displayValue;
  59. };
  60. /**
  61. * 获取显示的第一个值
  62. * @param {string} fieldName 字段名称
  63. */
  64. this.getDispalyValue0 = function(fieldName){
  65. return this.modelData.data[fieldName].displayValue[0];
  66. };
  67. /**
  68. * 设置显示的第一个值
  69. * @param {string} fieldName 字段名称
  70. * @param {string} displayValue0 显示的值
  71. */
  72. this.setDispalyValue0 = function(fieldName, displayValue0){
  73. this.modelData.data[fieldName].displayValue[0] = displayValue0;
  74. };
  75. /**
  76. * 设置自定义的属性
  77. * @param {string} propertyName 属性名称
  78. * @param {object} propertyValue 属性值
  79. */
  80. this.setCustomerProperty = function(propertyName, propertyValue){
  81. if(this.calloutProperty == null){
  82. this.calloutProperty = {};
  83. }
  84. this.calloutProperty[propertyName] = propertyValue;
  85. };
  86. /**
  87. * 获取自定义的属性
  88. * @param {string} propertyName 属性名称
  89. */
  90. this.getCustomerProperty = function(propertyName){
  91. if(this.calloutProperty == null){
  92. this.calloutProperty = {};
  93. }
  94. return this.calloutProperty[propertyName];
  95. };
  96. /**
  97. * 获取API的地址
  98. * @param {string} apiName
  99. * @returns
  100. */
  101. this.getApiURL = function(apiName){
  102. //获取当前网址,如: http://localhost:8083/myproj/view/my.jsp
  103. var curWwwPath = window.document.location.href;
  104. //获取主机地址之后的目录,如: myproj/view/my.jsp
  105. var pathName = window.document.location.pathname;
  106. var pos = curWwwPath.indexOf(pathName);
  107. //获取主机地址,如: http://localhost:8083
  108. var localhostPath = curWwwPath.substring(0, pos);
  109. return localhostPath + '/api/' + apiName;
  110. };
  111. /**
  112. * AJAX 请求头添加token
  113. * @param {object} request 请求
  114. */
  115. this.addTokenToRequest = function(request){
  116. request.setRequestHeader('token', localStorage.getItem('#token'));
  117. };
  118. /**
  119. * 获取子页签的数据
  120. * @param {int} tabIndex 子页签的序号
  121. */
  122. this.getSubTabModelDatas = function(tabIndex){
  123. if(actions === undefined || actions === null){
  124. console.error('操作集合 actions 为空,不能获取子页签的数据。');
  125. return;
  126. }
  127. const subTabsRef = actions.subTabsRef;
  128. if(subTabsRef === undefined || subTabsRef === null){
  129. console.error('操作集合 action.subTabsRef 为空,不能获取子页签的数据。');
  130. return;
  131. }
  132. return subTabsRef[tabIndex].modelDatas;
  133. };
  134. /**
  135. * 子页签增加数据
  136. * @param {int} tabIndex 子页签的序号
  137. * @param {com.leanwo.prodog.restful.base.model.ModelData} subTabNewModelData 子页签新增的数据
  138. */
  139. this.addSubTabModelData = function(tabIndex, subTabNewModelData){
  140. return this.subTabsRef[tabIndex].addModelData(subTabNewModelData);
  141. };
  142. /**
  143. * 修改父页签的数据
  144. * @param { String } fieldName 字段名称
  145. * @param { com.leanwo.prodog.restful.base.model.FieldValue } fieldValue 字段的值
  146. * @author YangZhiJie 20211012
  147. */
  148. this.changeParentModelData = function(fieldName, fieldValue){
  149. if(actions === undefined || actions === null){
  150. console.error('操作集合 actions 为空,不能修改父页签的数据。');
  151. return;
  152. }
  153. const changeParentModelData = actions.changeParentModelData;
  154. if(changeParentModelData === undefined || changeParentModelData === null){
  155. console.error('操作集合 action.changeParentModelData 为空,不能修改父页签的数据。');
  156. return;
  157. }
  158. changeParentModelData(fieldName, fieldValue);
  159. };
  160. /**
  161. * 获取本页签的表格数据
  162. */
  163. this.getModelDatas = function(){
  164. if(actions === undefined || actions === null){
  165. console.error('操作集合 actions 为空,不能获取本页签的表格数据。');
  166. return;
  167. }
  168. return actions.modelDatas;
  169. };
  170. return this;
  171. };