GridHeader.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <tr class="sticky-row">
  3. <th
  4. v-if="$i18n.locale === 'zh-CN'"
  5. class="text-center sticky-col"
  6. width="50px"
  7. >
  8. <div>{{ $t('lang.gridHeader.serialNumber') }}</div>
  9. </th>
  10. <th
  11. v-else
  12. class="text-center sticky-col"
  13. width="100px"
  14. >
  15. <div>{{ $t('lang.gridHeader.serialNumber') }}</div>
  16. </th>
  17. <th
  18. class="text-center sticky-col"
  19. width="30px"
  20. :class="{'mulitiple-select': multipleSelect}"
  21. style="left:50px" @click.self="changeSelectMode"
  22. >
  23. <input
  24. v-model="isSelectAll"
  25. autocomplete="off"
  26. type="checkbox"
  27. class="select-checkbox"
  28. />
  29. </th>
  30. <th
  31. v-if="isShowEdit == undefined || isShowEdit"
  32. class="text-center sticky-col"
  33. width="95px"
  34. style="left:80px"
  35. >
  36. <div>
  37. {{ $t('lang.gridHeader.operate') }}
  38. </div>
  39. </th>
  40. <template v-if="tabGridFields != null && tabGridFields.length > 0">
  41. <template v-for="tabGridField in tabGridFields">
  42. <th
  43. v-show="tabGridField.visible"
  44. v-if="tabGridField.groupNames == null || tabGridField.groupNames.length == 0 || (nowTab != null && (tabGridField.groupNames.indexOf(nowTab) >= 0))"
  45. :id="tabGridField.fieldId" :key="'th_' + getTabGridFieldId(tabGridField)"
  46. v-tooltip="tabGridField.help"
  47. class="text-center"
  48. :width="tabGridField.width + 'px'"
  49. style="position: relative;"
  50. @dragover="ondragover($event, tabGridField)"
  51. @click="onSort(tabGridField)"
  52. >
  53. <div
  54. :id="getTabGridFieldId(tabGridField)"
  55. class="rz-handle"
  56. draggable="true"
  57. @dragstart="ondragstart($event, tabGridField)"
  58. @drag="ondrag($event, tabGridField)"
  59. @dragend="ondragend($event, tabGridField)"
  60. />
  61. <div class="td-max">
  62. <span
  63. v-if="tabGridField.mandatory"
  64. class="require-mark"
  65. >*</span>
  66. <span size="2">{{ Language.getDisplayNameTrl($i18n.locale, tabGridField) }}</span><br />
  67. <span v-if="isChineseEnglish && $i18n.locale == 'zh-CN'" size="0.5">{{ tabGridField.displayNameEng }}</span>
  68. </div>
  69. </th>
  70. </template>
  71. </template>
  72. </tr>
  73. </template>
  74. <script>
  75. import WindowClientUtil from '../../resource/dictionary/WindowClientUtil.js';
  76. import GridColumnDef from './GridColumnDef.js';
  77. import Language from '../../common/Language.js';
  78. import Context from '../common/Context.js';
  79. import JsUtil from '../../common/JsUtil.js';
  80. import { Notify, Uuid } from 'pc-component-v3';
  81. export default {
  82. props: {
  83. windowNo: {
  84. type: String,
  85. default: null,
  86. },
  87. tabIndex: {
  88. type: Number,
  89. default: null,
  90. },
  91. tabGridFields: {
  92. type: Array,
  93. default : function(){
  94. return null;
  95. },
  96. },
  97. parentModelData: {
  98. type: Object,
  99. default : function(){
  100. return null;
  101. },
  102. },
  103. isShowEdit: {
  104. type: Boolean,
  105. default : false,
  106. },
  107. isChineseEnglish: {
  108. type: Boolean,
  109. default: null,
  110. },
  111. // 当前的页签
  112. nowTab: {
  113. type: String,
  114. default: '',
  115. },
  116. // 是否勾选了全选
  117. isSelectAllInput: {
  118. type: Boolean,
  119. default : false,
  120. },
  121. },
  122. emits: ['onSort', 'multipleSelect'],
  123. data: function () {
  124. this.Language = Language;
  125. return {
  126. startX: '',
  127. startWidth: '',
  128. isSelectAll: false,
  129. multipleSelect: true,
  130. };
  131. },
  132. watch: {
  133. 'isSelectAllInput': function (val) {
  134. var _self = this;
  135. _self.isSelectAll = val;
  136. },
  137. 'isSelectAll': function (val) {
  138. var _self = this;
  139. if (_self.multipleSelect) {
  140. _self.$emit('selectAll', _self.isSelectAll);
  141. } else {
  142. _self.isSelectAll = false;
  143. }
  144. },
  145. 'parentModelData.data': {
  146. deep: true,
  147. handler(curVal, oldVal) {
  148. var _self = this;
  149. for(let index = 0; index < _self.tabGridFields.length; index ++){
  150. const tabGridField = _self.tabGridFields[index];
  151. const columnShowLogical = tabGridField.columnShowLogical;
  152. if(columnShowLogical != null && columnShowLogical.length > 0){
  153. let functionName = tabGridField.fieldName.replace('.', '_') + '_showLogical';
  154. let executeFunction = function(){
  155. let parentCtx = new _self.getContext(_self.parentModelData);
  156. try{
  157. tabGridField.visible = _self[functionName](null, parentCtx.modelData);
  158. }catch(e){
  159. console.error('js代码 %s 执行异常 %o', columnShowLogical, e);
  160. tabGridField.visible = true;
  161. }
  162. };
  163. if(_self[functionName] == null){
  164. // 执行服务端的脚本
  165. const jsUrl = _self.jsUrl;
  166. if(jsUrl == null || jsUrl == undefined){
  167. Notify.error('数据字典定义异常', '【' + tabGridField.fieldName + '】列显示逻辑的JS文件不存在,请联系管理员检查数据字典是否JS文件。', false);
  168. return;
  169. }
  170. let promise = JsUtil.dynamicLoadJsFunction(jsUrl, columnShowLogical);
  171. promise.then(dynamicFunction => {
  172. let targetFunction = dynamicFunction;
  173. if(targetFunction == null){
  174. Notify.error('数据字典定义异常', '【' + tabGridField.fieldName + '】列显示逻辑定义异常,请联系管理员检查数据字典的定义。', false);
  175. return;
  176. }
  177. _self[functionName] = targetFunction;
  178. executeFunction();
  179. }, errorData => {
  180. console.error(errorData);
  181. });
  182. }else{
  183. executeFunction();
  184. }
  185. }
  186. }
  187. },
  188. },
  189. },
  190. methods: {
  191. /**
  192. * 获取Context
  193. */
  194. getContext : Context,
  195. /**
  196. * 获取表格列的Id
  197. */
  198. getTabGridFieldId: function (tabGridField) {
  199. var tabGridFieldId = 'GridHeader' + this.windowNo + '_' + this.tabIndex + '_' + tabGridField.fieldName + '_' + tabGridField.entityFieldIndex;
  200. return tabGridFieldId;
  201. },
  202. ondragstart: function (event, tabGridField) {
  203. var _self = this;
  204. _self.startX = event.pageX;
  205. _self.startWidth = tabGridField.width;
  206. var tabGridFieldId = this.getTabGridFieldId(tabGridField);
  207. var element1 = document.getElementById(tabGridFieldId);
  208. $(element1).addClass('rz-handle-active');
  209. // event.dataTransfer.setDragImage(element1, 0, 30);
  210. event.dataTransfer.setDragImage(event.target, 0, 20);
  211. event.dataTransfer.effectAllowed = 'move';
  212. // event.dataTransfer.dropEffect = 'move';
  213. },
  214. ondrag: function (event, tabGridField) {
  215. var _self = this;
  216. if ((_self.startWidth + (event.pageX - _self.startX)) > 20) {
  217. tabGridField.width = _self.startWidth + (event.pageX - _self.startX);
  218. } else {
  219. tabGridField.width = 20;
  220. }
  221. },
  222. ondragend: function (event, tabGridField) {
  223. var _self = this;
  224. if ((_self.startWidth + (event.pageX - _self.startX)) > 20) {
  225. tabGridField.width = _self.startWidth + (event.pageX - _self.startX);
  226. } else {
  227. tabGridField.width = 20;
  228. }
  229. GridColumnDef.saveGridFieldDef(_self.windowNo, _self.tabIndex, _self.tabGridFields).then(successData => {
  230. _self.$emit('propertyChanged', _self.tabGridFields);
  231. var tabGridFieldId = _self.getTabGridFieldId(tabGridField);
  232. var element1 = document.getElementById(tabGridFieldId);
  233. $(element1).removeClass('rz-handle-active');
  234. }, errorData => {
  235. console.log(errorData);
  236. });
  237. },
  238. ondragover: function (event, tabGridField) {
  239. event.preventDefault();
  240. event.dataTransfer.dropEffect = 'move';
  241. },
  242. onSort: function (tabGridField) {
  243. this.$emit('onSort', tabGridField);
  244. },
  245. changeSelectMode: function () {
  246. this.multipleSelect = !this.multipleSelect;
  247. this.$emit('multipleSelect', this.multipleSelect);
  248. },
  249. },
  250. };
  251. </script>
  252. <style scoped>
  253. .require-mark {
  254. color: red;
  255. }
  256. .mulitiple-select {
  257. background-color: #6699cc;
  258. }
  259. .text-center {
  260. text-align: center;
  261. }
  262. th {
  263. background-color: #f7f7f7;
  264. }
  265. .td-max {
  266. max-width: 100%;
  267. }
  268. </style>
  269. <style scoped>
  270. table.curd-table th {
  271. /* position: relative; */
  272. min-width: 25px;
  273. }
  274. table th,
  275. table td {
  276. text-align: left;
  277. overflow: hidden;
  278. white-space: nowrap;
  279. text-overflow: ellipsis;
  280. /* padding: 0.75em; */
  281. border-right: 1px solid rgba(0, 0, 0, 0.05);
  282. }
  283. table th {
  284. min-width: 10px;
  285. background-color: #f8f8f8;
  286. }
  287. .rz-handle {
  288. width: 10px;
  289. height: 100%;
  290. position: absolute;
  291. top: 0;
  292. right: 0;
  293. cursor: ew-resize !important;
  294. z-index: 3;
  295. }
  296. .rz-handle.rz-handle-active {
  297. border-right: 2px solid #000;
  298. transform: scaleX(100);
  299. background: rgba(0, 0, 0, 0.05) 2px;
  300. }
  301. .rz-handle:hover {
  302. background: rgba(0, 0, 0, 0.2) 4px;
  303. }
  304. /* 固定列 */
  305. .sticky-col {
  306. position: -webkit-sticky; /* Safari */
  307. position: sticky;
  308. left: 0;
  309. background: #fafafa;
  310. z-index: 1; /* 确保固定列在其他内容之上 */
  311. }
  312. /* 固定行 */
  313. .sticky-row {
  314. position: -webkit-sticky; /* Safari */
  315. position: sticky;
  316. top: 0;
  317. background: #fafafa;
  318. z-index: 2; /* 确保固定列在其他内容之上 */
  319. }
  320. </style>