From 6fc521b8bdcf2d42800133e5ca49b6c3c3bc3d0e Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Tue, 21 Oct 2025 16:44:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=94=AF=E4=BB=98=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/DictSelect/index.vue | 4 +- src/utils/jsonp.ts | 57 +------- src/views/hard/hard-order/index.vue | 4 + src/views/test-jsonp.vue | 208 ---------------------------- 4 files changed, 14 insertions(+), 259 deletions(-) delete mode 100644 src/views/test-jsonp.vue diff --git a/src/components/DictSelect/index.vue b/src/components/DictSelect/index.vue index 6433532..9711e8a 100644 --- a/src/components/DictSelect/index.vue +++ b/src/components/DictSelect/index.vue @@ -1,6 +1,6 @@ e && getDictOptions()"> + :multiple="props.multiple" @visible-change="(e: boolean) => e && getDictOptions()"> @@ -16,9 +16,11 @@ export type Props = { dictCode: string placeholder?: string hideIds?: string | Array + multiple?: boolean } const props = withDefaults(defineProps(), { placeholder: "请选择", + multiple: false, }) const state = reactive({ diff --git a/src/utils/jsonp.ts b/src/utils/jsonp.ts index bcd3676..d1b6420 100644 --- a/src/utils/jsonp.ts +++ b/src/utils/jsonp.ts @@ -7,7 +7,6 @@ interface JsonpOptions { timeout?: number callbackName?: string callbackParam?: string - debug?: boolean } /** @@ -18,17 +17,11 @@ interface JsonpOptions { */ export function jsonp(url: string, options: JsonpOptions = {}): Promise { const { - timeout = 15000, + timeout = 10000, 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") @@ -36,11 +29,7 @@ export function jsonp(url: string, options: JsonpOptions = {}): Promise { // 设置超时 const timer = setTimeout(() => { cleanup() - const error = new Error(`JSONP request timeout after ${timeout}ms`) - if (debug) { - console.error('[JSONP] 请求超时:', error) - } - reject(error) + reject(new Error("JSONP request timeout")) }, timeout) // 清理函数 @@ -56,34 +45,22 @@ export function jsonp(url: string, options: JsonpOptions = {}): Promise { // 设置全局回调函数 ;(window as any)[callbackName] = (data: any) => { - if (debug) { - console.log('[JSONP] 收到响应:', data) - } cleanup() resolve(data) } // 处理错误 - script.onerror = (event) => { + script.onerror = () => { cleanup() - const error = new Error("JSONP request failed to load script") - if (debug) { - console.error('[JSONP] 脚本加载失败:', event) - } - reject(error) + reject(new Error("JSONP request failed")) } // 构建请求 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) }) } @@ -93,11 +70,9 @@ export function jsonp(url: string, options: JsonpOptions = {}): Promise { */ export class TencentMapAPI { private apiKey: string - private debug: boolean - constructor(apiKey: string, debug: boolean = false) { + constructor(apiKey: string) { this.apiKey = apiKey - this.debug = debug } /** @@ -109,17 +84,8 @@ export class TencentMapAPI { async reverseGeocode(lat: number, lng: number): Promise { 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) - } - + const data = await jsonp(url) return data } catch (error) { console.error("逆地址解析失败:", error) @@ -138,17 +104,8 @@ export class TencentMapAPI { 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) - } - + const data = await jsonp(url) return data } catch (error) { console.error("地址搜索失败:", error) diff --git a/src/views/hard/hard-order/index.vue b/src/views/hard/hard-order/index.vue index 930c02f..746ce9b 100644 --- a/src/views/hard/hard-order/index.vue +++ b/src/views/hard/hard-order/index.vue @@ -30,6 +30,10 @@ + + + diff --git a/src/views/test-jsonp.vue b/src/views/test-jsonp.vue deleted file mode 100644 index 997254d..0000000 --- a/src/views/test-jsonp.vue +++ /dev/null @@ -1,208 +0,0 @@ - - - JSONP 跨域测试页面 - - - 1. 逆地址解析测试 - - 测试逆地址解析 (北京天安门) - - - 结果: {{ reverseResult }} - - - - - 2. 地址搜索测试 - - 搜索 - - 搜索结果: - - - {{ item.title }} - {{ item.address }} - - - - - - - 3. 地图选择器组件测试 - - - 选中位置: - 地址: {{ selectedLocation.address }} - 坐标: {{ selectedLocation.coordinates }} - - - - - 日志信息 - - - {{ log }} - - - - - - - - - \ No newline at end of file
结果: {{ reverseResult }}
搜索结果:
选中位置:
地址: {{ selectedLocation.address }}
坐标: {{ selectedLocation.coordinates }}