ExtSContainer.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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" size="default">取消</el-button>
  46. <el-button type="primary" @click="confirm" size="default">确定</el-button>
  47. </span>
  48. </template>
  49. </el-drawer>
  50. </template>
  51. <script setup lang="ts" name="ExtSContainer">
  52. import {defineAsyncComponent, nextTick, onMounted, reactive, ref} from 'vue';
  53. import {$body, $get} 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 props = defineProps({
  60. listKey: {
  61. type: String,
  62. default: 'list'
  63. },
  64. countKey: {
  65. type: String,
  66. default: 'total'
  67. },
  68. idKey:{
  69. type:String,
  70. default:'id'
  71. }
  72. })
  73. const state = reactive({
  74. queryItem: {
  75. id: undefined,
  76. },
  77. init: false,
  78. columns: [],
  79. initColumns: [
  80. {label: 'ID', prop: 'userId', width: 170, query: false, type: 'number', conf: {op: 'eq'}, resizable: true},
  81. {label: '名称', prop: 'userName', width: 120,query: false, type: 'text', resizable: true},
  82. ],
  83. datas: [],
  84. checkIds: [],
  85. chosenIdList: [],
  86. config: {} as any,
  87. show: false,
  88. queryForm: {},
  89. pageQuery: {
  90. pageIndex: 1,
  91. pageSize: 20,
  92. total: 0
  93. },
  94. callback: () => {
  95. },
  96. dataList: [],
  97. checkDataList: [],
  98. multiple: false,
  99. height: 500,
  100. loading: false
  101. })
  102. onMounted(() => {
  103. // initQuery();
  104. console.log("ExtSContainer>>>>>>>>>>onMounted")
  105. })
  106. const open = (callback: Function, multiple: boolean = false, config: any, chosenIdList: Array<number>) => {
  107. state.config = config;
  108. state.show = true;
  109. state.multiple = multiple;
  110. state.callback = callback;
  111. state.chosenIdList = chosenIdList;
  112. initQuery();
  113. loadData(true)
  114. }
  115. const handleSortChange = (sort: any) => {
  116. console.log("handleSortChange>>>>", sort)
  117. //TODO 合并查询条件
  118. }
  119. const handleCheckChange = (list: any) => {
  120. console.log("xxxx choosexxxx", list)
  121. state.checkDataList = list;
  122. }
  123. const loadData = (refresh: boolean = false) => {
  124. if (refresh) {
  125. state.pageQuery.pageIndex = 1;
  126. }
  127. let {url, domain, cols, query, method} = state.config;
  128. let requestQuery = {...state.pageQuery, ...query, ...state.queryForm}
  129. console.log(requestQuery)
  130. switch (method) {
  131. case 'get':
  132. $get(url, requestQuery).then((res: any) => {
  133. state.loading = false;
  134. state.pageQuery.total = res[props.countKey]
  135. state.dataList = props.listKey ? res[props.listKey] : res;
  136. })
  137. break;
  138. case 'body':
  139. default:
  140. $body(url, requestQuery).then((res: any) => {
  141. state.loading = false;
  142. let {list, count} = res;
  143. state.pageQuery.total = res[props.countKey]
  144. state.dataList = props.listKey ? res[props.listKey] : res;
  145. })
  146. break;
  147. }
  148. }
  149. const confirm = () => {
  150. if (state.callback && typeof state.callback === 'function') {
  151. state.callback.apply(null, [state.checkDataList]);
  152. }
  153. /* let list = [];
  154. for (var i = 0; i < this.dataList.length; i++) {
  155. if (this.containsInIds(this.dataList[i].id)) {
  156. list.push(this.dataList[i]);
  157. }
  158. }
  159. if (this.options.callback && list.length > 0) {
  160. this.options.callback(list);
  161. }*/
  162. state.show = false;
  163. }
  164. /**
  165. * 设置基础构造查询字段、展示字段等
  166. */
  167. const initQuery = () => {
  168. if (state.init) {
  169. return;
  170. }
  171. let {columns, query} = state.config;
  172. if (!u.isEmptyOrNull(columns)) {
  173. state.columns = state.initColumns.concat(columns);
  174. console.log(state.columns)
  175. }
  176. console.log(state.config)
  177. if (query) {
  178. state.queryForm = {...state.queryForm, ...query}
  179. // Object.keys(query).forEach(k=>state.queryForm[k] = query[k]);
  180. }
  181. console.log(state.queryForm)
  182. state.init = true;
  183. nextTick(() => {
  184. let bodyHeight = document.body.clientHeight;
  185. let queryHeight = queryRef.value?.$el.clientHeight;
  186. state.height = bodyHeight - queryHeight - 150
  187. console.log(state.height)
  188. })
  189. }
  190. // 暴露变量
  191. defineExpose({
  192. open,
  193. });
  194. </script>