分区-公共组件select-暴露info属性、needAll开关和handleChange钩子

This commit is contained in:
khalil
2025-04-01 12:02:30 +08:00
committed by chenruiye
parent 19e048873d
commit e710c02d3d
7 changed files with 40 additions and 29 deletions

View File

@@ -1,10 +0,0 @@
import request from '@/utils/request';
// 分区接口
export const listPartitionInfo = query => {
return request({
url: '/partition/listPartitionInfo',
method: 'get',
params: query
});
};

View File

@@ -3,7 +3,7 @@
<el-select
v-model="partitionIdValue"
:placeholder="placeholder"
@change="handleChange"
@change="handleChangeEvent"
>
<!-- 遍历 partitionInfoList 数组为每个 item 生成一个 el-option 组件 -->
<el-option
@@ -18,7 +18,7 @@
<script>
import { ref, watch, onMounted } from "vue";
import { listPartitionInfo } from "@/api/common/partition";
import { getPartitionInfoList, listAll } from "@/api/partition/partitionInfo";
export default {
name: "partitionSelect",
@@ -29,6 +29,10 @@ export default {
default: undefined,
required: true,
},
needAll: {
type: Boolean,
default: false,
},
partitionInfos: {
type: Array,
default: () => [],
@@ -37,14 +41,20 @@ export default {
type: String,
default: "请选择分区",
},
handleChange: {
type: Function,
default: () => {},
},
},
// 明确声明触发的事件
emits: ["update:partitionId"],
emits: ["update:partitionId", "update:partitionInfos"],
setup(props, { emit }) {
// 定义响应式变量 partitionInfoList 用于存储分区信息列表
const partitionInfoList = ref(props.partitionInfos);
// 定义响应式变量 internalValue 用于内部管理 partitionId 的值
const partitionIdValue = ref(props.partitionId);
const needAllValue = ref(props.needAll);
const handleChangeFunc = ref(props.handleChange);
// 监听外部传入的 partitionId 变化,并同步到 internalValue
watch(
@@ -56,22 +66,33 @@ export default {
// 在组件挂载时加载分区信息
onMounted(() => {
listPartitionInfo().then((res) => {
partitionInfoList.value = res.data;
partitionIdValue.value = partitionInfoList.value[0].id;
const listDateFunc = !needAllValue.value? getPartitionInfoList: listAll;
listDateFunc().then((res) => {
setPartitionInfos(res.data)
});
});
const setPartitionInfos = (data) => {
partitionInfoList.value = data;
partitionIdValue.value = partitionInfoList.value? partitionInfoList.value[0].id: undefined;
emit("update:partitionId", partitionIdValue.value);
emit("update:partitionInfos", partitionInfoList.value);
};
// 处理选择变化时触发的事件,并通过 emit 通知父组件
const handleChange = (value) => {
const handleChangeEvent = (value) => {
partitionIdValue.value = value
emit("update:partitionId", value);
handleChangeFunc.value(value);
};
// 返回需要暴露给模板使用的变量和方法
return {
partitionInfoList,
partitionIdValue,
handleChange,
partitionInfoList,
handleChangeEvent,
};
},
};

View File

@@ -119,7 +119,7 @@
<script>
import { ref, onMounted } from 'vue'
import { listPartitionInfo } from "@/api/common/partition";
import { getPartitionInfoList } from "@/api/partition/partitionInfo";
import { dateFormat } from "@/utils/system-helper";
import { formatDate } from "@/utils/relDate";
import {
@@ -334,7 +334,7 @@ export default {
detailPageFun();
};
onMounted(() => {
listPartitionInfo().then(res => {
getPartitionInfoList().then(res => {
partitionOptions.value = res.data;
});
getGameOptions()

View File

@@ -70,7 +70,7 @@
<script>
import { ref, onMounted } from 'vue'
import { listPartitionInfo } from "@/api/common/partition";
import { getPartitionInfoList } from "@/api/partition/partitionInfo";
import { dateFormat } from "@/utils/system-helper";
import { formatDate } from "@/utils/relDate";
import {
@@ -200,7 +200,7 @@ export default {
console.log()
}
onMounted(() => {
listPartitionInfo().then(res => {
getPartitionInfoList().then(res => {
partitionOptions.value = res.data;
});
getGameOptions()

View File

@@ -71,7 +71,7 @@
</template>
<script>
import { ref, onMounted ,reactive} from 'vue'
import { listPartitionInfo } from "@/api/common/partition";
import { getPartitionInfoList } from "@/api/partition/partitionInfo";
import { dateFormat } from "@/utils/system-helper";
import { ElMessage ,ElMessageBox} from "element-plus";
import { formatDate } from "@/utils/relDate";
@@ -200,7 +200,7 @@ export default {
getData();
};
onMounted(() => {
listPartitionInfo().then(res => {
getPartitionInfoList().then(res => {
partitionOptions.value = res.data;
formData.partitionId = partitionOptions.value[0].id;
getlistByPartition();

View File

@@ -83,7 +83,7 @@
</div>
</template>
<script>
import { listPartitionInfo } from "@/api/common/partition";
import { getPartitionInfoList } from "@/api/partition/partitionInfo";
import { pageRecord, exportRecord, listUserRecord } from "@/api/miniGame/miniGameWeekJackpot";
import { ElMessage, ElMessageBox } from 'element-plus'
@@ -112,7 +112,7 @@ export default {
};
},
created() {
listPartitionInfo().then((res) => {
getPartitionInfoList().then((res) => {
if (res.code !== 200) {
throw new Error(res.msg);
}

View File

@@ -57,7 +57,7 @@
<script>
import { ref, onMounted, reactive } from 'vue'
import { listPartitionInfo } from "@/api/common/partition";
import { getPartitionInfoList } from "@/api/partition/partitionInfo";
import { getavatarPaidRecordList, resetAvatarPaidRecord } from "@/api/users/userAvatarManagement";
import { ElMessage, ElMessageBox } from "element-plus";
export default {
@@ -118,7 +118,7 @@ export default {
getData();
};
onMounted(() => {
listPartitionInfo().then(res => {
getPartitionInfoList().then(res => {
partitionOptions.value = res.data;
});
});