Merge remote-tracking branch 'origin/master'

This commit is contained in:
zjf committed 2025-10-20 12:16:23 +08:00
commit d8a296f47f
14 files changed
+1976 -15

No files matched your search

+1
View File
@@ -18,6 +18,7 @@
"@axolo/json-editor-vue": "^0.3.2",
"@chenfengyuan/vue-qrcode": "^2.0.0",
"@element-plus/icons-vue": "^2.0.10",
"@map-component/vue-tmap": "^1.0.1",
"@popperjs/core": "2.11.8",
"@vueuse/core": "^10.4.1",
"@vxe-ui/plugin-render-element": "^4.0.10",
+40
View File
@@ -0,0 +1,40 @@
import request from "/@/utils/request"
export function fetchList(query?: Object) {
return request({
url: "/wallet/mch-pick-up/page",
method: "get",
params: query,
})
}
export function addObj(obj?: Object) {
return request({
url: "/wallet/mch-pick-up",
method: "post",
data: obj,
})
}
export function getObj(id?: string) {
return request({
url: "/wallet/mch-pick-up/" + id,
method: "get",
})
}
export function delObjs(ids?: Object) {
return request({
url: "/wallet/mch-pick-up",
method: "delete",
data: ids,
})
}
export function putObj(obj?: Object) {
return request({
url: "/wallet/mch-pick-up",
method: "put",
data: obj,
})
}
+251
View File
@@ -0,0 +1,251 @@
<template>
<div class="business-hours-container">
<div class="business-hours-header">
<span class="title">营业时间设置</span>
<el-button type="primary" size="small" @click="addBusinessHour" :icon="Plus">
添加时间段
</el-button>
</div>
<div class="business-hours-list">
<div v-for="(item, index) in businessHours" :key="item.id" class="business-hour-item">
<div class="item-header">
<span class="item-index">{{ index + 1 }}</span>
<el-button type="danger" size="small" :icon="Delete" circle @click="removeBusinessHour(index)"
:disabled="businessHours.length <= 1" />
</div>
<div class="item-content">
<el-row :gutter="16">
<el-col :span="24" class="mb16">
<el-form-item :label="`时间段${index + 1}标题`" :prop="`businessHours.${index}.title`">
<el-input v-model="item.title" placeholder="请输入时间段标题(如:工作日、周末、上午、下午等)" @input="handleChange" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb16">
<el-form-item :label="`开始时间`" :prop="`businessHours.${index}.startTime`">
<el-time-picker v-model="item.startTime" placeholder="选择开始时间" format="HH:mm" value-format="HH:mm"
@change="handleChange" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb16">
<el-form-item :label="`结束时间`" :prop="`businessHours.${index}.endTime`">
<el-time-picker v-model="item.endTime" placeholder="选择结束时间" format="HH:mm" value-format="HH:mm"
@change="handleChange" />
</el-form-item>
</el-col>
</el-row>
</div>
</div>
</div>
<div v-if="businessHours.length === 0" class="empty-state">
<el-empty description="暂无营业时间,请点击上方按钮添加" />
</div>
</div>
</template>
<script setup lang="ts" name="BusinessHours">
import { Plus, Delete } from '@element-plus/icons-vue'
// 定义接口
interface BusinessHour {
id: string
title: string
startTime: string
endTime: string
}
// 定义props
interface Props {
modelValue?: BusinessHour[]
}
const props = withDefaults(defineProps<Props>(), {
modelValue: () => []
})
// 定义emits
const emit = defineEmits<{
'update:modelValue': [value: BusinessHour[]]
'change': [value: BusinessHour[]]
}>()
// 响应式数据
const businessHours = ref<BusinessHour[]>([])
// 生成唯一ID
const generateId = () => {
return Date.now().toString(36) + Math.random().toString(36).substr(2)
}
// 创建默认营业时间项
const createDefaultBusinessHour = (): BusinessHour => ({
id: generateId(),
title: '',
startTime: '09:00',
endTime: '18:00'
})
// 初始化数据
const initData = () => {
if (props.modelValue && props.modelValue.length > 0) {
businessHours.value = props.modelValue.map(item => ({
...item,
id: item.id || generateId()
}))
} else {
businessHours.value = [createDefaultBusinessHour()]
}
}
// 添加营业时间
const addBusinessHour = () => {
businessHours.value.push(createDefaultBusinessHour())
handleChange()
}
// 删除营业时间
const removeBusinessHour = (index: number) => {
if (businessHours.value.length > 1) {
businessHours.value.splice(index, 1)
handleChange()
}
}
// 时间转换为分钟
const timeToMinutes = (time: string): number => {
const [hours, minutes] = time.split(':').map(Number)
return hours * 60 + minutes
}
// 处理数据变化
const handleChange = () => {
const validBusinessHours = businessHours.value.filter(item =>
item.startTime && item.endTime
)
emit('update:modelValue', [...businessHours.value])
emit('change', validBusinessHours)
}
// 监听props变化
watch(() => props.modelValue, (newValue) => {
if (JSON.stringify(newValue) !== JSON.stringify(businessHours.value)) {
initData()
handleChange()
}
}, { deep: true })
// 组件挂载时初始化
onMounted(() => {
initData()
handleChange()
})
// 暴露验证方法
const validate = (): Promise<boolean> => {
return new Promise((resolve) => {
let isValid = true
for (let i = 0; i < businessHours.value.length; i++) {
const item = businessHours.value[i]
if (!item.title || !item.startTime || !item.endTime) {
isValid = false
break
}
const startMinutes = timeToMinutes(item.startTime)
const endMinutes = timeToMinutes(item.endTime)
if (endMinutes <= startMinutes) {
isValid = false
break
}
}
resolve(isValid)
})
}
defineExpose({
validate
})
</script>
<style scoped lang="scss">
.business-hours-container {
.business-hours-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
.title {
font-size: 14px;
font-weight: 500;
color: #303133;
}
}
.business-hours-list {
.business-hour-item {
border: 1px solid #e4e7ed;
border-radius: 6px;
padding: 16px;
margin-bottom: 16px;
background-color: #fafafa;
&:last-child {
margin-bottom: 0;
}
.item-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
.item-index {
display: inline-flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
background-color: #409eff;
color: white;
border-radius: 50%;
font-size: 12px;
font-weight: 500;
}
}
.item-content {
.mb16 {
margin-bottom: 16px;
&:last-child {
margin-bottom: 0;
}
}
}
}
}
.empty-state {
text-align: center;
padding: 40px 0;
}
}
:deep(.el-form-item) {
margin-bottom: 0;
}
:deep(.el-form-item__label) {
font-size: 13px;
color: #606266;
}
</style>
+5 -13
View File
@@ -1,17 +1,7 @@
<template>
<el-select
style="width: 100%"
v-model="selectId"
:placeholder="props.placeholder"
clearable
remote-show-suffix
filterable
remote
:disabled="props.disabled"
:remote-method="remoteSearch"
:loading="state.loading"
@visible-change="(e: boolean) => e && getOptions()"
>
<el-select style="width: 100%" v-model="selectId" :placeholder="props.placeholder" clearable remote-show-suffix
filterable remote :disabled="props.disabled" :remote-method="remoteSearch" :loading="state.loading"
@visible-change="(e: boolean) => e && getOptions()" :multiple="props.multiple">
<el-option v-for="v in state.options" :key="v.id" :label="`${v.name}`" :value="v.id">
<div class="flex items-center">
<div class="color-primary">{{ v.name }}</div>
@@ -37,12 +27,14 @@ const props = withDefaults(
apiParams?: any
autoFirst?: boolean
disabled?: boolean
multiple?: boolean
}>(),
{
placeholder: "请选择",
apiParams: {},
autoFirst: false,
disabled: false,
multiple: false
},
)
+4
View File
@@ -36,6 +36,8 @@ import SelectCabinet from "/@/components/Select/SelectCabinet.vue"
import SelectMchCatory from "/@/components/Select/SelectMchCatory.vue"
import SelectCanteenSupplier from "/@/components/Select/SelectCanteenSupplier.vue"
import SelectWalletInvoice from "/@/components/Select/SelectWalletInvoice.vue"
// 地图组件
import MapSelect from "/@/components/map/map-select.vue"
// 第三方组件
import ElementPlus from "element-plus"
@@ -94,6 +96,8 @@ export default {
app.component("SelectCanteenSupplier", SelectCanteenSupplier)
app.component("SelectWalletInvoice", SelectWalletInvoice)
app.component("MapSelect", MapSelect)
// 导入全部的elmenet-plus的图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
+414
View File
@@ -0,0 +1,414 @@
<template>
<el-dialog v-model="state.visibleMapDialog" title="地图位置选择器" width="80%" :before-close="handleClose"
class="map-picker-dialog">
<div class="map-picker-container">
<!-- 地图容器 -->
<div class="map-container">
<tmap-map ref="mapRef" style="width: 100%; height: 500px; cursor: pointer;"
mapKey="CGABZ-3MH66-6VGST-MEMS3-K6U3V-DGBKA" :center="map.center" :zoom="map.zoom"
:doubleClickZoom="map.doubleClickZoom" :events="{
click: handleMapClick,
mousemove: handleMapMouseMove,
mouseleave: handleMapMouseLeave,
}">
<!-- 标记点 -->
<tmap-marker v-if="state.selectedLocation" :position="state.selectedLocation" :draggable="true"
@dragend="handleMarkerDragEnd">
<template #default>
<div class="custom-marker">
<div class="marker-icon">
<i class="el-icon-location-outline"></i>
手动发送发送到发送方
</div>
<div class="marker-shadow"></div>
</div>
</template>
</tmap-marker>
</tmap-map>
<!-- 鼠标悬停坐标显示 -->
<div v-if="state.showHoverCoords && state.hoverLocation" class="hover-coords">
<div class="coords-tooltip">
<span>经度: {{ state.hoverLocation.lng.toFixed(6) }}</span>
<span>纬度: {{ state.hoverLocation.lat.toFixed(6) }}</span>
</div>
</div>
</div>
</div>
<template #footer>
<div class="dialog-footer">
<el-button @click="handleClose">取消</el-button>
<el-button type="primary" @click="handleConfirm" :disabled="!state.selectedLocation">
确定
</el-button>
</div>
</template>
</el-dialog>
</template>
<script setup lang="ts" name="map-picker-dialog">
import { reactive, ref, nextTick } from 'vue'
import { ElMessage } from 'element-plus'
// 定义事件
const emit = defineEmits(['confirm', 'close'])
// 响应式状态
const state = reactive({
visibleMapDialog: false,
selectedLocation: null as any,
hoverLocation: null as any, // 鼠标悬停位置
showHoverCoords: false // 是否显示悬停坐标
})
// 地图配置
const map = reactive<any>({
// 默认中心点(可以根据需要调整)
center: { lat: 39.908823, lng: 116.397470 }, // 北京天安门
zoom: 15,
doubleClickZoom: true,
})
// 地图引用
const mapRef = ref()
// 打开对话框
const open = (initialLocation?: any) => {
state.visibleMapDialog = true
resetState()
// 如果有初始位置,设置为当前选中位置
if (initialLocation) {
state.selectedLocation = { ...initialLocation }
map.center = initialLocation
}
// 等待DOM更新后初始化地图
nextTick(() => {
console.log('地图对话框已打开')
})
}
// 关闭对话框
const handleClose = () => {
state.visibleMapDialog = false
resetState()
emit('close')
}
// 重置状态
const resetState = () => {
state.selectedLocation = null
state.hoverLocation = null
state.showHoverCoords = false
}
// 地图鼠标移动事件
const handleMapMouseMove = (event: any) => {
const { lat, lng } = event.latLng
state.hoverLocation = { lat, lng }
state.showHoverCoords = true
}
// 地图鼠标离开事件
const handleMapMouseLeave = () => {
state.showHoverCoords = false
state.hoverLocation = null
}
// 地图点击事件
const handleMapClick = (event: any) => {
const { lat, lng } = event.latLng
state.selectedLocation = { lat, lng }
console.log('选中位置:', { lat, lng })
}
// 标记拖拽结束事件
const handleMarkerDragEnd = (event: any) => {
const { lat, lng } = event.latLng
state.selectedLocation = { lat, lng }
console.log('拖拽到位置:', { lat, lng })
}
// 确认选择
const handleConfirm = () => {
if (!state.selectedLocation) {
ElMessage.warning('请先选择一个位置')
return
}
const result = {
location: state.selectedLocation,
coordinates: `${state.selectedLocation.lng},${state.selectedLocation.lat}`,
// 提供多种坐标格式
formats: {
lngLat: `${state.selectedLocation.lng},${state.selectedLocation.lat}`,
latLng: `${state.selectedLocation.lat},${state.selectedLocation.lng}`,
lng: state.selectedLocation.lng,
lat: state.selectedLocation.lat
}
}
emit('confirm', result)
handleClose()
}
// 暴露方法
defineExpose({
open
})
</script>
<style scoped>
.map-picker-dialog {
.el-dialog__body {
padding: 0;
}
}
.map-picker-container {
display: flex;
flex-direction: column;
height: 600px;
}
.search-bar {
padding: 16px;
border-bottom: 1px solid #e4e7ed;
background: #fff;
}
.search-input {
width: 100%;
}
.map-container {
position: relative;
flex: 1;
overflow: hidden;
}
/* 鼠标悬停坐标显示 */
.hover-coords {
position: absolute;
top: 10px;
left: 10px;
pointer-events: none;
z-index: 1000;
}
.coords-tooltip {
background: rgba(0, 0, 0, 0.8);
color: white;
padding: 0px 6px;
border-radius: 6px;
font-size: 12px;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
display: flex;
align-items: center;
gap: 6px;
backdrop-filter: blur(4px);
}
.coords-tooltip i {
font-size: 14px;
color: #67c23a;
}
/* 自定义标记点样式 */
.custom-marker {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
cursor: pointer;
}
.marker-icon {
width: 32px;
height: 32px;
background: linear-gradient(135deg, #ff6b6b, #ee5a52);
border: 3px solid white;
border-radius: 50% 50% 50% 0;
transform: rotate(-45deg);
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4);
transition: all 0.3s ease;
}
.marker-icon:hover {
transform: rotate(-45deg) scale(1.1);
box-shadow: 0 6px 16px rgba(255, 107, 107, 0.6);
}
.marker-icon i {
color: white;
font-size: 16px;
transform: rotate(45deg);
font-weight: bold;
}
.marker-shadow {
width: 20px;
height: 8px;
background: rgba(0, 0, 0, 0.2);
border-radius: 50%;
margin-top: 2px;
filter: blur(2px);
}
.info-panel {
padding: 16px;
border-top: 1px solid #e4e7ed;
background: #f8f9fa;
max-height: 200px;
overflow-y: auto;
}
.location-info {
margin-bottom: 16px;
}
.info-row {
display: flex;
margin-bottom: 8px;
font-size: 14px;
}
.label {
color: #606266;
width: 80px;
flex-shrink: 0;
}
.value {
color: #303133;
flex: 1;
word-break: break-all;
}
.search-results {
border-top: 1px solid #e4e7ed;
padding-top: 16px;
}
.results-title {
font-size: 14px;
font-weight: 500;
color: #303133;
margin-bottom: 12px;
}
.results-list {
max-height: 150px;
overflow-y: auto;
}
.result-item {
padding: 8px 12px;
border: 1px solid #e4e7ed;
border-radius: 4px;
margin-bottom: 8px;
cursor: pointer;
transition: all 0.2s;
background: #fff;
}
.result-item:hover {
border-color: #409eff;
background: #f0f9ff;
}
.result-title {
font-size: 14px;
font-weight: 500;
color: #303133;
margin-bottom: 4px;
}
.result-address {
font-size: 12px;
color: #909399;
}
.dialog-footer {
display: flex;
justify-content: flex-end;
gap: 12px;
}
/* 响应式设计 */
@media (max-width: 768px) {
.map-picker-container {
height: 500px;
}
.info-panel {
max-height: 150px;
}
.info-row {
flex-direction: column;
}
.label {
width: auto;
margin-bottom: 4px;
}
}
/* 地图标记样式优化 */
:deep(.tmap-marker) {
animation: bounce 0.6s ease-in-out;
}
@keyframes bounce {
0%,
20%,
53%,
80%,
100% {
transform: translate3d(0, 0, 0);
}
40%,
43% {
transform: translate3d(0, -8px, 0);
}
70% {
transform: translate3d(0, -4px, 0);
}
90% {
transform: translate3d(0, -2px, 0);
}
}
/* 搜索结果滚动条样式 */
.results-list::-webkit-scrollbar,
.info-panel::-webkit-scrollbar {
width: 6px;
}
.results-list::-webkit-scrollbar-track,
.info-panel::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 3px;
}
.results-list::-webkit-scrollbar-thumb,
.info-panel::-webkit-scrollbar-thumb {
background: #c1c1c1;
border-radius: 3px;
}
.results-list::-webkit-scrollbar-thumb:hover,
.info-panel::-webkit-scrollbar-thumb:hover {
background: #a8a8a8;
}
</style>
+230
View File
@@ -0,0 +1,230 @@
<template>
<div class="map-example-container">
<el-card header="地图位置选择器示例">
<div class="example-section">
<h3>基础用法</h3>
<map-select v-model="basicLocation" placeholder="请选择位置" @change="handleBasicChange" />
<div v-if="basicLocation" class="result-display">
<p><strong>选中地址:</strong>{{ basicLocation.address }}</p>
<p><strong>经纬度:</strong>{{ basicLocation.coordinates }}</p>
</div>
</div>
<el-divider />
<div class="example-section">
<h3>只返回坐标</h3>
<map-select v-model="coordinatesOnly" placeholder="选择位置(只返回坐标)" return-format="coordinates"
@change="handleCoordinatesChange" />
<div v-if="coordinatesOnly" class="result-display">
<p><strong>坐标:</strong>{{ coordinatesOnly }}</p>
</div>
</div>
<el-divider />
<div class="example-section">
<h3>只返回地址</h3>
<map-select v-model="addressOnly" placeholder="选择位置(只返回地址)" return-format="address"
@change="handleAddressChange" />
<div v-if="addressOnly" class="result-display">
<p><strong>地址:</strong>{{ addressOnly }}</p>
</div>
</div>
<el-divider />
<div class="example-section">
<h3>隐藏坐标信息</h3>
<map-select v-model="noCoordinates" placeholder="选择位置(隐藏坐标)" :show-coordinates="false"
@change="handleNoCoordinatesChange" />
<div v-if="noCoordinates" class="result-display">
<p><strong>选中地址:</strong>{{ noCoordinates.address }}</p>
</div>
</div>
<el-divider />
<div class="example-section">
<h3>禁用状态</h3>
<map-select v-model="disabledLocation" placeholder="禁用状态" disabled />
</div>
<el-divider />
<div class="example-section">
<h3>预设位置</h3>
<el-button @click="setPresetLocation">设置预设位置(天安门)</el-button>
<map-select v-model="presetLocation" placeholder="预设位置示例" @change="handlePresetChange" />
<div v-if="presetLocation" class="result-display">
<p><strong>选中地址:</strong>{{ presetLocation.address }}</p>
<p><strong>经纬度:</strong>{{ presetLocation.coordinates }}</p>
</div>
</div>
<el-divider />
<div class="example-section">
<h3>表单集成示例</h3>
<el-form :model="formData" label-width="120px">
<el-form-item label="商店名称">
<el-input v-model="formData.name" placeholder="请输入商店名称" />
</el-form-item>
<el-form-item label="商店位置">
<map-select v-model="formData.location" placeholder="请选择商店位置"
@change="handleFormLocationChange" />
</el-form-item>
<el-form-item label="联系电话">
<el-input v-model="formData.phone" placeholder="请输入联系电话" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm">提交</el-button>
<el-button @click="resetForm">重置</el-button>
</el-form-item>
</el-form>
</div>
</el-card>
</div>
</template>
<script setup lang="ts">
import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus'
import MapSelect from './map-select.vue'
// 定义位置数据类型
interface LocationData {
address: string
location: { lat: number, lng: number }
coordinates: string
}
// 基础用法
const basicLocation = ref<LocationData | null>(null)
const handleBasicChange = (value: any) => {
console.log('基础用法选择结果:', value)
}
// 只返回坐标
const coordinatesOnly = ref<string | null>(null)
const handleCoordinatesChange = (value: any) => {
console.log('坐标结果:', value)
}
// 只返回地址
const addressOnly = ref<string | null>(null)
const handleAddressChange = (value: any) => {
console.log('地址结果:', value)
}
// 隐藏坐标信息
const noCoordinates = ref<LocationData | null>(null)
const handleNoCoordinatesChange = (value: any) => {
console.log('隐藏坐标结果:', value)
}
// 禁用状态
const disabledLocation = ref<LocationData>({
address: '北京市朝阳区某某街道',
location: { lat: 39.9042, lng: 116.4074 },
coordinates: '116.4074,39.9042'
})
// 预设位置
const presetLocation = ref<LocationData | null>(null)
const setPresetLocation = () => {
presetLocation.value = {
address: '北京市东城区天安门广场',
location: { lat: 39.9042, lng: 116.4074 },
coordinates: '116.4074,39.9042'
}
}
const handlePresetChange = (value: any) => {
console.log('预设位置结果:', value)
}
// 表单集成
const formData = reactive<{
name: string
location: LocationData | null
phone: string
}>({
name: '',
location: null,
phone: ''
})
const handleFormLocationChange = (value: any) => {
console.log('表单位置选择:', value)
}
const submitForm = () => {
if (!formData.name) {
ElMessage.warning('请输入商店名称')
return
}
if (!formData.location) {
ElMessage.warning('请选择商店位置')
return
}
if (!formData.phone) {
ElMessage.warning('请输入联系电话')
return
}
console.log('提交表单数据:', formData)
ElMessage.success('表单提交成功')
}
const resetForm = () => {
formData.name = ''
formData.location = null
formData.phone = ''
ElMessage.info('表单已重置')
}
</script>
<style scoped>
.map-example-container {
padding: 20px;
max-width: 800px;
margin: 0 auto;
}
.example-section {
margin-bottom: 24px;
}
.example-section h3 {
margin-bottom: 16px;
color: #303133;
font-size: 16px;
font-weight: 600;
}
.result-display {
margin-top: 12px;
padding: 12px;
background: #f8f9fa;
border: 1px solid #e4e7ed;
border-radius: 4px;
font-size: 14px;
}
.result-display p {
margin: 4px 0;
color: #606266;
}
.result-display strong {
color: #303133;
}
.el-divider {
margin: 32px 0;
}
.el-form {
max-width: 500px;
}
</style>
+257
View File
@@ -0,0 +1,257 @@
<template>
<div class="map-select-container">
<el-input v-model="state.selectAddress" :placeholder="props.placeholder" :disabled="props.disabled"
:clearable="props.clearable" class="map-select-input" readonly @clear="handleClear">
<template #prepend v-if="state.selectedLocation">
<el-icon class="location-icon">
<Location />
</el-icon>
</template>
<template #append>
<el-button @click="handleMapClick" :disabled="props.disabled" class="map-button">
<el-icon>
<MapLocation />
</el-icon>
选择位置
</el-button>
</template>
</el-input>
<!-- 坐标信息显示 -->
<div v-if="state.selectedLocation && state.showCoordinates" class="coordinates-info">
<span class="coordinates-text">
经纬度: {{ state.selectedLocation.lng.toFixed(6) }}, {{ state.selectedLocation.lat.toFixed(6) }}
</span>
<el-button text size="small" @click="copyCoordinates" class="copy-btn">
<el-icon>
<CopyDocument />
</el-icon>
复制
</el-button>
</div>
<map-dialog ref="mapDialogRef" @confirm="handleLocationConfirm" @close="handleDialogClose" />
</div>
</template>
<script setup lang="ts" name="map-location-select">
import { reactive, ref, onMounted, watch, defineAsyncComponent } from 'vue'
import { ElMessage } from 'element-plus'
import { MapLocation, Location, CopyDocument } from '@element-plus/icons-vue'
const MapDialog = defineAsyncComponent(() => import('./map-dialog.vue'))
// 定义事件
const emit = defineEmits(['change', 'update:modelValue'])
// 定义属性
const props = withDefaults(
defineProps<{
modelValue?: any
placeholder?: string
disabled?: boolean
clearable?: boolean
showCoordinates?: boolean
returnFormat?: 'object' | 'coordinates' | 'address'
}>(),
{
placeholder: "请点击选择地图位置",
disabled: false,
clearable: true,
showCoordinates: true,
returnFormat: 'object'
}
)
// 响应式状态
const state = reactive<any>({
selectAddress: '',
selectedLocation: null,
selectedData: null
})
// 引用
const mapDialogRef = ref()
// 清空选择
const handleClear = () => {
state.selectAddress = ''
state.selectedLocation = null
state.selectedData = null
emit('update:modelValue', null)
emit('change', null)
}
// 打开地图选择器
const handleMapClick = () => {
if (props.disabled) return
// 如果已有位置,传递给对话框作为初始位置
mapDialogRef.value?.open(state.selectedLocation)
}
// 处理位置确认
const handleLocationConfirm = (result: any) => {
state.selectAddress = result.address
state.selectedLocation = result.location
state.selectedData = result
// 根据返回格式发送不同的值
let emitValue
switch (props.returnFormat) {
case 'coordinates':
emitValue = result.coordinates
break
case 'address':
emitValue = result.address
break
case 'object':
default:
emitValue = result
break
}
emit('update:modelValue', emitValue)
emit('change', emitValue)
ElMessage.success('位置选择成功')
}
// 处理对话框关闭
const handleDialogClose = () => {
// 对话框关闭时的处理
}
// 监听外部值变化
watch(() => props.modelValue, (newValue) => {
if (newValue) {
if (typeof newValue === 'object' && newValue.address) {
state.selectAddress = newValue.address
state.selectedLocation = newValue.location
state.selectedData = newValue
} else if (typeof newValue === 'string') {
state.selectAddress = newValue
}
} else {
handleClear()
}
}, { immediate: true })
onMounted(() => {
// 初始化
})
// 复制坐标
const copyCoordinates = async () => {
if (!state.selectedLocation) return
const coordinates = `${state.selectedLocation.lng},${state.selectedLocation.lat}`
try {
await navigator.clipboard.writeText(coordinates)
ElMessage.success('坐标已复制到剪贴板')
} catch (error) {
// 降级方案
const textArea = document.createElement('textarea')
textArea.value = coordinates
document.body.appendChild(textArea)
textArea.select()
document.execCommand('copy')
document.body.removeChild(textArea)
ElMessage.success('坐标已复制到剪贴板')
}
}
// 暴露方法
defineExpose({
open: handleMapClick,
clear: handleClear,
getLocation: () => state.selectedLocation,
getAddress: () => state.selectAddress,
getData: () => state.selectedData
})
</script>
<style scoped>
.map-select-container {
width: 100%;
}
.map-select-input {
width: 100%;
}
.map-select-input :deep(.el-input__inner) {
cursor: pointer;
}
.location-icon {
color: #409eff;
}
.map-button {
border: none;
background: #409eff;
color: white;
padding: 0 16px;
display: flex;
align-items: center;
gap: 4px;
transition: background-color 0.2s;
}
.map-button:hover {
background: #337ecc;
}
.map-button:disabled {
background: #c0c4cc;
cursor: not-allowed;
}
.coordinates-info {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 8px;
padding: 8px 12px;
background: #f8f9fa;
border: 1px solid #e4e7ed;
border-radius: 4px;
font-size: 12px;
}
.coordinates-text {
color: #606266;
flex: 1;
}
.copy-btn {
padding: 4px 8px;
height: auto;
font-size: 12px;
}
.copy-btn:hover {
color: #409eff;
}
/* 响应式设计 */
@media (max-width: 768px) {
.map-button {
padding: 0 12px;
font-size: 12px;
}
.coordinates-info {
flex-direction: column;
align-items: flex-start;
gap: 8px;
}
.copy-btn {
align-self: flex-end;
}
}
</style>
+2
View File
@@ -13,6 +13,7 @@ import VxeUITable from "vxe-table"
import "vxe-table/lib/style.css"
import VxeUIPluginRenderElement from "@vxe-ui/plugin-render-element"
import "@vxe-ui/plugin-render-element/dist/style.css"
import Tmap from "@map-component/vue-tmap"
// Initialize anti-debug protection
initAntiDebug()
@@ -37,4 +38,5 @@ app
.use(i18n) // 国际化
.use(VxeUI)
.use(VxeUITable)
.use(Tmap) // 腾讯地图
.mount("#app")
+187
View File
@@ -0,0 +1,187 @@
/**
* JSONP 工具函数
* 用于跨域请求
*/
interface JsonpOptions {
timeout?: number
callbackName?: string
callbackParam?: string
debug?: boolean
}
/**
* JSONP 请求
* @param url 请求地址
* @param options 配置选项
* @returns Promise
*/
export function jsonp(url: string, options: JsonpOptions = {}): Promise<any> {
const {
timeout = 15000,
callbackName = `jsonp_callback_${Date.now()}_${Math.random().toString(36).substr(2)}`,
callbackParam = "callback",
debug = false
} = options
if (debug) {
console.log('[JSONP] 发起请求:', url)
console.log('[JSONP] 回调函数名:', callbackName)
}
return new Promise((resolve, reject) => {
// 创建 script 标签
const script = document.createElement("script")
// 设置超时
const timer = setTimeout(() => {
cleanup()
const error = new Error(`JSONP request timeout after ${timeout}ms`)
if (debug) {
console.error('[JSONP] 请求超时:', error)
}
reject(error)
}, timeout)
// 清理函数
const cleanup = () => {
if (script.parentNode) {
script.parentNode.removeChild(script)
}
if ((window as any)[callbackName]) {
delete (window as any)[callbackName]
}
clearTimeout(timer)
}
// 设置全局回调函数
;(window as any)[callbackName] = (data: any) => {
if (debug) {
console.log('[JSONP] 收到响应:', data)
}
cleanup()
resolve(data)
}
// 处理错误
script.onerror = (event) => {
cleanup()
const error = new Error("JSONP request failed to load script")
if (debug) {
console.error('[JSONP] 脚本加载失败:', event)
}
reject(error)
}
// 构建请求 URL
const separator = url.includes("?") ? "&" : "?"
const requestUrl = `${url}${separator}${callbackParam}=${callbackName}`
if (debug) {
console.log('[JSONP] 完整请求URL:', requestUrl)
}
// 发起请求
script.src = requestUrl
script.async = true
document.head.appendChild(script)
})
}
/**
* 腾讯地图 API JSONP 请求封装
*/
export class TencentMapAPI {
private apiKey: string
private debug: boolean
constructor(apiKey: string, debug: boolean = false) {
this.apiKey = apiKey
this.debug = debug
}
/**
* 逆地址解析
* @param lat 纬度
* @param lng 经度
* @returns Promise
*/
async reverseGeocode(lat: number, lng: number): Promise<any> {
const url = `https://apis.map.qq.com/ws/geocoder/v1/?location=${lat},${lng}&key=${this.apiKey}&get_poi=1&output=jsonp`
if (this.debug) {
console.log('[TencentMapAPI] 逆地址解析请求:', { lat, lng })
}
try {
const data = await jsonp(url, { debug: this.debug })
if (this.debug) {
console.log('[TencentMapAPI] 逆地址解析响应:', data)
}
return data
} catch (error) {
console.error("逆地址解析失败:", error)
throw error
}
}
/**
* 地址搜索
* @param keyword 搜索关键词
* @param boundary 搜索范围
* @returns Promise
*/
async searchLocation(keyword: string, boundary: string = "region(全国,0)"): Promise<any> {
const url = `https://apis.map.qq.com/ws/place/v1/search?boundary=${encodeURIComponent(boundary)}&keyword=${encodeURIComponent(
keyword,
)}&page_size=10&page_index=1&key=${this.apiKey}&output=jsonp`
if (this.debug) {
console.log('[TencentMapAPI] 地址搜索请求:', { keyword, boundary })
}
try {
const data = await jsonp(url, { debug: this.debug })
if (this.debug) {
console.log('[TencentMapAPI] 地址搜索响应:', data)
}
return data
} catch (error) {
console.error("地址搜索失败:", error)
throw error
}
}
/**
* 地址解析(正向地理编码)
* @param address 地址
* @returns Promise
*/
async geocode(address: string): Promise<any> {
const url = `https://apis.map.qq.com/ws/geocoder/v1/?address=${encodeURIComponent(address)}&key=${this.apiKey}&output=jsonp`
try {
const data = await jsonp(url)
return data
} catch (error) {
console.error("地址解析失败:", error)
throw error
}
}
/**
* POI 搜索
* @param keyword 搜索关键词
* @param boundary 搜索范围
* @returns Promise
*/
async searchPOI(keyword: string, boundary: string = "region(全国,0)"): Promise<any> {
return this.searchLocation(keyword, boundary)
}
}
export default jsonp
+168
View File
@@ -0,0 +1,168 @@
<template>
<el-dialog :title="form.id ? '编辑' : '新增'" v-model="visible" :close-on-click-modal="false" draggable>
<el-form ref="dataFormRef" :model="form" :rules="dataRules" formDialogRef label-width="120px" v-loading="loading">
<el-row :gutter="24">
<el-col :span="24" class="mb20">
<el-form-item label="门店名称" prop="name">
<el-input v-model="form.name" placeholder="请输入门店名称" />
</el-form-item>
</el-col>
<el-col :span="24" class="mb20">
<el-form-item label="门店logo" prop="logo">
<upload-img v-model:imageUrl="form.logo" />
</el-form-item>
</el-col>
<el-col :span="24" class="mb20">
<el-form-item label="门店联系手机号" prop="phone">
<el-input v-model="form.phone" placeholder="请输入门店联系手机号" />
</el-form-item>
</el-col>
<el-col :span="24" class="mb20">
<el-form-item label="营业时间" prop="businessHoursJson">
<BusinessHours v-model="form.businessHoursJson" />
</el-form-item>
</el-col>
<el-col :span="24" class="mb20">
<el-form-item label="合作商户" prop="mchIds">
<select-mch multiple v-model="form.mchIds" placeholder="请选择合作商户" />
</el-form-item>
</el-col>
<el-col :span="24" class="mb20">
<el-form-item label="门店位置" prop="location">
<MapSelect />
</el-form-item>
</el-col>
<el-col :span="24" class="mb20">
<el-form-item label="门店简介" prop="introduction">
<el-input v-model="form.introduction" placeholder="请输入门店简介" type="textarea" :autosize="{ minRows: 2 }" />
</el-form-item>
</el-col>
<el-col :span="24" class="mb20">
<el-form-item label="门店详细地址" prop="detailAddress">
<el-input v-model="form.detailAddress" placeholder="请输入门店详细地址" type="textarea" :autosize="{ minRows: 2 }" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="visible = false">取消</el-button>
<el-button type="primary" @click="onSubmit" :disabled="loading">确认</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup lang="ts" name="MchPickUpDialog">
import { useMessage } from "/@/hooks/message";
import * as mchPickUpApi from '/@/api/wallet/mch-pick-up'
import BusinessHours from '/@/components/BusinessHours/index.vue'
// 定义营业时间接口
interface BusinessHour {
id: string
title: string
startTime: string
endTime: string
}
const emit = defineEmits(['refresh']);
// 定义变量内容
const dataFormRef = ref();
const visible = ref(false)
const loading = ref(false)
// 定义字典
// 提交表单数据
const form = reactive({
id: '',
name: '',
logo: '',
introduction: '',
phone: '',
status: '',
latitude: '',
longitude: '',
detailAddress: '',
businessHoursJson: [] as BusinessHour[],
mchIds: [],
});
// 定义校验规则
const dataRules = ref({
name: [{ required: true, message: "门店名称不能为空", trigger: "blur" }],
})
// 打开弹窗
const openDialog = (id: string) => {
visible.value = true
form.id = ''
// 重置表单数据
nextTick(() => {
dataFormRef.value?.resetFields();
});
// 重置营业时间数据
form.businessHoursJson = []
// 获取mchPickUp信息
if (id) {
form.id = id
getmchPickUpData(id)
}
};
// 提交
const onSubmit = async () => {
const valid = await dataFormRef.value.validate().catch(() => { });
if (!valid) return false;
try {
loading.value = true;
const _data: any = { ...form }
if (_data.businessHoursJson && _data.businessHoursJson.length) {
_data.businessHoursJson = JSON.stringify(_data.businessHoursJson)
}
form.id ? await mchPickUpApi.putObj(_data) : await mchPickUpApi.addObj(_data);
useMessage().success(form.id ? '修改成功' : '添加成功');
visible.value = false;
emit('refresh');
} catch (err: any) {
useMessage().error(err.msg);
} finally {
loading.value = false;
}
};
// 初始化表单数据
const getmchPickUpData = (id: string) => {
// 获取数据
loading.value = true
mchPickUpApi.getObj(id).then((res: any) => {
Object.assign(form, res.data)
if (res.data.businessHoursJson) {
try {
form.businessHoursJson = JSON.parse(res.data.businessHoursJson)
} catch (error) {
console.warn('解析营业时间JSON失败:', error)
form.businessHoursJson = []
}
}
}).finally(() => {
loading.value = false
})
};
// 暴露变量
defineExpose({
openDialog
});
</script>
+166
View File
@@ -0,0 +1,166 @@
<template>
<div class="layout-padding">
<div class="layout-padding-auto layout-padding-view">
<el-form v-if="showSearch" ref="queryRef" :inline="true" :model="state.queryForm" @keyup.enter="getDataList">
<el-row>
<el-form-item style="width: 250px" label="门店名称" prop="name">
<el-input v-model="state.queryForm.name" placeholder="请输入" />
</el-form-item>
<el-form-item style="width: 250px" label="门店联系手机号" prop="phone">
<el-input v-model="state.queryForm.phone" placeholder="请输入" />
</el-form-item>
<el-form-item style="width: 250px" label="合作状态" prop="visibleMobile">
<dict-select v-model="state.queryForm.status" dict-code="mch_pick_up_status_enum" />
</el-form-item>
<el-form-item>
<el-button icon="Search" type="primary" @click="getDataList">
{{ $t("common.queryBtn") }}
</el-button>
<el-button icon="Refresh" @click="resetQuery">{{ $t("common.resetBtn") }}</el-button>
</el-form-item>
</el-row>
</el-form>
<el-row>
<div class="mb8" style="width: 100%">
<el-button icon="folder-add" type="primary" class="ml10" @click="formDialogRef.openDialog()"
v-auth="'mch_mchPickUp_add'">
新 增
</el-button>
<el-button plain :disabled="multiple" icon="Delete" type="primary" v-auth="'mch_mchPickUp_del'"
@click="handleDelete(selectObjs)">
删除
</el-button>
<right-toolbar v-model:showSearch="showSearch" :export="'mch_mchPickUp_export'" @exportExcel="exportExcel"
class="ml10 mr20" style="float: right;" @queryTable="getDataList"></right-toolbar>
</div>
</el-row>
<el-table :data="state.dataList" v-loading="state.loading" border :cell-style="tableStyle.cellStyle"
:header-cell-style="tableStyle.headerCellStyle" @selection-change="selectionChangHandle"
@sort-change="sortChangeHandle">
<el-table-column type="selection" width="40" align="center" />
<el-table-column type="index" label="#" width="40" />
<el-table-column prop="name" label="门店名称" show-overflow-tooltip />
<el-table-column prop="logo" label="门店logo">
<template #default="{ row }">
<preview-image v-if="row.logo" :src="row.logo" />
<div style="width: 50px;height: 50px;" v-else />
</template>
</el-table-column>
<el-table-column prop="phone" label="门店手机" show-overflow-tooltip />
<el-table-column prop="status" label="门店状态" width="200">
<template #default="{ row }">
<el-switch active-value="20" inactive-value="10" active-text="正在合作" inactive-text="未合作" v-model="row.status"
@change="statusChange(row)" />
</template>
</el-table-column>
<el-table-column prop="detailAddress" label="门店详细地址" show-overflow-tooltip />
<el-table-column prop="businessHoursJson" label="营业时间">
<template #default="{ row }">
<div v-for="v in JSON.parse(row.businessHoursJson)" :key="v">
<span>{{ v.title }}</span>
<span>:</span>
<span>{{ v.startTime }}</span>
<span>-</span>
<span>{{ v.endTime }}</span>
</div>
</template>
</el-table-column>
<el-table-column label="操作" width="150">
<template #default="scope">
<el-button icon="edit-pen" text type="primary" v-auth="'mch_mchPickUp_edit'"
@click="formDialogRef.openDialog(scope.row.id)">编辑</el-button>
<el-button icon="delete" text type="primary" v-auth="'mch_mchPickUp_del'"
@click="handleDelete([scope.row.id])">删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination" />
</div>
<!-- 编辑、新增 -->
<form-dialog ref="formDialogRef" @refresh="getDataList(false)" />
</div>
</template>
<script setup lang="ts" name="systemMchPickUp">
import { BasicTableProps, useTable } from "/@/hooks/table";
import * as mchPickUpApi from '/@/api/wallet/mch-pick-up'
import { useMessage, useMessageBox } from "/@/hooks/message";
import { useDict } from '/@/hooks/dict';
// 引入组件
const FormDialog = defineAsyncComponent(() => import('./form.vue'));
// 定义查询字典
const { mch_pick_up_status_enum } = useDict("mch_pick_up_status_enum")
// 定义变量内容
const formDialogRef = ref()
// 搜索变量
const queryRef = ref()
const showSearch = ref(true)
// 多选变量
const selectObjs = ref([]) as any
const multiple = ref(true)
const state: BasicTableProps = reactive<BasicTableProps>({
queryForm: {},
pageList: mchPickUpApi.fetchList
})
// table hook
const {
getDataList,
currentChangeHandle,
sizeChangeHandle,
sortChangeHandle,
downBlobFile,
tableStyle
} = useTable(state)
// 清空搜索条件
const resetQuery = () => {
// 清空搜索条件
queryRef.value?.resetFields()
// 清空多选
selectObjs.value = []
getDataList()
}
// 导出excel
const exportExcel = () => {
downBlobFile('/mch/mch-pick-up/export', Object.assign(state.queryForm, { ids: selectObjs }), 'mchPickUp.xlsx')
}
// 多选事件
const selectionChangHandle = (objs: { id: string }[]) => {
selectObjs.value = objs.map(({ id }) => id);
multiple.value = !objs.length;
};
const statusChange = async (row: any) => {
try {
await mchPickUpApi.putObj(row)
getDataList()
useMessage().success("操作成功")
} catch (e) {
useMessage().error("操作错误")
}
}
// 删除操作
const handleDelete = async (ids: string[]) => {
try {
await useMessageBox().confirm('此操作将永久删除');
} catch {
return;
}
try {
await mchPickUpApi.delObjs(ids);
getDataList();
useMessage().success('删除成功');
} catch (err: any) {
useMessage().error(err.msg);
}
};
</script>
@@ -3,7 +3,7 @@
v-loading="state.loading">
<!-- **************************** start 喜爱菜品排行 start **************************** -->
<el-divider class="my-12">喜爱菜品排行配置</el-divider>
<el-form-item prop="cleaningData.carGap">
<el-form-item prop="nutritionSetting.carGap">
<template #label>
<div class="flex items-center gap-1">
<span>需要排除的菜品分类</span>
@@ -11,7 +11,36 @@
</template>
<select-ctcg v-model="form.nutritionSetting.topExcludeCategoryIds" multiple placeholder="请选择需要排除的菜品分类" />
</el-form-item>
<!-- **************************** end 同步间隔配置 end **************************** -->
<!-- **************************** end 喜爱菜品排行 end **************************** -->
<!-- **************************** start 营养分析 start **************************** -->
<el-divider class="my-12">营养分析配置</el-divider>
<el-form-item prop="nutritionSetting.hcCategoryIds">
<template #label>
<div class="flex items-center gap-1">
<span>荤菜菜品分类</span>
</div>
</template>
<select-ctcg v-model="form.nutritionSetting.hcCategoryIds" multiple placeholder="请选择荤菜菜品分类" />
</el-form-item>
<el-form-item prop="nutritionSetting.scCategoryIds">
<template #label>
<div class="flex items-center gap-1">
<span>素菜菜品分类</span>
</div>
</template>
<select-ctcg v-model="form.nutritionSetting.scCategoryIds" multiple placeholder="请选择素菜菜品分类" />
</el-form-item>
<el-form-item prop="nutritionSetting.zsCategoryIds">
<template #label>
<div class="flex items-center gap-1">
<span>主食菜品分类</span>
</div>
</template>
<select-ctcg v-model="form.nutritionSetting.zsCategoryIds" multiple placeholder="请选择主食菜品分类" />
</el-form-item>
<!-- **************************** end 营养分析 end **************************** -->
</el-form>
</template>
@@ -31,12 +60,21 @@ const form = reactive<any>({
nutritionSetting: {
// 喜爱菜品排行需要排除的菜品分类
topExcludeCategoryIds: [],
// 荤菜菜品分类
hcCategoryIds: [],
// 素菜菜品分类
scCategoryIds: [],
// 主食菜品分类
zsCategoryIds: [],
},
})
const dataRules = ref({
// 车辆考勤配置
"nutritionSetting.topExcludeCategoryIds": [{ required: true, message: '喜爱菜品排行需要排除的菜品分类不能为空', trigger: 'blur' }],
"nutritionSetting.hcCategoryIds": [{ required: true, message: '荤菜菜品分类不能为空', trigger: 'blur' }],
"nutritionSetting.scCategoryIds": [{ required: true, message: '素菜菜品分类不能为空', trigger: 'blur' }],
"nutritionSetting.zsCategoryIds": [{ required: true, message: '主食菜品分类不能为空', trigger: 'blur' }],
})
onMounted(() => {
@@ -50,6 +88,9 @@ async function getSetting() {
if (!data.nutritionSetting) {
data.nutritionSetting = {
topExcludeCategoryIds: [],
hcCategoryIds: [],
scCategoryIds: [],
zsCategoryIds: [],
}
}
if (data) {
+208
View File
@@ -0,0 +1,208 @@
<template>
<div class="test-jsonp-page">
<h2>JSONP 跨域测试页面</h2>
<div class="test-section">
<h3>1. 逆地址解析测试</h3>
<el-button @click="testReverseGeocode" type="primary">
测试逆地址解析 (北京天安门)
</el-button>
<div v-if="reverseResult" class="result">
<p><strong>结果:</strong> {{ reverseResult }}</p>
</div>
</div>
<div class="test-section">
<h3>2. 地址搜索测试</h3>
<el-input
v-model="searchKeyword"
placeholder="输入搜索关键词"
style="width: 300px; margin-right: 10px;"
/>
<el-button @click="testSearch" type="primary">搜索</el-button>
<div v-if="searchResults.length > 0" class="result">
<p><strong>搜索结果:</strong></p>
<ul>
<li v-for="(item, index) in searchResults" :key="index">
{{ item.title }} - {{ item.address }}
</li>
</ul>
</div>
</div>
<div class="test-section">
<h3>3. 地图选择器组件测试</h3>
<map-select
ref="mapSelectRef"
v-model="selectedLocation"
placeholder="点击选择位置"
style="width: 400px;"
/>
<div v-if="selectedLocation" class="result">
<p><strong>选中位置:</strong></p>
<p>地址: {{ selectedLocation.address }}</p>
<p>坐标: {{ selectedLocation.coordinates }}</p>
</div>
</div>
<div class="logs">
<h3>日志信息</h3>
<div class="log-content">
<div v-for="(log, index) in logs" :key="index" class="log-item">
{{ log }}
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { ElButton, ElInput, ElMessage } from 'element-plus'
import { TencentMapAPI } from '../utils/jsonp'
import MapSelect from '../components/map/map-select.vue'
// 创建腾讯地图API实例 (启用调试模式)
const mapAPI = new TencentMapAPI('CGABZ-3MH66-6VGST-MEMS3-K6U3V-DGBKA', true)
// 定义类型
interface LocationData {
address: string
coordinates: string
location: {
lat: number
lng: number
}
}
// 响应式数据
const reverseResult = ref('')
const searchKeyword = ref('北京大学')
const searchResults = ref<any[]>([])
const selectedLocation = ref<LocationData | null>(null)
const logs = ref<string[]>([])
// 添加日志
const addLog = (message: string) => {
const timestamp = new Date().toLocaleTimeString()
logs.value.unshift(`[${timestamp}] ${message}`)
if (logs.value.length > 10) {
logs.value.pop()
}
}
// 测试逆地址解析
const testReverseGeocode = async () => {
addLog('开始测试逆地址解析...')
try {
// 北京天安门坐标
const data = await mapAPI.reverseGeocode(39.908823, 116.397470)
if (data.status === 0) {
reverseResult.value = data.result.address
addLog(`逆地址解析成功: ${data.result.address}`)
ElMessage.success('逆地址解析成功')
} else {
addLog(`逆地址解析失败: ${data.message}`)
ElMessage.error('逆地址解析失败')
}
} catch (error) {
addLog(`逆地址解析错误: ${error}`)
ElMessage.error('逆地址解析错误')
console.error('逆地址解析错误:', error)
}
}
// 测试地址搜索
const testSearch = async () => {
if (!searchKeyword.value.trim()) {
ElMessage.warning('请输入搜索关键词')
return
}
addLog(`开始搜索: ${searchKeyword.value}`)
try {
const data = await mapAPI.searchLocation(searchKeyword.value)
if (data.status === 0) {
searchResults.value = data.data.map((item: any) => ({
title: item.title,
address: item.address,
location: item.location
}))
addLog(`搜索成功,找到 ${searchResults.value.length} 个结果`)
ElMessage.success(`搜索成功,找到 ${searchResults.value.length} 个结果`)
} else {
addLog(`搜索失败: ${data.message}`)
ElMessage.error('搜索失败')
}
} catch (error) {
addLog(`搜索错误: ${error}`)
ElMessage.error('搜索错误')
console.error('搜索错误:', error)
}
}
</script>
<style scoped>
.test-jsonp-page {
padding: 20px;
max-width: 800px;
margin: 0 auto;
}
.test-section {
margin-bottom: 30px;
padding: 20px;
border: 1px solid #e4e7ed;
border-radius: 8px;
background-color: #fafafa;
}
.test-section h3 {
margin-top: 0;
color: #409eff;
}
.result {
margin-top: 15px;
padding: 10px;
background-color: #f0f9ff;
border: 1px solid #b3d8ff;
border-radius: 4px;
}
.result ul {
margin: 5px 0;
padding-left: 20px;
}
.logs {
margin-top: 30px;
padding: 20px;
border: 1px solid #e4e7ed;
border-radius: 8px;
background-color: #f8f9fa;
}
.logs h3 {
margin-top: 0;
color: #67c23a;
}
.log-content {
max-height: 200px;
overflow-y: auto;
font-family: 'Courier New', monospace;
font-size: 12px;
}
.log-item {
padding: 2px 0;
border-bottom: 1px solid #eee;
}
.log-item:last-child {
border-bottom: none;
}
</style>