feat:自提点

This commit is contained in:
dzc committed 2025-10-16 16:56:35 +08:00
1 parent 8dba6a0894
commit cf8aa56c9c
13 files changed
+1767 -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,
})
}
+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)
+486
View File
@@ -0,0 +1,486 @@
<template>
<el-dialog v-model="state.visibleMapDialog" title="地图位置选择器" width="80%" :before-close="handleClose"
class="map-picker-dialog">
<div class="map-picker-container">
<!-- 搜索栏 -->
<div class="search-bar">
<el-input v-model="state.searchKeyword" placeholder="请输入地址或POI名称进行搜索" class="search-input"
@keyup.enter="handleSearch">
<template #append>
<el-button @click="handleSearch" :loading="state.searching">
<el-icon>
<Search />
</el-icon>
</el-button>
</template>
</el-input>
</div>
<!-- 地图容器 -->
<div class="map-container">
<tmap-map ref="mapRef" style="width: 100%; height: 500px;" mapKey="CGABZ-3MH66-6VGST-MEMS3-K6U3V-DGBKA"
:center="map.center" :zoom="map.zoom" :doubleClickZoom="map.doubleClickZoom"
@click="handleMapClick">
<!-- 标记点 -->
<tmap-marker v-if="state.selectedLocation" :position="state.selectedLocation" :draggable="true"
@dragend="handleMarkerDragEnd" />
</tmap-map>
<!-- 地图中心十字标 -->
<div class="map-crosshair">
<div class="crosshair-horizontal"></div>
<div class="crosshair-vertical"></div>
</div>
</div>
<!-- 信息面板 -->
<div class="info-panel">
<div class="location-info">
<div class="info-row">
<span class="label">选中地址:</span>
<span class="value">{{ state.selectedAddress || '请在地图上点击选择位置' }}</span>
</div>
<div class="info-row">
<span class="label">经纬度:</span>
<span class="value">
{{ state.selectedLocation ? `${state.selectedLocation.lng}, ${state.selectedLocation.lat}` :
'未选择' }}
</span>
</div>
</div>
<!-- 搜索结果列表 -->
<div v-if="state.searchResults.length > 0" class="search-results">
<div class="results-title">搜索结果</div>
<div class="results-list">
<div v-for="(item, index) in state.searchResults" :key="index" class="result-item"
@click="selectSearchResult(item)">
<div class="result-title">{{ item.title }}</div>
<div class="result-address">{{ item.address }}</div>
</div>
</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, onMounted, nextTick } from 'vue'
import { ElMessage } from 'element-plus'
import { Search } from '@element-plus/icons-vue'
import { TencentMapAPI } from '../../utils/jsonp'
// 定义事件
const emit = defineEmits(['confirm', 'close'])
// 响应式状态
const state = reactive<any>({
visibleMapDialog: false,
searchKeyword: '',
searching: false,
selectedLocation: null,
selectedAddress: '',
searchResults: []
})
// 地图配置
const map = reactive<any>({
// 默认县府
center: { lat: 29.453297, lng: 119.89259 },
zoom: 15,
doubleClickZoom: true,
})
// 地图引用
const mapRef = ref()
// 腾讯地图API密钥 <mcreference link="https://lbs.qq.com/getPoint/#J" index="0">0</mcreference>
const TENCENT_MAP_KEY = "4INBZ-UIUCZ-ILHXD-7P2GM-6C2LZ-S7BNI"
// 创建腾讯地图API实例 (启用调试模式)
const mapAPI = new TencentMapAPI(TENCENT_MAP_KEY, true)
onMounted(() => {
// 初始化地图相关功能
})
// 打开对话框
const open = (initialLocation?: any) => {
state.visibleMapDialog = true
resetState()
// 如果有初始位置,设置为当前选中位置
if (initialLocation) {
state.selectedLocation = { ...initialLocation }
map.center = initialLocation
state.selectedAddress = '正在获取地址...'
reverseGeocode(initialLocation)
}
// 等待DOM更新后初始化地图
nextTick(() => {
initMap(initialLocation)
})
}
// 关闭对话框
const handleClose = () => {
state.visibleMapDialog = false
resetState()
emit('close')
}
// 重置状态
const resetState = () => {
state.searchKeyword = ''
state.searching = false
state.selectedLocation = null
state.selectedAddress = ''
state.searchResults = []
}
// 地图点击事件
const handleMapClick = (event: any) => {
const { lat, lng } = event.latLng
state.selectedLocation = { lat, lng }
// 逆地址解析
reverseGeocode({ lat, lng })
}
// 标记拖拽结束事件
const handleMarkerDragEnd = (event: any) => {
const { lat, lng } = event.latLng
state.selectedLocation = { lat, lng }
// 逆地址解析
reverseGeocode({ lat, lng })
}
// 搜索地址
const handleSearch = async () => {
if (!state.searchKeyword.trim()) {
ElMessage.warning('请输入搜索关键词')
return
}
state.searching = true
try {
const results = await searchLocation(state.searchKeyword)
state.searchResults = results
if (results.length === 0) {
ElMessage.info('未找到相关地址')
}
} catch (error) {
console.error('搜索失败:', error)
ElMessage.error('搜索失败,请重试')
} finally {
state.searching = false
}
}
// 选择搜索结果
const selectSearchResult = (item: any) => {
state.selectedLocation = { lat: item.location.lat, lng: item.location.lng }
state.selectedAddress = item.address
map.center = state.selectedLocation
// 清空搜索结果
state.searchResults = []
state.searchKeyword = item.title
}
// 确认选择
const handleConfirm = () => {
if (!state.selectedLocation) {
ElMessage.warning('请先选择一个位置')
return
}
const result = {
location: state.selectedLocation,
address: state.selectedAddress,
coordinates: `${state.selectedLocation.lng},${state.selectedLocation.lat}`
}
emit('confirm', result)
handleClose()
}
// 逆地址解析
const reverseGeocode = async (location: { lat: number, lng: number }) => {
try {
const data = await mapAPI.reverseGeocode(location.lat, location.lng)
if (data.status === 0) {
state.selectedAddress = data.result.address
} else {
console.error('逆地址解析失败:', data.message)
state.selectedAddress = `纬度:${location.lat}, 经度:${location.lng}`
}
} catch (error) {
console.error('逆地址解析错误:', error)
state.selectedAddress = `纬度:${location.lat}, 经度:${location.lng}`
}
}
// 地址搜索
const searchLocation = async (keyword: string) => {
try {
const data = await mapAPI.searchLocation(keyword)
if (data.status === 0) {
return data.data.map((item: any) => ({
title: item.title,
address: item.address,
location: item.location
}))
} else {
console.error('地址搜索失败:', data.message)
return []
}
} catch (error) {
console.error('地址搜索错误:', error)
return []
}
}
// 初始化地图
const initMap = (initialLocation?: any) => {
// 这里应该初始化腾讯地图
// 由于需要腾讯地图SDK,这里提供一个基础的实现框架
console.log('初始化地图', initialLocation)
// 如果有初始位置,设置地图中心
if (initialLocation) {
// 设置地图中心到初始位置
// map.setCenter(new TMap.LatLng(initialLocation.lat, initialLocation.lng))
}
}
// 暴露方法
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;
}
.map-crosshair {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
pointer-events: none;
z-index: 1000;
}
.crosshair-horizontal,
.crosshair-vertical {
position: absolute;
background: #ff4757;
}
.crosshair-horizontal {
width: 20px;
height: 2px;
top: -1px;
left: -10px;
}
.crosshair-vertical {
width: 2px;
height: 20px;
top: -10px;
left: -1px;
}
.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
+148
View File
@@ -0,0 +1,148 @@
<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">
<el-input v-model="form.businessHoursJson" placeholder="请输入营业时间" />
</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 { useDict } from '/@/hooks/dict';
import { useMessage } from "/@/hooks/message";
import * as mchPickUpApi from '/@/api/wallet/mch-pick-up'
import { rule } from '/@/utils/validate';
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: '',
mchIds: [],
});
// 定义校验规则
const dataRules = ref({
name: [{ required: true, message: "门店名称不能为空", trigger: "blur" }],
})
// 打开弹窗
const openDialog = (id: string) => {
visible.value = true
form.id = ''
// 重置表单数据
nextTick(() => {
dataFormRef.value?.resetFields();
});
// 获取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;
form.id ? await mchPickUpApi.putObj(form) : await mchPickUpApi.addObj(form);
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)
}).finally(() => {
loading.value = false
})
};
// 暴露变量
defineExpose({
openDialog
});
</script>
+156
View File
@@ -0,0 +1,156 @@
<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="营业时间" show-overflow-tooltip />
<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>