From 769ce650f20a584e7565ef55814ae6add482c2d0 Mon Sep 17 00:00:00 2001 From: phm1551 <52021264+phm1551@users.noreply.github.com> Date: Sat, 27 Jun 2026 18:30:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- .htaccess | 8 + README.en.md | 36 ++++ README.md | 35 ++-- ...vite.config.ts.timestamp-1779333463627.mjs | 34 ++++ nginx.htaccess | 0 niucloud/.env | 2 +- niucloud/config/version.php | 4 +- niucloud/public/.gitignore | 5 +- niucloud/public/.htaccess | 16 +- niucloud/public/admin/index.html | 2 +- niucloud/public/nginx.htaccess | 2 +- niucloud/public/tianmap/index.html | 6 +- niucloud/public/wap/index.html | 2 +- uni-app/.env.development | 2 +- .../src/addon/components/diy/group/index.vue | 1 - uni-app/src/app/pages/member/address_edit.vue | 39 +++- .../components/share-poster/share-poster.vue | 10 +- uni-app/src/hooks/useLocation.ts | 187 ++++++++++++++---- uni-app/src/pages.json | 1 + uni-app/src/stores/system.ts | 2 +- uni-app/src/utils/common.ts | 11 +- 22 files changed, 318 insertions(+), 89 deletions(-) create mode 100644 .htaccess create mode 100644 README.en.md create mode 100644 admin/vite.config.ts.timestamp-1779333463627.mjs create mode 100644 nginx.htaccess diff --git a/.gitignore b/.gitignore index 14a6efb53..ad4ad41b3 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,5 @@ bin-release/ # information for Eclipse / Flash Builder. /.idea +/upgrade niucloud/public/.htaccess -admin/.env.development diff --git a/.htaccess b/.htaccess new file mode 100644 index 000000000..791800521 --- /dev/null +++ b/.htaccess @@ -0,0 +1,8 @@ + + Options +FollowSymlinks -Multiviews + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L] + RewriteEngine on RewriteCond % !^$ + \ No newline at end of file diff --git a/README.en.md b/README.en.md new file mode 100644 index 000000000..97b8330d3 --- /dev/null +++ b/README.en.md @@ -0,0 +1,36 @@ +# niucloud-admin + +#### Description +{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} + +#### Software Architecture +Software architecture description + +#### Installation + +1. xxxx +2. xxxx +3. xxxx + +#### Instructions + +1. xxxx +2. xxxx +3. xxxx + +#### Contribution + +1. Fork the repository +2. Create Feat_xxx branch +3. Commit your code +4. Create Pull Request + + +#### Gitee Feature + +1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md +2. Gitee blog [blog.gitee.com](https://blog.gitee.com) +3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) +4. The most valuable open source project [GVP](https://gitee.com/gvp) +5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) +6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md index 04d9bcf8a..1b17e6803 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -![输入图片说明](https://media.niucloud.com/1712133019020249f332e83457a01a6799472e0495_aliyun.png) +![输入图片说明](https://www.niucloud.com/img/readme/%E9%A1%B6%E9%83%A8%E5%B9%BF%E5%91%8A1.jpg) -### niucloud-admin是什么? +### niucloud-admin是什么? niucloud-admin是一款快速开发通用管理后台框架,前端采用最新的技术栈Vite+TypeScript+Vue3+ElementPlus最流行技术架构,后台结合PHP8、Java SDK、Python等主流后端语言搭建,内置集成用户权限、代码生成器、表单设计、云存储、短信发送、素材中心、微信及公众号、Api模块一系列开箱即用功能,是一款快速可以开发企业级应用的软件系统。 -### niucloud-admin采用的技术亮点 +### niucloud-admin采用的技术亮点 -- 后台php采用thinkphp8+php8+mysql,支持composer快速安装扩展,支持redis缓存以及消息队列,支持多语言设计开发,同时开发采用严格的restful的api设计开发。 +- 后台php采用thinkphp8+php8+mysql,支持composer快速安装扩展,支持redis缓存以及消息队列,支持多语言设计开发,同时开发采用严格的restful的api设计开发。 - 后台前后端分离采用element-plus、vue3.0、typescript、vite、pina等前端技术,同时使用i18n支持国际化多语言开发。 @@ -32,25 +32,20 @@ niucloud-admin是一款快速开发通用管理后台框架,前端采用最新 ### 操作指南 [官网地址](https://www.niucloud.com) | [服务市场](https://www.niucloud.com) - | [使用手册](https://www.niucloud.com/doc) - | [二开手册](https://www.niucloud.com/doc) - | [开发视频](https://www.niucloud.com/doc) - | [API接口手册](https://api.niucloud.com/apidoc.html?target_id=001) - | [论坛地址](https://niucloud.com/bbs) + | [使用手册](https://www.kancloud.cn/niucloud/niucloud-admin-develop/3153336) + | [二开手册](https://www.kancloud.cn/niucloud/niucloud-admin-develop/3153336) + | [API接口手册](https://www.niucloud.com/apidoc.html) + | [论坛地址](https://www.niucloud.com/bbs) ### 演示地址 -- 管理后台演示网址:[ 查看 ] -https://v6.site.niucloud.com/admin 账号:admin 密码:123456 - -- web端演示网址:[ 查看 ] -https://v6.site.niucloud.com 账号:admin 密码:123456 - +- 管理后台演示网址:[ 查看 ] +http://v6.site.niucloud.com 账号:admin 密码:123456 - H5前端演示网址:[ 查看 ] https://v6.site.niucloud.com/wap/ 账号:admin 密码:123456 -### 开源使用须知 +### 开源使用须知 -1.允许用于个人学习、毕业设计、教学案例、公益事业、商业使用; +1.允许用于个人学习、毕业设计、教学案例、公益事业、商业使用; 2.本框架应用源代码所有权和著作权归niucloud官方所有,基于niucloud-admin框架开发的应用,所有权和著作权归应用开发商所有。但必须明确声明是基于niucloud-admin框架开发,请自觉遵守,否则产生的一切任何后果责任由侵权者自负; @@ -62,12 +57,14 @@ niucloud-admin是一款快速开发通用管理后台框架,前端采用最新 6.一切事物有个人喜好的标准,本开源代码意在分享,不喜勿喷。 + + ### 版权信息 版权所有Copyright © 2015-2030 niucloud-admin 版权所有 All rights reserved。 - 杭州数字云动科技有限公司 杭州牛之云科技有限公司 -提供技术支持 \ No newline at end of file + +提供技术支持 \ No newline at end of file diff --git a/admin/vite.config.ts.timestamp-1779333463627.mjs b/admin/vite.config.ts.timestamp-1779333463627.mjs new file mode 100644 index 000000000..8319b613d --- /dev/null +++ b/admin/vite.config.ts.timestamp-1779333463627.mjs @@ -0,0 +1,34 @@ +// vite.config.ts +import { fileURLToPath, URL } from "node:url"; +import { defineConfig } from "file:///G:/www/niucloud-admin-niushop-v6/admin/node_modules/vite/dist/node/index.js"; +import vue from "file:///G:/www/niucloud-admin-niushop-v6/admin/node_modules/@vitejs/plugin-vue/dist/index.mjs"; +import AutoImport from "file:///G:/www/niucloud-admin-niushop-v6/admin/node_modules/unplugin-auto-import/dist/vite.js"; +import Components from "file:///G:/www/niucloud-admin-niushop-v6/admin/node_modules/unplugin-vue-components/dist/vite.mjs"; +import { ElementPlusResolver } from "file:///G:/www/niucloud-admin-niushop-v6/admin/node_modules/unplugin-vue-components/dist/resolvers.mjs"; +var __vite_injected_original_import_meta_url = "file:///G:/www/niucloud-admin-niushop-v6/admin/vite.config.ts"; +var vite_config_default = defineConfig({ + base: "", + server: { + host: "0.0.0.0" + }, + plugins: [ + vue(), + AutoImport({ + resolvers: [ElementPlusResolver()] + }), + Components({ + resolvers: [ElementPlusResolver()] + }) + ], + resolve: { + alias: { + "@": fileURLToPath(new URL("./src", __vite_injected_original_import_meta_url)), + "assets": fileURLToPath(new URL("./src/assets", __vite_injected_original_import_meta_url)), + "vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js" + } + } +}); +export { + vite_config_default as default +}; +//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9kaXJuYW1lID0gXCJHOlxcXFx3d3dcXFxcbml1Y2xvdWQtYWRtaW4tbml1c2hvcC12NlxcXFxhZG1pblwiO2NvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9maWxlb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UsQ0FBQztBQUFBLE1BQ3BELFVBQVUsY0FBYyxJQUFJLElBQUksZ0JBQWdCLHdDQUFlLENBQUM7QUFBQSxNQUNoRSxZQUFZO0FBQUEsSUFDaEI7QUFBQSxFQUNKO0FBQ0osQ0FBQzsiLAogICJuYW1lcyI6IFtdCn0K diff --git a/nginx.htaccess b/nginx.htaccess new file mode 100644 index 000000000..e69de29bb diff --git a/niucloud/.env b/niucloud/.env index add44e4f6..f09beb0ed 100644 --- a/niucloud/.env +++ b/niucloud/.env @@ -1 +1 @@ -APP_DEBUG = true [APP] DEFAULT_TIMEZONE = Asia/Shanghai AUTH_KEY = {auth_key} PRODUCT_KEY = {product_key} [DATABASE] TYPE = mysql HOSTNAME = {dbhost} DATABASE = {dbname} USERNAME = {dbuser} PASSWORD = {dbpwd} HOSTPORT = {dbport} PREFIX = {dbprefix} CHARSET = utf8mb4 DEBUG = false [REDIS] REDIS_HOSTNAME = 127.0.0.1 PORT = 6379 REDIS_PASSWORD = SELECT = 0 [QUEUE] state = false [LANG] default_lang = zh-cn [SYSTEM] ADMIN_TOKEN_NAME = token API_TOKEN_NAME = token ADMIN_TOKEN_EXPIRE_TIME = 604800 API_TOKEN_EXPIRE_TIME = 2592000 LANG_NAME = lang CHANNEL_NAME = channel ADMIN_DOMAIN = WAP_DOMAIN = WEB_DOMAIN = [NIUCLOUD] code = secret = \ No newline at end of file +APP_DEBUG = false [APP] DEFAULT_TIMEZONE = Asia/Shanghai AUTH_KEY = {auth_key} PRODUCT_KEY = {product_key} [DATABASE] TYPE = mysql HOSTNAME = {dbhost} DATABASE = {dbname} USERNAME = {dbuser} PASSWORD = {dbpwd} HOSTPORT = {dbport} PREFIX = {dbprefix} CHARSET = utf8mb4 DEBUG = false [REDIS] REDIS_HOSTNAME = 127.0.0.1 PORT = 6379 REDIS_PASSWORD = SELECT = 0 [QUEUE] state = false [LANG] default_lang = zh-cn [SYSTEM] ADMIN_TOKEN_NAME = token API_TOKEN_NAME = token ADMIN_TOKEN_EXPIRE_TIME = 604800 API_TOKEN_EXPIRE_TIME = 2592000 LANG_NAME = lang CHANNEL_NAME = channel ADMIN_DOMAIN = WAP_DOMAIN = WEB_DOMAIN = [NIUCLOUD] code = secret = \ No newline at end of file diff --git a/niucloud/config/version.php b/niucloud/config/version.php index dfeb89484..5399eb566 100644 --- a/niucloud/config/version.php +++ b/niucloud/config/version.php @@ -1,5 +1,5 @@ '1.6.2', - 'code' => '202606060001' + 'version' => '1.6.3', + 'code' => '202606270001' ]; \ No newline at end of file diff --git a/niucloud/public/.gitignore b/niucloud/public/.gitignore index 8b0144799..3e02c68c3 100644 --- a/niucloud/public/.gitignore +++ b/niucloud/public/.gitignore @@ -1,4 +1,7 @@ /.htaccess upload nginx.htaccess -.htaccess \ No newline at end of file +.htaccess +admin +wap +web diff --git a/niucloud/public/.htaccess b/niucloud/public/.htaccess index 81fe165fe..791800521 100644 --- a/niucloud/public/.htaccess +++ b/niucloud/public/.htaccess @@ -1,8 +1,8 @@ - - Options +FollowSymlinks -Multiviews - RewriteEngine On - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L] - RewriteEngine on RewriteCond % !^$ - + + Options +FollowSymlinks -Multiviews + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L] + RewriteEngine on RewriteCond % !^$ + \ No newline at end of file diff --git a/niucloud/public/admin/index.html b/niucloud/public/admin/index.html index 0a64cc5ec..dde0d47c9 100644 --- a/niucloud/public/admin/index.html +++ b/niucloud/public/admin/index.html @@ -5,7 +5,7 @@ - + diff --git a/niucloud/public/nginx.htaccess b/niucloud/public/nginx.htaccess index f5a712939..16ac67c4a 100644 --- a/niucloud/public/nginx.htaccess +++ b/niucloud/public/nginx.htaccess @@ -1,4 +1,4 @@ -location /{ +location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php/$1 last; break; } diff --git a/niucloud/public/tianmap/index.html b/niucloud/public/tianmap/index.html index c0d86c65c..7b410d530 100644 --- a/niucloud/public/tianmap/index.html +++ b/niucloud/public/tianmap/index.html @@ -870,9 +870,13 @@ window.postMessage({ type: 'tianmap:select', data: payload }, '*'); // alert('已选择坐标:' + selectedLongitude.toFixed(6) + ',' + selectedLatitude.toFixed(6)); } + + document.addEventListener('DOMContentLoaded', function() { + setTimeout(onLoad, 100); + }); - +
diff --git a/niucloud/public/wap/index.html b/niucloud/public/wap/index.html index 32d512117..d65ea37bc 100644 --- a/niucloud/public/wap/index.html +++ b/niucloud/public/wap/index.html @@ -14,7 +14,7 @@ - + diff --git a/uni-app/.env.development b/uni-app/.env.development index c91d54be7..2cb61c2cb 100644 --- a/uni-app/.env.development +++ b/uni-app/.env.development @@ -16,4 +16,4 @@ VITE_REQUEST_HEADER_TOKEN_KEY='token' VITE_REQUEST_HEADER_CHANNEL_KEY='channel' # 应用版本 -VITE_APP_VERSION='1.0.1' \ No newline at end of file +VITE_APP_VERSION='1.0.1' diff --git a/uni-app/src/addon/components/diy/group/index.vue b/uni-app/src/addon/components/diy/group/index.vue index 79184057a..a3463d13c 100644 --- a/uni-app/src/addon/components/diy/group/index.vue +++ b/uni-app/src/addon/components/diy/group/index.vue @@ -123,7 +123,6 @@ - diff --git a/uni-app/src/app/pages/member/address_edit.vue b/uni-app/src/app/pages/member/address_edit.vue index ceba0c4f6..abe241cfe 100644 --- a/uni-app/src/app/pages/member/address_edit.vue +++ b/uni-app/src/app/pages/member/address_edit.vue @@ -85,6 +85,8 @@ import useSystemStore from '@/stores/system'; import { useLocation } from '@/hooks/useLocation' const systemStore = useSystemStore(); +const { refresh: refreshLocation } = useLocation(true); + const formData: any = ref({ id: 0, name: '', @@ -111,6 +113,7 @@ const isSelectMap = ref(2) // 值为1,该地址需要有经纬度,反之不 const wxPrivacyPopupRef: any = ref(null) onLoad((data: any) => { + refreshLocation(); isSelectMap.value = data.isSelectMap || ''; const selectAddress = uni.getStorageSync('selectAddressCallback') if (data.id) { @@ -260,8 +263,12 @@ const save = () => { // 选择地址 const chooseLocation = () => { - let latitude = systemStore.diyAddressInfo ? systemStore.diyAddressInfo.latitude : ''; - let longitude = systemStore.diyAddressInfo ? systemStore.diyAddressInfo.longitude : ''; + // 安全取值,空对象时直接返回空字符串 + const latitude = systemStore.diyAddressInfo?.latitude ?? '' + const longitude = systemStore.diyAddressInfo?.longitude ?? '' + + // let latitude = systemStore.diyAddressInfo ? systemStore.diyAddressInfo.latitude : ''; + // let longitude = systemStore.diyAddressInfo ? systemStore.diyAddressInfo.longitude : ''; // #ifndef H5 uni.chooseLocation({ @@ -276,6 +283,12 @@ const chooseLocation = () => { if (res.latitude && res.longitude) { let latng = res.latitude + ',' + res.longitude; getAddress(latng); + // 关键:选完地址后,存入仓库 + 本地缓存 + systemStore.setAddressInfo({ + latitude: res.latitude, + longitude: res.longitude, + address: res.address + }) } }, fail: (res) => { @@ -283,12 +296,15 @@ const chooseLocation = () => { if (res.errMsg && res.errno) { if (res.errno == 104) { let msg = '用户未授权隐私权限,选择位置失败'; - uni.showToast({ title: msg, icon: 'none' }) + // uni.showToast({ title: msg, icon: 'none' }) + console.log(msg) } else if (res.errno == 112) { let msg = '隐私协议中未声明,打开地图选择位置失败'; - uni.showToast({ title: msg, icon: 'none' }) + // uni.showToast({ title: msg, icon: 'none' }) + console.log(msg) } else { - uni.showToast({ title: res.errMsg, icon: 'none' }) + // uni.showToast({ title: res.errMsg, icon: 'none' }) + console.log(res.errMsg) } } } @@ -385,7 +401,7 @@ const choosegAddress = () =>{ // 匹配市id(基于省id) formData.value.city_id = findIdByNameAndParentId(areaTree.value, res.cityName, formData.value.province_id); // 匹配区id(基于市id) - formData.value.district_id = findIdByNameAndParentId(areaTree.value, res.countyName, formData.value.cityId); + formData.value.district_id = findIdByNameAndParentId(areaTree.value, res.countyName, formData.value.city_id); }, fail(err) { loadingchoosegAddress.value = false @@ -393,7 +409,14 @@ const choosegAddress = () =>{ }); } -onMounted(()=>{ +onMounted(async ()=>{ + // 读取本地缓存的历史定位地址 + const cacheLocation = uni.getStorageSync('location_address') + if(cacheLocation && Object.keys(cacheLocation).length) { + // 调用仓库方法,把缓存塞进去 + systemStore.setAddressInfo(cacheLocation) + } + // #ifdef MP uni.authorize({ scope: 'scope.userLocation', @@ -410,7 +433,7 @@ onMounted(()=>{ success: (settingRes) => { if (settingRes.authSetting['scope.userLocation']) { const locationVal = useLocation(true); - locationVal.init(); + locationVal.refresh(); } } }); diff --git a/uni-app/src/components/share-poster/share-poster.vue b/uni-app/src/components/share-poster/share-poster.vue index 46210e458..d6ab89dd1 100644 --- a/uni-app/src/components/share-poster/share-poster.vue +++ b/uni-app/src/components/share-poster/share-poster.vue @@ -205,15 +205,19 @@ const savePoster = () => { fail: (err) => { if (err.errno == 104) { let msg = '用户未授权隐私权限,将图像保存到相册失败'; - uni.showToast({ title: msg, icon: 'none' }) + // uni.showToast({ title: msg, icon: 'none' }) + console.log(msg) } else if (err.errMsg == "saveImageToPhotosAlbum:fail auth deny" || err.errMsg == "saveImageToPhotosAlbum:fail:auth denied") { show.value = true; + console.log(err.errMsg) } else if (err.errMsg == "saveImageToPhotosAlbum:fail cancel") { let msg = '用户取消将图片保存到相册'; - uni.showToast({ title: msg, icon: 'none' }) + // uni.showToast({ title: msg, icon: 'none' }) + console.log(msg) } else { - uni.showToast({ title: err.errMsg, icon: 'none' }) + // uni.showToast({ title: err.errMsg, icon: 'none' }) + console.log(err.errMsg) } } }); diff --git a/uni-app/src/hooks/useLocation.ts b/uni-app/src/hooks/useLocation.ts index 632cf27ab..b5f6f2e76 100644 --- a/uni-app/src/hooks/useLocation.ts +++ b/uni-app/src/hooks/useLocation.ts @@ -4,6 +4,10 @@ import { getAddressByLatlng } from '@/app/api/system'; import wechat from '@/utils/wechat' import useSystemStore from '@/stores/system'; +// 单例定位服务 +// 使用全局 Promise 确保整个应用中只有一个定位请求在执行 +let locationPromise: Promise | null = null; + export function useLocation(isOpenLocation: any) { const systemStore = useSystemStore(); @@ -13,6 +17,80 @@ export function useLocation(isOpenLocation: any) { isOpen = false; } + const init = () => { + if (!isOpen) return false; + + // 使用 locationPromise 作为唯一的锁源 + if (locationPromise) { + return; + } + + // 立即设置空 Promise 作为锁 + locationPromise = new Promise(() => {}); + + // 排除手动地图选择位置的情况 + if (!uni.getStorageSync('manually_select_location_from_map')) { + // #ifdef H5 + if (isWeixinBrowser() && systemStore.mapConfig.is_open && !uni.getStorageSync('location_address')) { + wechat.init(() => { + wechat.getLocation(res => { + locationPromise = null; + let latlng = res.latitude + ',' + res.longitude; + getAddressByLatlngFn(latlng); + }); + }); + } else { + locationPromise = null; + } + // #endif + + // #ifndef H5 + if (systemStore.mapConfig.is_open && !uni.getStorageSync('location_address')) { + uni.getLocation({ + // #ifndef APP-PLUS + type: 'gcj02', + // #endif + success: res => { + locationPromise = null; + let latlng = res.latitude + ',' + res.longitude; + getAddressByLatlngFn(latlng); + }, + fail: (res) => { + locationPromise = null; + // uni.showToast({ title: res.errMsg, icon: 'none', duration: 15000 }); + systemStore.defaultPositionAddress = '定位失败'; + if (res.errno) { + if (res.errno == 104) { + let msg = '用户未授权隐私权限,获取位置失败'; + // uni.showToast({ title: msg, icon: 'none' }); + console.log(msg) + } else if (res.errno == 112) { + let msg = '隐私协议中未声明,获取位置失败'; + // uni.showToast({ title: msg, icon: 'none' }); + console.log(msg) + } + } + if (res.errMsg) { + if (res.errMsg.indexOf('getLocation:fail') != -1 || res.errMsg.indexOf('deny') != -1 || res.errMsg.indexOf('denied') != -1) { + let msg = '用户未授权获取位置权限,将无法提供服务'; + // uni.showToast({ title: msg, icon: 'none' }); + console.log(msg) + } else { + // uni.showToast({ title: res.errMsg, icon: 'none' }); + console.log(res.errMsg) + } + } + } + }); + } else { + locationPromise = null; + } + // #endif + } else { + locationPromise = null; + } + }; + // 监听页面加载 const onLoadLifeCycle = (callback: any = '') => { onLoad((option: any) => { @@ -25,76 +103,112 @@ export function useLocation(isOpenLocation: any) { }); } - const init = () => { + // 刷新页面时需要调用的 + const refreshLocation = () => { if (!isOpen) return false; + + // 使用 locationPromise 作为唯一的锁源 + // 如果已经有定位在进行,直接返回 + if (locationPromise) { + return; + } + + // 立即设置空 Promise 作为锁(这是关键!必须在任何检查之前设置) + // 第二个调用者会在上面的检查中看到 locationPromise 已存在,直接返回 + locationPromise = new Promise(() => {}); + + // 只读取一次本地缓存,减少重复存储调用 + const locationCache = uni.getStorageSync('location_address'); + const manualSelect = uni.getStorageSync('manually_select_location_from_map'); + + // 存在手动选点标记,直接终止逻辑 + if (manualSelect) { + locationPromise = null; + return; + } + + // 有定位缓存 + if (locationCache) { + const cacheInfo = locationStorage(); + // 缓存未过期,恢复定位信息 + if (!cacheInfo.is_expired) { + // 检查经纬度是否有效(非空且非0) + const hasValidLatLng = locationCache.latitude && locationCache.longitude && + locationCache.latitude !== 0 && locationCache.longitude !== 0; + if (hasValidLatLng) { + systemStore.setAddressInfo(locationCache); + locationPromise = null; + return; // 有有效缓存,直接返回,不触发定位 + } + // 经纬度无效,继续往下走重新定位 + } + // 缓存过期或经纬度无效,删除缓存 + uni.removeStorageSync('location_address'); + } + + // 无缓存或缓存无效/过期,直接执行定位 // 排除手动地图选择位置的情况 if (!uni.getStorageSync('manually_select_location_from_map')) { // #ifdef H5 - if (isWeixinBrowser() && systemStore.mapConfig.is_open && !uni.getStorageSync('location_address')) { + if (isWeixinBrowser() && systemStore.mapConfig.is_open) { wechat.init(() => { wechat.getLocation(res => { - let latlng = res.latitude + ',' + res.longitude; // 纬度(浮点数,范围为90 ~ -90),经度(浮点数,范围为180 ~ -180) - getAddressByLatlngFn(latlng) - }) + locationPromise = null; + let latlng = res.latitude + ',' + res.longitude; + getAddressByLatlngFn(latlng); + }); }); - + } else { + locationPromise = null; } // #endif // #ifndef H5 - if (systemStore.mapConfig.is_open && !uni.getStorageSync('location_address')) { + if (systemStore.mapConfig.is_open) { uni.getLocation({ // #ifndef APP-PLUS type: 'gcj02', // #endif success: res => { - let latlng = res.latitude + ',' + res.longitude; // 纬度(浮点数,范围为90 ~ -90),经度(浮点数,范围为180 ~ -180) + locationPromise = null; + let latlng = res.latitude + ',' + res.longitude; getAddressByLatlngFn(latlng); }, fail: (res) => { - uni.showToast({ title: res.errMsg, icon: 'none', duration: 15000 }) + locationPromise = null; + // uni.showToast({ title: res.errMsg, icon: 'none', duration: 15000 }); systemStore.defaultPositionAddress = '定位失败'; if (res.errno) { if (res.errno == 104) { let msg = '用户未授权隐私权限,获取位置失败'; - uni.showToast({ title: msg, icon: 'none' }) + // uni.showToast({ title: msg, icon: 'none' }); + console.log(msg) } else if (res.errno == 112) { let msg = '隐私协议中未声明,获取位置失败'; - uni.showToast({ title: msg, icon: 'none' }) + // uni.showToast({ title: msg, icon: 'none' }); + console.log(msg) } } if (res.errMsg) { if (res.errMsg.indexOf('getLocation:fail') != -1 || res.errMsg.indexOf('deny') != -1 || res.errMsg.indexOf('denied') != -1) { let msg = '用户未授权获取位置权限,将无法提供服务'; - uni.showToast({ title: msg, icon: 'none' }) + // uni.showToast({ title: msg, icon: 'none' }); + console.log(msg) } else { - uni.showToast({ title: res.errMsg, icon: 'none' }) + // uni.showToast({ title: res.errMsg, icon: 'none' }); + console.log(res.errMsg) } } } }); + } else { + locationPromise = null; } // #endif + } else { + locationPromise = null; } - } - - // 刷新页面时需要调用的 - const refreshLocation = () => { - if (!isOpen) return false; - if (!uni.getStorageSync('manually_select_location_from_map') && uni.getStorageSync('location_address')) { - if (locationStorage() && !locationStorage().is_expired) { - systemStore.setAddressInfo(uni.getStorageSync('location_address')) - } else { - uni.removeStorageSync('location_address'); - } - - } - - // 定位信息过期后,重新获取定位 - if (!uni.getStorageSync('manually_select_location_from_map') && locationStorage() && locationStorage().is_expired) { - init(); - } - } + }; // 通过经纬度获取地址信息 const getAddressByLatlngFn = (latlng: any = '') => { @@ -161,12 +275,15 @@ export function useLocation(isOpenLocation: any) { if (res.errMsg && res.errno) { if (res.errno == 104) { let msg = '用户未授权隐私权限,选择位置失败'; - uni.showToast({ title: msg, icon: 'none' }) + // uni.showToast({ title: msg, icon: 'none' }) + console.log(msg) } else if (res.errno == 112) { let msg = '隐私协议中未声明,打开地图选择位置失败'; - uni.showToast({ title: msg, icon: 'none' }) + // uni.showToast({ title: msg, icon: 'none' }) + console.log(msg) } else { - uni.showToast({ title: res.errMsg, icon: 'none' }) + // uni.showToast({ title: res.errMsg, icon: 'none' }) + console.log(res.errMsg) } } } diff --git a/uni-app/src/pages.json b/uni-app/src/pages.json index 8e766e6e2..d7b29d463 100644 --- a/uni-app/src/pages.json +++ b/uni-app/src/pages.json @@ -210,6 +210,7 @@ ], "subPackages": [ // {{ PAGE_BEGAIN }} + // {{ PAGE_END }} { "root": "app/components", diff --git a/uni-app/src/stores/system.ts b/uni-app/src/stores/system.ts index a1b7fd701..54644c7d2 100644 --- a/uni-app/src/stores/system.ts +++ b/uni-app/src/stores/system.ts @@ -61,7 +61,7 @@ const useSystemStore = defineStore('system', { }, shareCallback: null, defaultPositionAddress: '定位中', - diyAddressInfo: null, + diyAddressInfo: {}, currTabbar: { path: '', query: {} diff --git a/uni-app/src/utils/common.ts b/uni-app/src/utils/common.ts index c36ad9096..56ea4eebc 100644 --- a/uni-app/src/utils/common.ts +++ b/uni-app/src/utils/common.ts @@ -576,12 +576,15 @@ export function copy(value: any, callback: any) { if (res.errMsg && res.errno) { if (res.errno == 104) { let msg = '用户未授权隐私权限,设置剪贴板数据失败'; - uni.showToast({ title: msg, icon: 'none' }) + // uni.showToast({ title: msg, icon: 'none' }) + console.log(msg) } else if (res.errno == 112) { let msg = '隐私协议中未声明,设置剪贴板数据失败'; - uni.showToast({ title: msg, icon: 'none' }) + // uni.showToast({ title: msg, icon: 'none' }) + console.log(msg) } else { - uni.showToast({ title: res.errMsg, icon: 'none' }) + // uni.showToast({ title: res.errMsg, icon: 'none' }) + console.log(res.errMsg) } } } @@ -845,7 +848,7 @@ export function openMapSelector(backurl: string, params = '') { // 天地图的位置选择器URL // 注意:天地图的位置选择器API可能与腾讯地图不同,需要根据实际API文档调整 const baseUrl = (import.meta.env.VITE_APP_BASE_URL || `${ location.origin }`).replace(/\/api\/$/, '') - const url = baseUrl + `/tianmap/index.html?search=1&type=0&backurl=${ encodeURIComponent(backurl) }&key=${ tiandituKey }` + (params ? '&' + params : '') + const url = baseUrl + `/tianmap/index.html?search=1&type=0&backurl=${ encodeURIComponent(backurl) }&key=${ tiandituKey }&t=${Date.now()}` + (params ? '&' + params : '') window.location.href = url; } } \ No newline at end of file