From 44d277ec414a9223619730646f99ec16df78a451 Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周三, 07 5月 2025 17:59:33 +0800
Subject: [PATCH] 支持 导出模板
---
Weben_CMS专用代码生成器/Weben_CMS_TemplateDemo/web/src/widgets/HIAWms/Controllers/WmsMaterial.ts | 550 +++++++++++++++++++++++++++---------------------------
1 files changed, 275 insertions(+), 275 deletions(-)
diff --git "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Weben_CMS_TemplateDemo/web/src/widgets/HIAWms/Controllers/WmsMaterial.ts" "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Weben_CMS_TemplateDemo/web/src/widgets/HIAWms/Controllers/WmsMaterial.ts"
index 49acc29..1f51100 100644
--- "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Weben_CMS_TemplateDemo/web/src/widgets/HIAWms/Controllers/WmsMaterial.ts"
+++ "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Weben_CMS_TemplateDemo/web/src/widgets/HIAWms/Controllers/WmsMaterial.ts"
@@ -1,275 +1,275 @@
-import { ref, onMounted, reactive, Ref, nextTick, computed } from 'vue'
-import { injectModel } from '@/libs/Provider/Provider'
-import { WmsMaterial } from '../Models/WmsMaterial'
-import { ElMessage } from 'element-plus'
-import { ConfirmBox } from '@/components/ConfirmBox/ConfirmBox'
-import { useFile } from './File'
-
-interface CurrentType {
- row: any
- index: number
-}
-export const useWmsMaterial = (props: any, ctx?: any) => {
- const wmsMaterial = injectModel<WmsMaterial>('wmsMaterial')
- const { exportFile } = useFile()
- /**
- * 澶撮儴閰嶇疆
- */
- const headers = ref({})
- /**
- * 鍔ㄦ�佸垪閰嶇疆
- */
- const wmsMaterialColumns = ref<Record<string, any>>([])
- /**
- * 鎼滅储鍊�
- */
- const search = ref('')
-
- /**
- * 鎺掑簭
- */
- const sort = ref(0)
- /**
- * 閫夋嫨椤�
- */
- const selection = ref([])
- /**
- * 褰撳墠閫変腑鐨勮
- */
- const current = ref<any>(null)
- /**
- * 鏁版嵁婧�
- */
- const dataSource: Ref<any[]> = ref([])
-
- /**
- * 琛ㄦ牸
- */
- const tableRef = ref()
- const dialogConfig = reactive({
- visible: false,
- title: '',
- isAdd: false,
- })
- const dialogConfigForQuery = reactive({
- visible: false,
- title: '',
- isAdd: false,
- })
-
-
- const dialogSettingConfig = reactive({
- visible: false,
- title: '',
- })
-
- /**
- * 鍒嗛〉鏁版嵁
- */
- const paginationParams = ref({})
-
- /**
- * 鎵撳紑璇︽儏
- * @param row
- */
- const openDetail = (row: any) => {
- current.value = row
- dialogConfig.visible = true
- dialogConfig.title = row.name
- dialogConfig.isAdd = false
- sort.value = row.sort
- }
-
- const contextMenu = [
- {
- label: '灞曞紑璇︽儏',
- fn: (c: CurrentType) => {
- current.value = null
- sort.value = c.row.sort
- nextTick(() => openDetail(c.row))
- },
- divided: true,
- icon: 'o',
- },
- // {
- // label: '鍚戜笂娣诲姞',
- // fn: (c: CurrentType, pageNum: number) => {
- // current.value = null
- // sort.value = c.index + 1 + (pageNum - 1) * 50
- // dialogConfig.visible = true
- // dialogConfig.title = '娣诲姞'
- // dialogConfig.isAdd = false
- // },
- // divided: true,
- // icon: 'up',
- // },
- // {
- // label: '鍚戜笅娣诲姞',
- // fn: (c: CurrentType, pageNum: number) => {
- // current.value = null
- // sort.value = c.index + 2 + (pageNum - 1) * 50
- // dialogConfig.visible = true
- // dialogConfig.title = '娣诲姞'
- // dialogConfig.isAdd = false
- // },
- // divided: true,
- // icon: 'down',
- // },
- // {
- // label: '鍒涘缓鍓湰',
- // fn: async ({ row }: CurrentType) => {
- // await wmsMaterial.cloneData([row.id])
- // ElMessage.success('鍒涘缓鍓湰鎴愬姛')
- // tableRef.value?.getList()
- // },
- // divided: true,
- // icon: 'copy',
- // },
- {
- label: '鍒犻櫎',
- fn: async (c: CurrentType) => {
- const names = selection.value.map((item: { name: string }) => item.name)
- ConfirmBox(
- `鏄惁鍒犻櫎${names.length ? names.join(',') : c.row.name}`
- ).then(async () => {
- const ids = selection.value.map((item: { id: string }) => item.id)
- await wmsMaterial.deleteWmsMaterials(ids.length ? ids : [c.row.id])
- ElMessage.success('鍒犻櫎鎴愬姛')
- tableRef.value.getList()
- })
- },
- icon: 'close',
- },
- ]
-
- const onCheck = (records: any) => {
- selection.value = records
- }
-
- const onAddWmsMaterial = () => {
- const params = tableRef.value?.getPaginationParams()
- current.value = null
- dialogConfig.visible = true
- dialogConfig.isAdd = true
- dialogConfig.title = '娣诲姞'
- sort.value = params.totalCount + 1
- }
-
- //鐐瑰嚮鎸夐挳銆愰珮绾ф煡璇€��
- const onAdvancedQuery = () => {
- const params = tableRef.value?.getPaginationParams()
- current.value = null
- dialogConfigForQuery.visible = true
- dialogConfigForQuery.isAdd = true
- dialogConfigForQuery.title = '楂樼骇鏌ヨ'
- }
-
- const onConfirmWmsMaterial = async () => {
- dialogConfig.visible = false
- if (dialogConfig.isAdd) {
- tableRef.value?.scrollToRow({
- skip: true,
- })
- } else {
- await tableRef.value?.getList()
- }
- }
- /**
- * 琛岀偣鍑绘椂鏇存柊current
- */
- const onRowClick = ({ row }: any) => {
- if (dialogConfig.visible && current.value) {
- current.value = row
- }
- }
- /**
- * 瀵煎嚭
- */
- const onExport = () => {
- const params = tableRef.value?.getParams()
- exportFile('/api/v1/hIAWms/wmsMaterial/export', params, 'hIAWms')
- }
-
- /**
- * 鍏抽敭瀛楁悳绱�
- */
- const onSearch = () => {
- tableRef.value?.getList({
- Filter: search.value,
- })
- }
-
- /**
- * 閲嶇疆琛ㄦ牸鏁版嵁
- */
- const reloadList = () => {
- tableRef.value?.getList()
- }
- /**
- * 涓婁紶鎴愬姛
- */
- const onSuccess = () => {
- tableRef.value?.getList()
- ElMessage.success('瀵煎叆鎴愬姛')
- }
- /**
- * 澶辫触
- * @param err
- */
- const onError = (err: any) => {
- try {
- const message = JSON.parse(err.message)
- ElMessage.error(message.msg)
- } catch (error) {
- ElMessage.error('瀵煎叆澶辫触')
- }
- }
- /**
- * 涓婁紶閽╁瓙
- */
- const onBeforeUpload = (file: File) => {
- const format = ['xlsx', 'xls', 'csv']
- if (!format.includes(file.name.split('.')[1])) {
- ElMessage.error('瀵煎叆鏂囦欢鏍煎紡涓嶆纭紝璇峰鍏�.xlsx/.xls涓�.csv鏍煎紡鐨勬枃浠�')
- return false
- }
- return true
- }
-
- onMounted(() => {
- headers.value = {
- Authorization: `Bearer ${sessionStorage.getItem('Token')}`,
- 'X-Project': sessionStorage.getItem('X-Project'),
- }
- })
-
- ctx.expose({
- reloadList,
- })
-
- return {
- dataSource,
- contextMenu,
- dialogConfig,
- dialogConfigForQuery,
- dialogSettingConfig,
- tableRef,
- current,
- search,
- sort,
- wmsMaterialColumns,
- paginationParams,
- headers,
- onBeforeUpload,
- onError,
- onSuccess,
- openDetail,
- onSearch,
- onExport,
- onRowClick,
- onConfirmWmsMaterial,
- onCheck,
- onAddWmsMaterial,
- onAdvancedQuery
- }
-}
+import { ref, onMounted, reactive, Ref, nextTick, computed } from 'vue'
+import { injectModel } from '@/libs/Provider/Provider'
+import { WmsMaterial } from '../Models/WmsMaterial'
+import { ElMessage } from 'element-plus'
+import { ConfirmBox } from '@/components/ConfirmBox/ConfirmBox'
+import { useFile } from './File'
+
+interface CurrentType {
+ row: any
+ index: number
+}
+export const useWmsMaterial = (props: any, ctx?: any) => {
+ const wmsMaterial = injectModel<WmsMaterial>('wmsMaterial')
+ const { exportFile } = useFile()
+ /**
+ * 澶撮儴閰嶇疆
+ */
+ const headers = ref({})
+ /**
+ * 鍔ㄦ�佸垪閰嶇疆
+ */
+ const wmsMaterialColumns = ref<Record<string, any>>([])
+ /**
+ * 鎼滅储鍊�
+ */
+ const search = ref('')
+
+ /**
+ * 鎺掑簭
+ */
+ const sort = ref(0)
+ /**
+ * 閫夋嫨椤�
+ */
+ const selection = ref([])
+ /**
+ * 褰撳墠閫変腑鐨勮
+ */
+ const current = ref<any>(null)
+ /**
+ * 鏁版嵁婧�
+ */
+ const dataSource: Ref<any[]> = ref([])
+
+ /**
+ * 琛ㄦ牸
+ */
+ const tableRef = ref()
+ const dialogConfig = reactive({
+ visible: false,
+ title: '',
+ isAdd: false,
+ })
+ const dialogConfigForQuery = reactive({
+ visible: false,
+ title: '',
+ isAdd: false,
+ })
+
+
+ const dialogSettingConfig = reactive({
+ visible: false,
+ title: '',
+ })
+
+ /**
+ * 鍒嗛〉鏁版嵁
+ */
+ const paginationParams = ref({})
+
+ /**
+ * 鎵撳紑璇︽儏
+ * @param row
+ */
+ const openDetail = (row: any) => {
+ current.value = row
+ dialogConfig.visible = true
+ dialogConfig.title = row.name
+ dialogConfig.isAdd = false
+ sort.value = row.sort
+ }
+
+ const contextMenu = [
+ {
+ label: '灞曞紑璇︽儏',
+ fn: (c: CurrentType) => {
+ current.value = null
+ sort.value = c.row.sort
+ nextTick(() => openDetail(c.row))
+ },
+ divided: true,
+ icon: 'o',
+ },
+ // {
+ // label: '鍚戜笂娣诲姞',
+ // fn: (c: CurrentType, pageNum: number) => {
+ // current.value = null
+ // sort.value = c.index + 1 + (pageNum - 1) * 50
+ // dialogConfig.visible = true
+ // dialogConfig.title = '娣诲姞'
+ // dialogConfig.isAdd = false
+ // },
+ // divided: true,
+ // icon: 'up',
+ // },
+ // {
+ // label: '鍚戜笅娣诲姞',
+ // fn: (c: CurrentType, pageNum: number) => {
+ // current.value = null
+ // sort.value = c.index + 2 + (pageNum - 1) * 50
+ // dialogConfig.visible = true
+ // dialogConfig.title = '娣诲姞'
+ // dialogConfig.isAdd = false
+ // },
+ // divided: true,
+ // icon: 'down',
+ // },
+ // {
+ // label: '鍒涘缓鍓湰',
+ // fn: async ({ row }: CurrentType) => {
+ // await wmsMaterial.cloneData([row.id])
+ // ElMessage.success('鍒涘缓鍓湰鎴愬姛')
+ // tableRef.value?.getList()
+ // },
+ // divided: true,
+ // icon: 'copy',
+ // },
+ {
+ label: '鍒犻櫎',
+ fn: async (c: CurrentType) => {
+ const names = selection.value.map((item: { name: string }) => item.name)
+ ConfirmBox(
+ `鏄惁鍒犻櫎${names.length ? names.join(',') : c.row.name}`
+ ).then(async () => {
+ const ids = selection.value.map((item: { id: string }) => item.id)
+ await wmsMaterial.deleteWmsMaterials(ids.length ? ids : [c.row.id])
+ ElMessage.success('鍒犻櫎鎴愬姛')
+ tableRef.value.getList()
+ })
+ },
+ icon: 'close',
+ },
+ ]
+
+ const onCheck = (records: any) => {
+ selection.value = records
+ }
+
+ const onAddWmsMaterial = () => {
+ const params = tableRef.value?.getPaginationParams()
+ current.value = null
+ dialogConfig.visible = true
+ dialogConfig.isAdd = true
+ dialogConfig.title = '娣诲姞'
+ sort.value = params.totalCount + 1
+ }
+
+ //鐐瑰嚮鎸夐挳銆愰珮绾ф煡璇€��
+ const onAdvancedQuery = () => {
+ const params = tableRef.value?.getPaginationParams()
+ current.value = null
+ dialogConfigForQuery.visible = true
+ dialogConfigForQuery.isAdd = true
+ dialogConfigForQuery.title = '楂樼骇鏌ヨ'
+ }
+
+ const onConfirmWmsMaterial = async () => {
+ dialogConfig.visible = false
+ if (dialogConfig.isAdd) {
+ tableRef.value?.scrollToRow({
+ skip: true,
+ })
+ } else {
+ await tableRef.value?.getList()
+ }
+ }
+ /**
+ * 琛岀偣鍑绘椂鏇存柊current
+ */
+ const onRowClick = ({ row }: any) => {
+ if (dialogConfig.visible && current.value) {
+ current.value = row
+ }
+ }
+ /**
+ * 瀵煎嚭
+ */
+ const onExport = (data={}) => {
+ //const params = tableRef.value?.getParams()
+ exportFile('/api/v1/hIAWms/wmsMaterial/export', data, 'hIAWms')
+ }
+
+ /**
+ * 鍏抽敭瀛楁悳绱�
+ */
+ const onSearch = () => {
+ tableRef.value?.getList({
+ Filter: search.value,
+ })
+ }
+
+ /**
+ * 閲嶇疆琛ㄦ牸鏁版嵁
+ */
+ const reloadList = () => {
+ tableRef.value?.getList()
+ }
+ /**
+ * 涓婁紶鎴愬姛
+ */
+ const onSuccess = () => {
+ tableRef.value?.getList()
+ ElMessage.success('瀵煎叆鎴愬姛')
+ }
+ /**
+ * 澶辫触
+ * @param err
+ */
+ const onError = (err: any) => {
+ try {
+ const message = JSON.parse(err.message)
+ ElMessage.error(message.msg)
+ } catch (error) {
+ ElMessage.error('瀵煎叆澶辫触')
+ }
+ }
+ /**
+ * 涓婁紶閽╁瓙
+ */
+ const onBeforeUpload = (file: File) => {
+ const format = ['xlsx', 'xls', 'csv']
+ if (!format.includes(file.name.split('.')[1])) {
+ ElMessage.error('瀵煎叆鏂囦欢鏍煎紡涓嶆纭紝璇峰鍏�.xlsx/.xls涓�.csv鏍煎紡鐨勬枃浠�')
+ return false
+ }
+ return true
+ }
+
+ onMounted(() => {
+ headers.value = {
+ Authorization: `Bearer ${sessionStorage.getItem('Token')}`,
+ 'X-Project': sessionStorage.getItem('X-Project'),
+ }
+ })
+
+ ctx.expose({
+ reloadList,
+ })
+
+ return {
+ dataSource,
+ contextMenu,
+ dialogConfig,
+ dialogConfigForQuery,
+ dialogSettingConfig,
+ tableRef,
+ current,
+ search,
+ sort,
+ wmsMaterialColumns,
+ paginationParams,
+ headers,
+ onBeforeUpload,
+ onError,
+ onSuccess,
+ openDetail,
+ onSearch,
+ onExport,
+ onRowClick,
+ onConfirmWmsMaterial,
+ onCheck,
+ onAddWmsMaterial,
+ onAdvancedQuery
+ }
+}
--
Gitblit v1.9.3