index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <div>
  3. <!--自定义查询区域-->
  4. <div class="jeecg-basic-table-form-container" @keyup.enter="searchQuery" v-if="customSearch">
  5. <a-form ref="formRef" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
  6. <a-row :gutter="24">
  7. <a-col :lg="8">
  8. <a-form-item label="用户名">
  9. <a-input placeholder="请输入名称模糊查询" v-model:value="queryParam.name"></a-input>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :lg="8">
  13. <a-form-item label="年龄">
  14. <a-input placeholder="最小年龄" type="ge" v-model:value="queryParam.age_begin" style="width: calc(50% - 15px)"></a-input>
  15. <span>~</span>
  16. <a-input placeholder="最大年龄" type="le" v-model:value="queryParam.age_end" style="width: calc(50% - 15px)"></a-input>
  17. </a-form-item>
  18. </a-col>
  19. <template v-if="toggleSearchStatus">
  20. <a-col :lg="8">
  21. <a-form-item label="性别">
  22. <JDictSelectTag v-model:value="queryParam.sex" placeholder="请选择性别" dictCode="sex" />
  23. </a-form-item>
  24. </a-col>
  25. <a-col :lg="8">
  26. <a-form-item label="选择用户">
  27. <JDictSelectTag v-model:value="queryParam.id" placeholder="请选择用户" dictCode="demo,name,id" />
  28. </a-form-item>
  29. </a-col>
  30. </template>
  31. <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
  32. <a-col :lg="6">
  33. <a-button type="primary" preIcon="ant-design:search-outlined" @click="searchQuery">查询</a-button>
  34. <a-button type="primary" preIcon="ant-design:reload-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
  35. <a @click="toggleSearchStatus = !toggleSearchStatus" style="margin-left: 8px">
  36. {{ toggleSearchStatus ? '收起' : '展开' }}
  37. <Icon :icon="toggleSearchStatus ? 'ant-design:up-outlined' : 'ant-design:down-outlined'" />
  38. </a>
  39. </a-col>
  40. </span>
  41. </a-row>
  42. </a-form>
  43. </div>
  44. <BasicTable @register="registerTable" :rowSelection="rowSelection" :class="{ 'p-4': customSearch }">
  45. <template #form-age="{ model, field }">
  46. <a-input placeholder="最小年龄" type="ge" v-model:value="min" style="width: calc(50% - 15px)" @change="ageChange(model, field)"></a-input>
  47. <span>~</span>
  48. <a-input placeholder="最大年龄" type="le" v-model:value="max" style="width: calc(50% - 15px)" @change="ageChange(model, field)"></a-input>
  49. </template>
  50. <template #tableTitle>
  51. <a-button preIcon="ant-design:plus-outlined" type="primary" @click="handleAdd">新增</a-button>
  52. <a-upload name="file" :showUploadList="false" :customRequest="(file) => handleImportXls(file, getImportUrl, reload)">
  53. <a-button preIcon="ant-design:import-outlined" type="primary">导入</a-button>
  54. </a-upload>
  55. <a-button preIcon="ant-design:export-outlined" type="primary" @click="handleExportXls('单表示例', getExportUrl, exportParams)">导出</a-button>
  56. <a-button preIcon="ant-design:filter" type="primary" @click="">高级查询?</a-button>
  57. <a-button preIcon="ant-design:plus-outlined" type="primary" @click="openTab">打开Tab页</a-button>
  58. <a-button preIcon="ant-design:retweet-outlined" type="primary" @click="customSearch = !customSearch">{{ customSearch ? '表单配置查询' : '自定义查询' }}</a-button>
  59. <a-button preIcon="ant-design:import-outlined" type="primary" @click="handleImport">弹窗导入</a-button>
  60. <super-query :config="superQueryConfig" @search="handleSuperQuery" />
  61. <a-dropdown v-if="checkedKeys.length > 0">
  62. <template #overlay>
  63. <a-menu>
  64. <a-menu-item key="1" @click="batchHandleDelete">
  65. <Icon icon="ant-design:delete-outlined"></Icon>
  66. 删除
  67. </a-menu-item>
  68. </a-menu>
  69. </template>
  70. <a-button
  71. >批量操作
  72. <Icon style="fontsize: 12px" icon="ant-design:down-outlined"></Icon>
  73. </a-button>
  74. </a-dropdown>
  75. </template>
  76. <template #action="{ record }">
  77. <TableAction :actions="getActions(record)" />
  78. </template>
  79. </BasicTable>
  80. <DemoModal @register="registerModal" @success="reload" />
  81. <DemoDetailModal @register="registerDetailModal" />
  82. <JImportModal @register="registerModal1" :url="getImportUrl" online />
  83. </div>
  84. </template>
  85. <script lang="ts" setup>
  86. import { ref, unref, reactive, toRaw, watch, computed } from 'vue';
  87. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  88. import { useModal } from '/@/components/Modal';
  89. import DemoModal from './DemoModal.vue';
  90. import JImportModal from '/@/components/Form/src/jeecg/components/JImportModal.vue';
  91. import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
  92. import { useMessage } from '/@/hooks/web/useMessage';
  93. import { useMethods } from '/@/hooks/system/useMethods';
  94. import { getDemoList, deleteDemo, batchDeleteDemo, getExportUrl, getImportUrl } from './demo.api';
  95. import { columns, searchFormSchema } from './demo.data';
  96. import { useGo } from '/@/hooks/web/usePage';
  97. import { router } from '/@/router';
  98. import { filterObj } from '/@/utils/common/compUtils';
  99. import DemoDetailModal from './DemoDetailModal.vue';
  100. import SuperQuery from '/@/components/jeecg/super/superquery/SuperQuery.vue';
  101. const go = useGo();
  102. const checkedKeys = ref<Array<string | number>>([]);
  103. const [registerModal, { openModal }] = useModal();
  104. const [registerModal1, { openModal: openModal1 }] = useModal();
  105. const [registerDetailModal, { openModal: openDetailModal }] = useModal();
  106. const { handleExportXls, handleImportXls } = useMethods();
  107. const min = ref();
  108. const max = ref();
  109. const [registerTable, { reload, setProps }] = useTable({
  110. title: '单表示例',
  111. api: getDemoList,
  112. columns,
  113. formConfig: {
  114. labelWidth: 120,
  115. schemas: searchFormSchema,
  116. fieldMapToTime: [['birthday', ['birthday_begin', 'birthday_end'], 'YYYY-MM-DD HH:mm:ss']],
  117. fieldMapToNumber: [['age', ['age_begin', 'age_end']]],
  118. autoAdvancedCol: 2,
  119. actionColOptions: {
  120. style: { textAlign: 'left' },
  121. },
  122. },
  123. striped: true,
  124. useSearchForm: true,
  125. showTableSetting: true,
  126. clickToRowSelect: false,
  127. bordered: true,
  128. showIndexColumn: false,
  129. tableSetting: { fullScreen: true },
  130. canResize: false,
  131. rowKey: 'id',
  132. actionColumn: {
  133. width: 30,
  134. title: '操作',
  135. dataIndex: 'action',
  136. slots: { customRender: 'action' },
  137. fixed: undefined,
  138. },
  139. });
  140. /**
  141. * 选择列配置
  142. */
  143. const rowSelection = {
  144. type: 'checkbox',
  145. columnWidth: 20,
  146. selectedRowKeys: checkedKeys,
  147. onChange: onSelectChange,
  148. };
  149. function handleImport() {
  150. openModal1(true);
  151. }
  152. const exportParams = computed(() => {
  153. let paramsForm = {};
  154. if (checkedKeys.value && checkedKeys.value.length > 0) {
  155. paramsForm['selections'] = checkedKeys.value.join(',');
  156. }
  157. return filterObj(paramsForm);
  158. });
  159. /**
  160. * 操作列定义
  161. * @param record
  162. */
  163. function getActions(record) {
  164. return [
  165. {
  166. label: '编辑',
  167. onClick: handleEdit.bind(null, record),
  168. },
  169. {
  170. label: '删除',
  171. popConfirm: {
  172. title: '是否确认删除',
  173. confirm: handleDelete.bind(null, record),
  174. },
  175. },
  176. {
  177. label: '详情',
  178. onClick: handleDetail.bind(null, record),
  179. },
  180. ];
  181. }
  182. function handleDetail(record) {
  183. openDetailModal(true, {
  184. record,
  185. });
  186. }
  187. /**
  188. * 选择事件
  189. */
  190. function onSelectChange(selectedRowKeys: (string | number)[]) {
  191. console.log('checkedKeys------>', checkedKeys);
  192. checkedKeys.value = selectedRowKeys;
  193. }
  194. /**
  195. * 新增事件
  196. */
  197. function handleAdd() {
  198. openModal(true, {
  199. isUpdate: false,
  200. });
  201. }
  202. /**
  203. * 编辑事件
  204. */
  205. function handleEdit(record) {
  206. openModal(true, {
  207. record,
  208. isUpdate: true,
  209. });
  210. }
  211. /**
  212. * 删除事件
  213. */
  214. async function handleDelete(record) {
  215. await deleteDemo({ id: record.id }, reload);
  216. }
  217. /**
  218. * 批量删除事件
  219. */
  220. async function batchHandleDelete() {
  221. await batchDeleteDemo({ ids: checkedKeys.value }, reload);
  222. }
  223. /**
  224. * 年龄修改事件
  225. */
  226. function ageChange(model, field) {
  227. model[field] = [unref(min), unref(max)];
  228. }
  229. /**
  230. * 打开tab页面
  231. */
  232. function openTab() {
  233. go(`/comp/jeecg/basic`);
  234. }
  235. //-----自定义查询----begin--------
  236. const formElRef = ref();
  237. const labelCol = reactive({
  238. xs: { span: 24 },
  239. sm: { span: 7 },
  240. });
  241. const wrapperCol = reactive({
  242. xs: { span: 24 },
  243. sm: { span: 16 },
  244. });
  245. const toggleSearchStatus = ref(false);
  246. const customSearch = ref(false);
  247. const queryParam = reactive({
  248. name: '',
  249. age_begin: '',
  250. age_end: '',
  251. sex: '',
  252. id: '',
  253. });
  254. watch(customSearch, () => {
  255. setProps({ useSearchForm: !unref(customSearch) });
  256. });
  257. function searchQuery() {
  258. setProps({ searchInfo: toRaw(queryParam) });
  259. reload();
  260. }
  261. function searchReset() {
  262. Object.assign(queryParam, { name: '', age_begin: '', age_end: '', sex: '', id: '' });
  263. reload();
  264. }
  265. //自定义查询----end---------
  266. const superQueryConfig = reactive({
  267. name: { title: '名称', view: 'text', type: 'string', order: 1 },
  268. sex: { title: '性别', view: 'list', type: 'string', dictCode: 'sex', order: 2 },
  269. });
  270. function handleSuperQuery(params) {
  271. Object.keys(params).map((k) => {
  272. queryParam[k] = params[k];
  273. });
  274. searchQuery();
  275. }
  276. </script>
  277. <style lang="less" scoped>
  278. .jeecg-basic-table-form-container {
  279. .table-page-search-submitButtons {
  280. display: block;
  281. margin-bottom: 24px;
  282. white-space: nowrap;
  283. }
  284. }
  285. </style>