ExtSContainer.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <style scoped>
  2. </style>
  3. <template>
  4. <el-drawer
  5. ref="modal"
  6. v-model="state.show"
  7. show-close
  8. append-to-body
  9. :close-on-click-modal="false"
  10. :close-on-press-escape="false"
  11. title="选择"
  12. style="padding: 10px;"
  13. size="45%">
  14. <el-row>
  15. <el-col :span="24">
  16. <ExtQueryForm ref="queryRef"
  17. v-model="state.queryForm"
  18. :columns="state.columns"
  19. @on-change="loadData(true)"/>
  20. </el-col>
  21. </el-row>
  22. <el-row>
  23. <el-col :span="24">
  24. <el-scrollbar>
  25. <ExtTable
  26. :height="state.height"
  27. :data-list="state.dataList"
  28. :columns="state.columns"
  29. :show-check-box="state.multiple"
  30. :loading="state.loading"
  31. :border="true"
  32. :selectable="true"
  33. @on-check-change="handleCheckChange"
  34. @on-sort-change="handleSortChange"/>
  35. </el-scrollbar>
  36. </el-col>
  37. </el-row>
  38. <el-row>
  39. <el-col :span="24">
  40. <ExtPage v-model:value="state.pageQuery" @change="loadData(true)"/>
  41. </el-col>
  42. </el-row>
  43. <template #footer>
  44. <span class="dialog-footer">
  45. <el-button @click="state.show = false">取消</el-button>
  46. <el-button type="primary" @click="confirm">确定</el-button>
  47. </span>
  48. </template>
  49. </el-drawer>
  50. </template>
  51. <script setup lang="ts" name="ExtSContainer">
  52. import {reactive, onMounted, defineAsyncComponent,nextTick,ref} from 'vue';
  53. import {$body, $post} from "/@/utils/request";
  54. import u from "/@/utils/u";
  55. import ExtQueryForm from "/@/components/form/ExtQueryForm.vue";
  56. const ExtPage = defineAsyncComponent(() => import('/@/components/form/ExtPage.vue'))
  57. const ExtTable = defineAsyncComponent(() => import('/@/components/form/ExtTable.vue'))
  58. const queryRef = ref();
  59. const state = reactive({
  60. queryItem: {
  61. id: undefined,
  62. },
  63. init: false,
  64. columns: [
  65. {label: 'ID', prop: 'id', width: 70,query: true,type:'number',conf:{op:'eq'}},
  66. {label: '名称', prop: 'name', query: true, type: 'text', resizable: true},
  67. {label: '创建时间', prop: 'createAt', query: true,sortable: 'custom',type:'datetime',hide:true},
  68. {label: '更新时间', prop: 'updateAt',query: true, sortable: 'custom',type:'datetime',hide:true},
  69. ],
  70. datas: [],
  71. checkIds: [],
  72. chosenIdList: [],
  73. config: {} as any,
  74. show: false,
  75. queryForm: {},
  76. pageQuery: {
  77. pageIndex: 1,
  78. pageSize: 20,
  79. total: 0
  80. },
  81. callback: () => {
  82. },
  83. dataList: [],
  84. checkDataList: [],
  85. multiple: false,
  86. height:500,
  87. loading:false
  88. })
  89. onMounted(() => {
  90. // initQuery();
  91. console.log("ExtSContainer>>>>>>>>>>onMounted")
  92. })
  93. const open = (callback: Function, multiple: boolean = false, config: any, chosenIdList: Array<number>) => {
  94. state.config = config;
  95. state.show = true;
  96. state.multiple = multiple;
  97. state.callback = callback;
  98. state.chosenIdList = chosenIdList;
  99. initQuery();
  100. loadData(true)
  101. }
  102. const handleSortChange = (sort: any) => {
  103. console.log("handleSortChange>>>>", sort)
  104. //TODO 合并查询条件
  105. }
  106. const handleCheckChange = (list: any) => {
  107. console.log("xxxx choosexxxx", list)
  108. state.checkDataList = list;
  109. }
  110. const loadData = (refresh: boolean = false) => {
  111. if (refresh) {
  112. state.pageQuery.pageIndex = 1;
  113. }
  114. let {url, domain, cols, query} = state.config;
  115. // if (url) {
  116. // request = u.fmt.fmtUrl(url);
  117. // } else {
  118. // request = u.fmt.fmtUrl(`/${domain}/list`);
  119. // }
  120. let requestQuery = {...state.pageQuery,...query, ...state.queryForm}
  121. console.log(requestQuery)
  122. $body(url, requestQuery).then((res: any) => {
  123. state.loading = false;
  124. let {list, count} = res;
  125. state.pageQuery.total = count;
  126. state.dataList = list;
  127. })
  128. }
  129. const confirm = () => {
  130. if (state.callback && typeof state.callback === 'function') {
  131. state.callback.apply(null, [state.checkDataList]);
  132. }
  133. /* let list = [];
  134. for (var i = 0; i < this.dataList.length; i++) {
  135. if (this.containsInIds(this.dataList[i].id)) {
  136. list.push(this.dataList[i]);
  137. }
  138. }
  139. if (this.options.callback && list.length > 0) {
  140. this.options.callback(list);
  141. }*/
  142. state.show = false;
  143. }
  144. /**
  145. * 设置基础构造查询字段、展示字段等
  146. */
  147. const initQuery = () => {
  148. if (state.init) {
  149. return;
  150. }
  151. let {columns, query} = state.config;
  152. if (!u.isEmptyOrNull(columns)) {
  153. //
  154. }
  155. console.log(state.config)
  156. if (query) {
  157. state.queryForm = {...state.queryForm, ...query}
  158. // Object.keys(query).forEach(k=>state.queryForm[k] = query[k]);
  159. }
  160. console.log(state.queryForm)
  161. state.init = true;
  162. nextTick(() => {
  163. let bodyHeight = document.body.clientHeight;
  164. let queryHeight = queryRef.value?.$el.clientHeight;
  165. state.height = bodyHeight - queryHeight - 150
  166. console.log(state.height)
  167. })
  168. }
  169. // 暴露变量
  170. defineExpose({
  171. open,
  172. });
  173. </script>