Browse Source

中奖+活动持久化+导出

lihuilin/feature-20250718094329-25周年庆后台
wangxiangwen4 4 weeks ago
parent
commit
5dfc234ab0
  1. 10
      activitylink/src/api/manage/win.js
  2. 48
      activitylink/src/stone/winStone.js
  3. 15
      activitylink/src/views/zhongchou/activity/detail/index.vue
  4. 3
      activitylink/src/views/zhongchou/activity/index.vue
  5. 109
      activitylink/src/views/zhongchou/winning/index.vue

10
activitylink/src/api/manage/win.js

@ -24,4 +24,14 @@ export function getWinLevelList(){
url: '/admin/grade/allGradeName',
method: 'post',
})
}
export function exportWinExcel(data)
{
return request({
url: '/admin/win/export',
method: 'post',
data,
responseType: 'blob'
})
}

48
activitylink/src/stone/winStone.js

@ -0,0 +1,48 @@
import { defineStore } from "pinia";
import { ref } from 'vue';
import localforage from 'localforage';
// 创建本地存储实例
const winStorage = localforage.createInstance({
name: 'winStore',
storeName: 'winData'
});
export const useWinStone = defineStore('winStone', () => {
// 持久化参数:searchgradeId
const searchgradeId = ref(localStorage.getItem('searchgradeId') || '');
// 设置 searchgradeId 并持久化
const setSearchgradeId = (value) => {
searchgradeId.value = value;
localStorage.setItem('searchgradeId', value);
winStorage.setItem('searchgradeId', value).catch((err) => {
console.error('保存 searchgradeId 到 localforage 失败:', err);
});
};
// 初始化恢复数据
const initialize = async () => {
try {
const storedgradeId = await winStorage.getItem('searchgradeId');
if (storedgradeId !== null) {
searchgradeId.value = storedgradeId;
}
} catch (error) {
console.warn('从 localforage 恢复失败,尝试从 localStorage 恢复');
const localStoragegradeId = localStorage.getItem('searchgradeId');
if (localStoragegradeId !== null) {
searchgradeId.value = localStoragegradeId;
}
}
};
// 初始化时恢复数据
initialize();
// 暴露出去
return {
searchgradeId,
setSearchgradeId,
};
});

15
activitylink/src/views/zhongchou/activity/detail/index.vue

@ -70,7 +70,7 @@
<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useRouter , onBeforeRouteLeave} from 'vue-router'
import { useactivityStone } from '@/stone/activityStone'
import { getDetailListbyActivityId, getDetailMessage, getMarket, exportActivityDataExcel } from '@/api/manage/activity'
import { ElMessage } from 'element-plus'
@ -116,6 +116,7 @@ const pageSize = ref(10)
//
const goBack = () => {
router.back()
}
@ -219,6 +220,18 @@ onMounted(async () => {
fetchMarketList()
})
onBeforeRouteLeave((to, from, next) => {
// activity/index
if (to.name !== 'activityDetail') {
// activityStone
activityStone.setSearchUsername('')
activityStone.setSearchJwcode('')
}
next() // next()
})
//
const getDetailData = async () => {
try {

3
activitylink/src/views/zhongchou/activity/index.vue

@ -314,9 +314,6 @@ const handleCurrentChange = (val) => {
//
const goToDetail = (row) => {
activityStone.setselectedactivityId(row.id);
activityStone.setSearchUsername("");
activityStone.setSearchJwcode("");
router.push({ name: 'activityDetail' });
};

109
activitylink/src/views/zhongchou/winning/index.vue

@ -70,15 +70,21 @@
<script setup>
import { ref, onMounted } from 'vue'
import { getWinList, getWinLevelList } from '@/api/manage/win'
//
import { useactivityStone } from '@/stone/activityStone'
import { useWinStone } from '@/stone/winStone'
import { getWinList, getWinLevelList ,exportWinExcel} from '@/api/manage/win'
import { onBeforeRouteLeave } from 'vue-router'
import { ElMessage } from 'element-plus'
const activityStone = useactivityStone()
const winStone = useWinStone()
// 使
const searchParams = ref({
pageNum: 1,
pageSize: 10,
username: '',
gradeId: '',
jwcode: ''
username: "",
gradeId: "",
jwcode: ""
})
//
@ -104,9 +110,9 @@ const fetchWinLevelList = async () => {
const fetchWinList = async () => {
try {
const requestData = {
username: searchParams.value.username,
gradeId: searchParams.value.gradeId,
jwcode: searchParams.value.jwcode,
username: activityStone.searchUsername,
gradeId: winStone.searchgradeId,
jwcode: activityStone.searchJwcode,
pageNum: searchParams.value.pageNum,
pageSize: searchParams.value.pageSize
}
@ -125,36 +131,73 @@ const fetchWinList = async () => {
//
const handleSearch = () => {
searchParams.value.pageNum = 1
//
activityStone.setSearchUsername(searchParams.value.username)
activityStone.setSearchJwcode(searchParams.value.jwcode)
winStone.setSearchgradeId(searchParams.value.gradeId)
fetchWinList()
}
//
const handleExport = async () => {
try {
const username = activityStone.searchUsername;
const jwcode = activityStone.searchJwcode;
const gradeId = winStone.searchgradeId;
//
const exportData = {
gradeId,
username,
jwcode
};
// blob
const response = await exportWinExcel(exportData);
// Blob
const blob = new Blob([response], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
});
//
const downloadUrl = window.URL.createObjectURL(blob);
// <a>
const link = document.createElement('a');
link.href = downloadUrl;
link.setAttribute('download', '中奖用户.xlsx'); // .xlsx
document.body.appendChild(link);
link.click();
//
link.remove();
window.URL.revokeObjectURL(downloadUrl);
} catch (error) {
console.error('导出数据失败:', error);
ElMessage.error('导出数据失败');
}
};
//
const handleReset = () => {
searchParams.value = {
pageNum: 1,
pageSize: 10,
username: '',
gradeName: '',
gradeId: '',
jwcode: ''
}
fetchWinList()
}
//
const handleExport = () => {
console.log('导出数据')
}
//
const handleSizeChange = (val) => {
searchParams.value.pageSize = val
searchParams.value.pageNum = 1
fetchWinList()
}
//
activityStone.setSearchUsername('')
activityStone.setSearchJwcode('')
winStone.setSearchgradeId('')
//
const handleCurrentChange = (val) => {
searchParams.value.pageNum = val
fetchWinList()
}
@ -168,6 +211,20 @@ onMounted(() => {
fetchWinLevelList()
fetchWinList()
})
onBeforeRouteLeave((to, from, next) => {
// activity/index
if (to.name !== 'zhongchouwinning') {
// winStone gradeId
winStone.setSearchgradeId('')
// activityStone
activityStone.setSearchUsername('')
activityStone.setSearchJwcode('')
}
next() // next()
})
</script>
<style scoped>

Loading…
Cancel
Save