QueryPageTable.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <template>
  2. <div :id="tableOutDivId" class="flex-main table-fix-head">
  3. <table class="fixed-table table-striped table-bordered" :width="tableWidth" height="40px">
  4. <thead>
  5. <tr height="40px">
  6. <th width="50px">{{ $t("lang.QueryPage.serialNumber") }}</th>
  7. <th
  8. width="30px" class="text-center" :class="{ 'mulitiple-select': multipleSelect }"
  9. @click.self="changeSelectMode"
  10. >
  11. <input v-model="isSelectAll" autocomplete="off" type="checkbox" />
  12. </th>
  13. <template v-for="infoGridField in infoGridFieldsInstance.infoGridFields">
  14. <th
  15. v-if="infoGridField.simpleDisplayType != 'OperateButton'" v-show="infoGridField.isShow"
  16. :key="infoGridField.fieldName" :width="infoGridField.width + 'px'"
  17. @dragover="ondragover($event, infoGridField)" @click="onSort(infoGridField)"
  18. >
  19. <div
  20. :id="'infoGridFieldId_' + infoGridField.fieldName" class="rz-handle" draggable="true"
  21. @dragstart="ondragstart($event, infoGridField)" @drag="ondrag($event, infoGridField)"
  22. @dragend="ondragend($event, infoGridField)"
  23. />
  24. <div
  25. v-tooltip.right="Language.getHelpTrl($i18n.locale, infoGridField)
  26. " class="td-max"
  27. >
  28. {{ Language.getNameTrl($i18n.locale, infoGridField) }}
  29. </div>
  30. </th>
  31. </template>
  32. <th v-if="operateButtons != null && operateButtons.length > 0" style="width: 160px;">
  33. 操作
  34. </th>
  35. </tr>
  36. </thead>
  37. <tbody>
  38. <tr
  39. v-for="(item1, index) in infoWindowDataInstance.dataList" :key="'tr' + item1.id" height="40px"
  40. :class="{ warning: item1.select }" @dblclick="selectNode(item1)"
  41. >
  42. <td style="text-align: center">
  43. {{
  44. index +
  45. 1 +
  46. (pagination.current_page - 1) * pagination.per_page
  47. }}
  48. </td>
  49. <td class="text-center">
  50. <input
  51. autocomplete="off" type="checkbox" :checked="item1.select"
  52. @click.self="selectNodeForSearch(item1)"
  53. />
  54. </td>
  55. <template v-for="item2 in infoGridFieldsInstance.infoGridFields">
  56. <td
  57. v-show="item2.isShow" v-if="item2.simpleDisplayType != 'OperateButton'" id="item.id"
  58. :key="'td-' + item2.id"
  59. >
  60. <span v-if="item2.simpleDisplayType == 'Image'">
  61. <QueryPageImage
  62. v-if="item1.data[item2.fieldName] != undefined"
  63. :class-name="item2.selectClause"
  64. :image-names="item1.data[item2.fieldName].displayValue[0]"
  65. />
  66. </span>
  67. <span v-else>
  68. {{
  69. item1.data[item2.fieldName] != undefined
  70. ? item1.data[item2.fieldName].displayValue[0]
  71. : ""
  72. }}
  73. </span>
  74. </td>
  75. </template>
  76. <td v-if="operateButtons != null && operateButtons.length > 0">
  77. <template v-for="item in operateButtons" :key="item">
  78. <a-button @click="executeCallout(item1, item)">{{ item.name }}</a-button>
  79. </template>
  80. </td>
  81. </tr>
  82. </tbody>
  83. </table>
  84. </div>
  85. </template>
  86. <script>
  87. import Context from './Context.js';
  88. import JsUtil from '../../common/JsUtil.js';
  89. import Language from '../../common/Language.js';
  90. import QueryPageImage from './QueryPageImage.vue';
  91. import Uuid from '../../common/Uuid.js';
  92. import Notify from '../../common/Notify.js';
  93. export default {
  94. name: 'QueryPageTable',
  95. components: {
  96. QueryPageImage,
  97. },
  98. props: {
  99. callOutJsUrl:{
  100. type: String,
  101. default() {
  102. return null;
  103. },
  104. },
  105. infoWindowDataInstance: {
  106. type: Object,
  107. default() {
  108. return {};
  109. },
  110. },
  111. pagination: {
  112. type: Object,
  113. default() {
  114. return {};
  115. },
  116. },
  117. infoGridFieldsInstance: {
  118. type: Object,
  119. default() {
  120. return {};
  121. },
  122. },
  123. /**
  124. * 是否多选
  125. */
  126. multiple: {
  127. type: Boolean,
  128. default: false,
  129. },
  130. // 是否勾选了全选
  131. isSelectAllInput: {
  132. type: Boolean,
  133. default : false,
  134. },
  135. /**
  136. * 排序对象实例
  137. */
  138. sortInstance: {
  139. type: Object,
  140. default() {
  141. return {};
  142. },
  143. },
  144. },
  145. emits: ['dataSelected', 'deleteSelected','infoSelected'],
  146. data: function () {
  147. this.Language = Language;
  148. return {
  149. isSelectAll: false,
  150. multipleSelect: false,
  151. // 表格外面的DIV的id
  152. tableOutDivId: Uuid.createUUID(),
  153. modelDatas:[],
  154. };
  155. },
  156. computed: {
  157. tableWidth: function () {
  158. var totalWidth = 50;
  159. if (this.infoGridFieldsInstance != undefined
  160. && this.infoGridFieldsInstance.infoGridFields != undefined) {
  161. this.infoGridFieldsInstance.infoGridFields.forEach(function (item) {
  162. if (item.isShow) {
  163. totalWidth += Number(item.width);
  164. }
  165. });
  166. }
  167. return totalWidth + 'px';
  168. },
  169. operateButtons: function () {
  170. let buttons = [];
  171. this.infoGridFieldsInstance.infoGridFields.forEach(item => {
  172. if (item.simpleDisplayType == 'OperateButton') {
  173. buttons.push(item);
  174. }
  175. });
  176. return buttons;
  177. },
  178. },
  179. watch: {
  180. isSelectAllInput: function (val) {
  181. var _self = this;
  182. _self.isSelectAll = val;
  183. },
  184. /**
  185. * 是否选择了全部的数据
  186. */
  187. isSelectAll: function (val) {
  188. var _self = this;
  189. if (_self.multipleSelect) {
  190. if (_self.isSelectAll) {
  191. if (val) {
  192. _self.infoWindowDataInstance.setAllSelect();
  193. _self.$emit('infoSelected',val);
  194. }
  195. } else {
  196. _self.infoWindowDataInstance.setAllUnSelect();
  197. _self.$emit('infoSelected',val);
  198. }
  199. } else {
  200. _self.isSelectAll = false;
  201. _self.$emit('infoSelected',val);
  202. }
  203. },
  204. multiple: {
  205. handler: function (newValue, oldValue) {
  206. this.multipleSelect = newValue;
  207. },
  208. immediate: true,
  209. },
  210. 'infoWindowDataInstance.timestamp': function (newValue, oldValue) {
  211. this.fixedTableHeader();
  212. },
  213. },
  214. methods: {
  215. getContext: Context,
  216. executeCallout: function (rowData, filedItem) {
  217. let _self = this;
  218. const methodName = filedItem.callOutJsMethod;
  219. const callOutJsUrl = this.infoWindowDto.callOutJsUrl;
  220. let functionName = methodName.replace('.', '_') + '_calloutjs';
  221. let executeFunction = function () {
  222. let context = new _self.getContext(rowData, {});
  223. try {
  224. _self[functionName](context);
  225. } catch (e) {
  226. console.error(e);
  227. Notify.error('数据字典定义异常', ` 【 ${methodName} 】前端列显示逻辑定义异常,请联系管理员检查数据字典的定义。`, false);
  228. }
  229. };
  230. if (_self[functionName] == null) {
  231. // 执行服务端的脚本
  232. const jsUrl = callOutJsUrl;
  233. if (jsUrl == null || jsUrl == undefined) {
  234. Notify.error('数据字典定义异常', `【 ${methodName} 】Callout前端逻辑的JS文件不存在,请联系管理员检查数据字典是否JS文件。`, false);
  235. return;
  236. }
  237. let promise = JsUtil.dynamicLoadJsFunction(jsUrl, methodName);
  238. promise.then(targetFunction => {
  239. if (targetFunction == null) {
  240. Notify.error('数据字典定义异常', `【 ${methodName} 】Callout前端逻辑定义异常,请联系管理员检查数据字典的定义。`, false);
  241. return;
  242. }
  243. _self[functionName] = targetFunction;
  244. executeFunction();
  245. }, errorData => {
  246. console.error(errorData);
  247. });
  248. } else {
  249. executeFunction();
  250. }
  251. },
  252. /**
  253. * 切换全选/单选
  254. */
  255. changeSelectMode: function () {
  256. this.multipleSelect = !this.multipleSelect;
  257. },
  258. ondragstart: function (event, gridFieldItem) {
  259. var _self = this;
  260. _self.startX = event.pageX;
  261. _self.startWidth = Number(gridFieldItem.width);
  262. event.dataTransfer.setDragImage(event.target, 0, 20);
  263. event.dataTransfer.effectAllowed = 'move';
  264. },
  265. ondrag: function (event, gridFieldItem) {
  266. var _self = this;
  267. gridFieldItem.width = _self.startWidth + (event.pageX - _self.startX);
  268. },
  269. ondragend: function (event, gridFieldItem, index) {
  270. var _self = this;
  271. let newWidth = _self.startWidth + (event.pageX - _self.startX);
  272. if (newWidth < 50) {
  273. newWidth = 50;
  274. }
  275. _self.infoGridFieldsInstance.changeGridFieldWidth(gridFieldItem, newWidth);
  276. },
  277. ondragover: function (event, gridFieldItem) {
  278. event.preventDefault();
  279. event.dataTransfer.dropEffect = 'move';
  280. },
  281. /**
  282. * 选择/取消选择表格行中的复选框事件
  283. */
  284. selectNodeForSearch: function (modelData) {
  285. var _self = this;
  286. var currentStatus = modelData.select;
  287. if (!_self.multipleSelect) {
  288. _self.infoWindowDataInstance.setAllUnSelect();
  289. }
  290. _self.infoWindowDataInstance.selectSelectState(modelData, !currentStatus);
  291. if (modelData.select === true) {
  292. _self.$emit('dataSelected', modelData);
  293. _self.$emit('infoSelected');
  294. } else {
  295. _self.$emit('deleteSelected', modelData);
  296. _self.$emit('infoSelected');
  297. }
  298. },
  299. /**
  300. * 双击表格行事件
  301. */
  302. selectNode: function (modelData) {
  303. this.$emit('dataSelected', modelData);
  304. },
  305. /**
  306. * 冻结表头
  307. */
  308. fixedTableHeader: function () {
  309. let _self = this;
  310. _self.$nextTick(function () {
  311. var $th = $('#' + _self.tableOutDivId).find('thead');
  312. $('#' + _self.tableOutDivId).on('scroll', function () {
  313. $th.css('transform', 'translateY(' + this.scrollTop + 'px)');
  314. });
  315. });
  316. },
  317. /**
  318. * 排序
  319. */
  320. onSort: function (infoGridField) {
  321. var _self = this;
  322. var fieldName = null;
  323. if (
  324. infoGridField.sortFieldName != undefined &&
  325. infoGridField.sortFieldName != ''
  326. ) {
  327. fieldName = infoGridField.sortFieldName;
  328. } else {
  329. fieldName = infoGridField.fieldName;
  330. }
  331. _self.sortInstance.changeFieldName(fieldName);
  332. },
  333. },
  334. };
  335. </script>
  336. <style scoped>
  337. .flex-main {
  338. overflow: scroll;
  339. flex: 1;
  340. margin-bottom: 0px;
  341. }
  342. .fixed-table {
  343. table-layout: fixed;
  344. }
  345. table.fixed-table tr th {
  346. text-align: center;
  347. }
  348. table.fixed-table td {
  349. text-align: center;
  350. word-wrap: break-word;
  351. word-break: normal;
  352. }
  353. table.fixed-table th {
  354. position: relative;
  355. min-width: 25px;
  356. }
  357. table.fixed-table th,
  358. table.fixed-table td {
  359. overflow: hidden;
  360. white-space: nowrap;
  361. text-overflow: ellipsis;
  362. border-right: 1px solid rgba(0, 0, 0, 0.05);
  363. }
  364. table.fixed-table th {
  365. min-width: 10px;
  366. background-color: #f8f8f8;
  367. }
  368. table.fixed-table th .rz-handle {
  369. width: 10px;
  370. height: 100%;
  371. position: absolute;
  372. top: 0;
  373. right: 0;
  374. background: repeating-linear-gradient(45deg,
  375. transparent,
  376. transparent 2px,
  377. rgba(0, 0, 0, 0.05) 2px,
  378. rgba(0, 0, 0, 0.05) 4px);
  379. cursor: ew-resize !important;
  380. }
  381. table.fixed-table th .rz-handle.rz-handle-active {
  382. border-right: 2px solid #000;
  383. transform: scaleX(100);
  384. background: rgba(0, 0, 0, 0.05) 2px;
  385. }
  386. .rz-handle:hover {
  387. background: rgba(0, 0, 0, 0.2) 4px;
  388. }
  389. </style>