index_inside.vue.btl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <%
  3. var searchCount = 0;
  4. var row = 0;
  5. %>
  6. <% for(var i = 0; i < configList.~size; i++) { %>
  7. <% if(!configList[i].needTableId && configList[i].needPage) { searchCount ++; }%>
  8. <% } %>
  9. <a-card :bordered="false" v-if="indexShow">
  10. <% if (searchCount > 0) { %>
  11. <a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
  12. <a-row :gutter="24">
  13. <% for(var i = 0; i < configList.~size; i++) { %>
  14. <% if(!configList[i].needTableId && configList[i].needPage) { row ++; %>
  15. <% if(row <= 3) { %>
  16. <a-col :span="6">
  17. <% if(configList[i].effectType == 'input' || configList[i].effectType == 'textarea') { %>
  18. <a-form-item label="${configList[i].fieldRemark}" name="${configList[i].fieldNameCamelCase}">
  19. <a-input v-model:value="searchFormState.${configList[i].fieldNameCamelCase}" placeholder="请输入${configList[i].fieldRemark}" allow-clear/>
  20. </a-form-item>
  21. <% } else if (configList[i].effectType == 'select' || configList[i].effectType == 'radio' || configList[i].effectType == 'checkbox') {%>
  22. <a-form-item label="${configList[i].fieldRemark}" name="${configList[i].fieldNameCamelCase}">
  23. <a-select v-model:value="searchFormState.${configList[i].fieldNameCamelCase}" placeholder="请选择${configList[i].fieldRemark}" :options="${configList[i].fieldNameCamelCase}Options" show-search allow-clear optionFilterProp="label"/>
  24. </a-form-item>
  25. <% } else if (configList[i].effectType == 'inputNumber' || configList[i].effectType == 'slider') {%>
  26. <a-form-item label="${configList[i].fieldRemark}" name="${configList[i].fieldNameCamelCase}">
  27. <a-input-number v-model:value="searchFormState.${configList[i].fieldNameCamelCase}" placeholder="请输入${configList[i].fieldRemark}" style="width: 100%" />
  28. </a-form-item>
  29. <% } else if (configList[i].effectType == 'datepicker') {%>
  30. <a-form-item label="${configList[i].fieldRemark}" name="${configList[i].fieldNameCamelCase}">
  31. <a-range-picker v-model:value="searchFormState.${configList[i].fieldNameCamelCase}" value-format="YYYY-MM-DD HH:mm:ss" show-time allow-clear/>
  32. </a-form-item>
  33. <% } else {%>
  34. <a-form-item label="${configList[i].fieldRemark}" name="${configList[i].fieldNameCamelCase}">
  35. <a-input v-model:value="searchFormState.${configList[i].fieldNameCamelCase}" placeholder="请输入${configList[i].fieldRemark}" allow-clear/>
  36. </a-form-item>
  37. <% } %>
  38. </a-col>
  39. <% } else { %>
  40. <a-col :span="6" v-show="advanced">
  41. <% if(configList[i].effectType == 'input' || configList[i].effectType == 'textarea') { %>
  42. <a-form-item label="${configList[i].fieldRemark}" name="${configList[i].fieldNameCamelCase}">
  43. <a-input v-model:value="searchFormState.${configList[i].fieldNameCamelCase}" placeholder="请输入${configList[i].fieldRemark}" allow-clear/>
  44. </a-form-item>
  45. <% } else if (configList[i].effectType == 'select' || configList[i].effectType == 'radio' || configList[i].effectType == 'checkbox') {%>
  46. <a-form-item label="${configList[i].fieldRemark}" name="${configList[i].fieldNameCamelCase}">
  47. <a-select v-model:value="searchFormState.${configList[i].fieldNameCamelCase}" placeholder="请选择${configList[i].fieldRemark}" :options="${configList[i].fieldNameCamelCase}Options" show-search allow-clear optionFilterProp="label"/>
  48. </a-form-item>
  49. <% } else if (configList[i].effectType == 'inputNumber' || configList[i].effectType == 'slider') {%>
  50. <a-form-item label="${configList[i].fieldRemark}" name="${configList[i].fieldNameCamelCase}">
  51. <a-input-number v-model:value="searchFormState.${configList[i].fieldNameCamelCase}" placeholder="请输入${configList[i].fieldRemark}" style="width: 100%" />
  52. </a-form-item>
  53. <% } else if (configList[i].effectType == 'datepicker') {%>
  54. <a-form-item label="${configList[i].fieldRemark}" name="${configList[i].fieldNameCamelCase}">
  55. <a-range-picker v-model:value="searchFormState.${configList[i].fieldNameCamelCase}" show-time allow-clear/>
  56. </a-form-item>
  57. <% } else {%>
  58. <a-form-item label="${configList[i].fieldRemark}" name="${configList[i].fieldNameCamelCase}">
  59. <a-input v-model:value="searchFormState.${configList[i].fieldNameCamelCase}" placeholder="请输入${configList[i].fieldRemark}" allow-clear/>
  60. </a-form-item>
  61. <% } %>
  62. </a-col>
  63. <% } %>
  64. <% } %>
  65. <% } %>
  66. <a-col :span="6">
  67. <a-button type="primary" @click="onSearch()">查询</a-button>
  68. <a-button style="margin: 0 8px" @click="reset">重置</a-button>
  69. <% if(searchCount > 3) { %>
  70. <a @click="toggleAdvanced" style="margin-left: 8px">
  71. {{ advanced ? '收起' : '展开' }}
  72. <component :is="advanced ? 'up-outlined' : 'down-outlined'"/>
  73. </a>
  74. <% }%>
  75. </a-col>
  76. </a-row>
  77. </a-form>
  78. <% } %>
  79. <s-table
  80. ref="tableRef"
  81. :columns="columns"
  82. :data="loadData"
  83. :alert="options.alert.show"
  84. bordered
  85. <% for(var i = 0; i < configList.~size; i++) { %>
  86. <% if(configList[i].needTableId) { %>
  87. :row-key="(record) => record.${configList[i].fieldNameCamelCase}"
  88. <% } %>
  89. <% } %>
  90. :tool-config="toolConfig"
  91. :row-selection="options.rowSelection"
  92. v-model:filterParam="filterParam"
  93. :scroll="{ x: 2000 }"
  94. >
  95. <template #operator class="table-operator">
  96. <a-space>
  97. <a-button type="primary" @click="onDetail()" v-if="hasPerm('${classNameFirstLower}Add')">
  98. <template #icon><plus-outlined /></template>
  99. 新增
  100. </a-button>
  101. <xn-batch-delete
  102. v-if="hasPerm('${classNameFirstLower}Delete')"
  103. :selectedRowKeys="selectedRowKeys"
  104. @batchDelete="deleteBatch${className}"
  105. />
  106. <a-button @click="onExport" v-if="hasPerm('${classNameFirstLower}BatchExport')">
  107. <template #icon><export-outlined /></template>
  108. 批量导出
  109. </a-button>
  110. </a-space>
  111. </template>
  112. <template #bodyCell="{ column, record }">
  113. <% for(var i = 0; i < configList.~size; i++) { %>
  114. <% if(!configList[i].needTableId && configList[i].whetherTable) { %>
  115. <% if (configList[i].effectType == 'select' || configList[i].effectType == 'radio') { %>
  116. <template v-if="column.dataIndex === '${configList[i].fieldNameCamelCase}'">
  117. {{ $TOOL.dictTypeData('${configList[i].dictTypeCode}', record.${configList[i].fieldNameCamelCase}) }}
  118. </template>
  119. <% } else if (configList[i].effectType == 'checkbox') { %>
  120. <template v-if="column.dataIndex === '${configList[i].fieldNameCamelCase}'">
  121. <a-tag v-for="textValue in JSON.parse(record.${configList[i].fieldNameCamelCase})" :key="textValue" color="green">{{ $TOOL.dictTypeData('${configList[i].dictTypeCode}', textValue) }}</a-tag>
  122. </template>
  123. <% } else if (configList[i].effectType == 'imageUpload') { %>
  124. <template v-if="column.dataIndex === '${configList[i].fieldNameCamelCase}'">
  125. <a-image :src="record.${configList[i].fieldNameCamelCase}" style="width: 30px; height: 30px;" />
  126. </template>
  127. <% } else if (configList[i].effectType == 'fileUpload') { %>
  128. <template v-if="column.dataIndex === '${configList[i].fieldNameCamelCase}'">
  129. <a :href="record.${configList[i].fieldNameCamelCase}" :target="record.${configList[i].fieldNameCamelCase}">{{ record.${configList[i].fieldNameCamelCase} }}</a>
  130. </template>
  131. <% } %>
  132. <% } %>
  133. <% } %>
  134. <template v-if="column.dataIndex === 'action'">
  135. <a-space>
  136. <a @click="onDetail(record, true)" v-if="hasPerm('${classNameFirstLower}View')">查看</a>
  137. <a-divider type="vertical" v-if="hasPerm('${classNameFirstLower}View') && hasPerm(['${classNameFirstLower}Edit', '${classNameFirstLower}Delete'], 'or')" />
  138. <a @click="onDetail(record)" v-if="hasPerm('${classNameFirstLower}Edit')">编辑</a>
  139. <a-divider type="vertical" v-if="hasPerm(['${classNameFirstLower}Edit', '${classNameFirstLower}Delete'], 'and')" />
  140. <a-popconfirm title="确定要删除吗?" @confirm="delete${className}(record)">
  141. <a-button type="link" danger size="small" v-if="hasPerm('${classNameFirstLower}Delete')">删除</a-button>
  142. </a-popconfirm>
  143. </a-space>
  144. </template>
  145. </template>
  146. </s-table>
  147. </a-card>
  148. <Detail v-else ref="detailRef" @onClose="indexShow = true" @successful="onSearch()" />
  149. </template>
  150. <script setup name="${busName}">
  151. <%
  152. var iptTool = 0;
  153. if (searchCount > 0) {
  154. for(var i = 0; i < configList.~size; i++) {
  155. if(!configList[i].needTableId) {
  156. if(configList[i].effectType == 'select' || configList[i].effectType == 'radio' || configList[i].effectType == 'checkbox') {
  157. iptTool++;
  158. }
  159. }
  160. }
  161. }
  162. %>
  163. <% if(iptTool > 0) { %>
  164. import tool from '@/utils/tool'
  165. <% } %>
  166. import { cloneDeep } from 'lodash-es'
  167. import Detail from './detail.vue'
  168. import ${classNameFirstLower}Api from '@/api/${moduleName}/${classNameFirstLower}Api'
  169. import downloadUtil from "@/utils/downloadUtil";
  170. const { proxy } = getCurrentInstance()
  171. <% if (searchCount > 0) { %>
  172. const searchFormState = ref({})
  173. const searchFormStateReal = ref({}) // 点击搜索后备份的查询参数
  174. const searchFormRef = ref()
  175. <% } %>
  176. const tableRef = ref()
  177. const filterParam = ref({})
  178. const detailRef = ref()
  179. const indexShow = ref(true)
  180. const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
  181. <% if(searchCount > 3) { %>
  182. // 查询区域显示更多控制
  183. const advanced = ref(false)
  184. const toggleAdvanced = () => {
  185. advanced.value = !advanced.value
  186. }
  187. <% } %>
  188. const columns = [
  189. <% for(var i = 0; i < configList.~size; i++) { %>
  190. <% if(!configList[i].needTableId && configList[i].whetherTable) { %>
  191. {
  192. title: '${configList[i].fieldRemark}',
  193. dataIndex: '${configList[i].fieldNameCamelCase}',
  194. <% if(configList[i].whetherRetract) { %>
  195. ellipsis: true,
  196. <% } %>
  197. <% if(configList[i].whetherSort) { %>
  198. sorter: true,
  199. <% } %>
  200. <% if(configList[i].whetherFixed != 0) { %>
  201. fixed: '<% if(configList[i].whetherFixed == 1) { %>left<% } %><% if(configList[i].whetherFixed == 2) { %>right<% } %>',
  202. <% } %>
  203. },
  204. <% } %>
  205. <% } %>
  206. ]
  207. // 操作栏通过权限判断是否显示
  208. if (hasPerm(['${classNameFirstLower}Edit', '${classNameFirstLower}Delete'])) {
  209. columns.push({
  210. title: '操作',
  211. dataIndex: 'action',
  212. align: 'center',
  213. width: 200,
  214. fixed: 'right',
  215. })
  216. }
  217. const selectedRowKeys = ref([])
  218. // 列表选择配置
  219. const options = {
  220. // columns数字类型字段加入 needTotal: true 可以勾选自动算账
  221. alert: {
  222. show: true,
  223. clear: () => {
  224. selectedRowKeys.value = ref([])
  225. }
  226. },
  227. rowSelection: {
  228. onChange: (selectedRowKey, selectedRows) => {
  229. selectedRowKeys.value = selectedRowKey
  230. }
  231. }
  232. }
  233. const loadData = (parameter) => {
  234. tableRef.value.clearSelected()
  235. <% if (searchCount > 0) { %>
  236. <% for(var i = 0; i < configList.~size; i++) { %>
  237. <% if(!configList[i].needTableId && configList[i].needPage) { %>
  238. <% if (configList[i].effectType == 'datepicker') {%>
  239. // ${configList[i].fieldNameCamelCase}范围查询条件重载
  240. if (searchFormStateReal.value.${configList[i].fieldNameCamelCase}) {
  241. searchFormStateReal.value.start${configList[i].fieldNameCamelCaseFirstUpper} = searchFormStateReal.value.${configList[i].fieldNameCamelCase}[0]
  242. searchFormStateReal.value.end${configList[i].fieldNameCamelCaseFirstUpper} = searchFormStateReal.value.${configList[i].fieldNameCamelCase}[1]
  243. delete searchFormStateReal.value.${configList[i].fieldNameCamelCase}
  244. }
  245. <% } %>
  246. <% } %>
  247. <% } %>
  248. return ${classNameFirstLower}Api.${classNameFirstLower}Page(Object.assign(parameter, searchFormStateReal.value)).then((data) => {
  249. <% } else { %>
  250. return ${classNameFirstLower}Api.${classNameFirstLower}Page(parameter).then((data) => {
  251. <% } %>
  252. return data
  253. })
  254. }
  255. // 搜索同时备份参数
  256. const onSearch = (parameter) => {
  257. searchFormStateReal.value = cloneDeep(searchFormState.value)
  258. tableRef.value.refresh(parameter)
  259. }
  260. // 重置
  261. const reset = () => {
  262. searchFormRef.value.resetFields()
  263. onSearch(true)
  264. }
  265. // 删除
  266. const delete${className} = (record) => {
  267. let params = [
  268. {
  269. <% for(var i = 0; i < configList.~size; i++) { %>
  270. <% if(configList[i].needTableId) { %>
  271. ${configList[i].fieldNameCamelCase}: record.${configList[i].fieldNameCamelCase}
  272. <% } %>
  273. <% } %>
  274. }
  275. ]
  276. ${classNameFirstLower}Api.${classNameFirstLower}Delete(params).then(() => {
  277. tableRef.value.refresh(true)
  278. })
  279. }
  280. // 批量删除
  281. const deleteBatch${className} = (params) => {
  282. ${classNameFirstLower}Api.${classNameFirstLower}Delete(params).then(() => {
  283. tableRef.value.clearRefreshSelected()
  284. })
  285. }
  286. // 批量导出
  287. const onExport = () => {
  288. const params = {
  289. ...filterParam.value
  290. }
  291. if (selectedRowKeys.value.length > 0) {
  292. params.ids = selectedRowKeys.value
  293. } else {
  294. Object.entries(searchFormStateReal.value).forEach(([key, value]) => {
  295. console.log(key)
  296. if (proxy.$util.isValue(value)) {
  297. params[key] = value
  298. }
  299. })
  300. }
  301. ${classNameFirstLower}Api.${classNameFirstLower}Export(params).then((res) => {
  302. downloadUtil.resultDownload(res)
  303. tableRef.value.clearSelected()
  304. })
  305. }
  306. // 切换至表单
  307. const onDetail = (record = null, view) => {
  308. indexShow.value = false
  309. nextTick(() => {
  310. detailRef.value.onOpen(record, view)
  311. })
  312. }
  313. <% if (searchCount > 0) { %>
  314. <% for(var i = 0; i < configList.~size; i++) { %>
  315. <% if(!configList[i].needTableId && configList[i].needPage) { %>
  316. <% if (configList[i].effectType == 'select' || configList[i].effectType == 'radio' || configList[i].effectType == 'checkbox') { %>
  317. const ${configList[i].fieldNameCamelCase}Options = tool.dictList('${configList[i].dictTypeCode}')
  318. <% } %>
  319. <% } %>
  320. <% } %>
  321. <% } %>
  322. </script>