2025-07-08 16:49:39 +08:00
|
|
|
<template>
|
|
|
|
|
<picker
|
|
|
|
|
:range="pickerList"
|
|
|
|
|
:range-key="props?.key || 'name'"
|
|
|
|
|
:disabled="props?.disabled"
|
|
|
|
|
@change="onChange"
|
|
|
|
|
>
|
|
|
|
|
<view class="picker_select_btn">
|
|
|
|
|
<view class="label">{{ selectValue || props?.placeholder }}</view>
|
|
|
|
|
<uni-icons type="down" color="#333" size="12" />
|
|
|
|
|
</view>
|
|
|
|
|
</picker>
|
|
|
|
|
</template>
|
|
|
|
|
<script setup lang="ts">
|
2025-07-09 00:34:00 +08:00
|
|
|
import { getApiLoading } from '@/common/libraries/apiLoading'
|
|
|
|
|
import { onMounted, ref, watch } from 'vue'
|
2025-07-08 16:49:39 +08:00
|
|
|
const props = defineProps([
|
2025-07-09 00:34:00 +08:00
|
|
|
'Enums',
|
|
|
|
|
'title',
|
|
|
|
|
'pickerIndex',
|
|
|
|
|
'value',
|
|
|
|
|
'borderTop',
|
|
|
|
|
'required',
|
|
|
|
|
'disabled',
|
|
|
|
|
'tip',
|
|
|
|
|
'key',
|
|
|
|
|
'des',
|
|
|
|
|
'padding',
|
|
|
|
|
'valueModel',
|
|
|
|
|
'placeholder',
|
|
|
|
|
'Apis'
|
|
|
|
|
])
|
|
|
|
|
const pickerList = ref<any>([])
|
|
|
|
|
const selectValue = ref('')
|
|
|
|
|
const emit = defineEmits(['change', 'update:valueModel'])
|
2025-07-08 16:49:39 +08:00
|
|
|
const onChange = (e: any) => {
|
2025-07-09 00:34:00 +08:00
|
|
|
let selectData: any = pickerList.value[e?.detail.value]
|
|
|
|
|
selectValue.value = selectData?.name
|
|
|
|
|
emit('update:valueModel', selectData?.id || '')
|
|
|
|
|
emit('change', selectData)
|
|
|
|
|
}
|
2025-07-08 16:49:39 +08:00
|
|
|
|
|
|
|
|
const getPickerList = () => {
|
2025-07-09 00:34:00 +08:00
|
|
|
getApiLoading(props?.Apis, {}).then(res => {
|
|
|
|
|
pickerList.value = [...[{ name: props?.placeholder, id: 0 }], ...res?.data]
|
|
|
|
|
console.log(res)
|
|
|
|
|
})
|
|
|
|
|
}
|
2025-07-08 16:49:39 +08:00
|
|
|
|
|
|
|
|
onMounted(() => {
|
2025-07-09 00:34:00 +08:00
|
|
|
getPickerList()
|
|
|
|
|
})
|
2025-07-08 16:49:39 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.picker_select_btn {
|
|
|
|
|
background-color: #eee;
|
|
|
|
|
padding: 14rpx 20rpx;
|
|
|
|
|
border-radius: 100rpx;
|
|
|
|
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
color: #333;
|
|
|
|
|
margin-left: 30rpx;
|
|
|
|
|
|
|
|
|
|
text {
|
|
|
|
|
padding-right: 10rpx;
|
|
|
|
|
}
|
|
|
|
|
.label {
|
|
|
|
|
white-space: nowrap; /* 防止文本换行 */
|
|
|
|
|
overflow: hidden; /* 隐藏超出部分的内容 */
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
min-width: 100rpx;
|
|
|
|
|
max-width: 200rpx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|