From 00a7a61df86db969f2ba61c508d02ba4709ce3d4 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期五, 05 六月 2026 10:09:06 +0800
Subject: [PATCH] 改bug
---
app/utils/utils.js | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 157 insertions(+), 1 deletions(-)
diff --git a/app/utils/utils.js b/app/utils/utils.js
index 3562b9e..eefaa45 100644
--- a/app/utils/utils.js
+++ b/app/utils/utils.js
@@ -46,4 +46,160 @@
});
})
return promise;
-}
\ No newline at end of file
+}
+
+const LOCATION_NOTICE_STORAGE_KEY = 'location_permission_notice_shown'
+const IMAGE_NOTICE_STORAGE_KEY = 'image_permission_notice_shown'
+
+const DEFAULT_LOCATION_NOTICE = {
+ title: '鑾峰彇浣嶇疆淇℃伅',
+ content: '涓轰簡缁欐偍鍒嗛厤闄勮繎鐨勮鍗曪紝骞惰绠楁帴閫佽揣鐨勭簿鍑嗚窛绂讳笌瀵艰埅璺嚎锛屾湰搴旂敤闇�瑕佽幏鍙栨偍鐨勪綅缃俊鎭��',
+ confirmText: '宸茬煡鏅�'
+}
+
+const DEFAULT_IMAGE_NOTICE = {
+ title: '鑾峰彇鐩告満鏉冮檺',
+ content: '涓轰簡鏀寔鎮ㄨ繘琛屽徃鏈鸿韩浠借璇侊紝浠ュ強鏂逛究鎮ㄥ湪鍙栭�佷欢鏃舵媿鐓х暀瀛樺嚟璇侊紝鏈簲鐢ㄩ渶瑕佽幏鍙栨偍鐨勭浉鏈轰笌鐩稿唽鏉冮檺銆�',
+ confirmText: '宸茬煡鏅�'
+}
+
+export function ensureLocationPermissionNotice(modalOptions = {}) {
+ const hasShown = uni.getStorageSync(LOCATION_NOTICE_STORAGE_KEY)
+ if (hasShown) {
+ return Promise.resolve(true)
+ }
+
+ const options = Object.assign({}, DEFAULT_LOCATION_NOTICE, modalOptions)
+
+ return new Promise((resolve) => {
+ uni.showModal({
+ title: options.title,
+ content: options.content,
+ confirmText: options.confirmText,
+ showCancel: false,
+ success: (res) => {
+ if (res.confirm) {
+ uni.setStorageSync(LOCATION_NOTICE_STORAGE_KEY, true)
+ resolve(true)
+ return
+ }
+ resolve(false)
+ },
+ fail: () => {
+ resolve(false)
+ }
+ })
+ })
+}
+
+export function getLocationWithNotice(locationOptions = {}, modalOptions = {}) {
+ return ensureLocationPermissionNotice(modalOptions).then((confirmed) => {
+ if (!confirmed) {
+ return Promise.reject({ errMsg: 'location permission notice canceled' })
+ }
+
+ return new Promise((resolve, reject) => {
+ uni.getLocation(Object.assign({}, locationOptions, {
+ success: (res) => {
+ uni.$emit('locationPermissionGranted', res)
+ if (typeof locationOptions.success === 'function') {
+ locationOptions.success(res)
+ }
+ resolve(res)
+ },
+ fail: (err) => {
+ if (typeof locationOptions.fail === 'function') {
+ locationOptions.fail(err)
+ }
+ reject(err)
+ }
+ }))
+ })
+ })
+}
+
+export function ensureImagePermissionNotice(modalOptions = {}) {
+ const hasShown = uni.getStorageSync(IMAGE_NOTICE_STORAGE_KEY)
+ if (hasShown) {
+ return Promise.resolve(true)
+ }
+
+ const options = Object.assign({}, DEFAULT_IMAGE_NOTICE, modalOptions)
+
+ return new Promise((resolve) => {
+ uni.showModal({
+ title: options.title,
+ content: options.content,
+ confirmText: options.confirmText,
+ showCancel: false,
+ success: (res) => {
+ if (res.confirm) {
+ uni.setStorageSync(IMAGE_NOTICE_STORAGE_KEY, true)
+ resolve(true)
+ return
+ }
+ resolve(false)
+ },
+ fail: () => {
+ resolve(false)
+ }
+ })
+ })
+}
+
+export function chooseImageWithNotice(imageOptions = {}, modalOptions = {}) {
+ return ensureImagePermissionNotice(modalOptions).then((confirmed) => {
+ if (!confirmed) {
+ return Promise.reject({ errMsg: 'image permission notice canceled' })
+ }
+
+ return new Promise((resolve, reject) => {
+ uni.chooseImage(Object.assign({}, imageOptions, {
+ success: (res) => {
+ if (typeof imageOptions.success === 'function') {
+ imageOptions.success(res)
+ }
+ resolve(res)
+ },
+ fail: (err) => {
+ const errMsg = (err && err.errMsg) || ''
+ if (errMsg && !/cancel/i.test(errMsg)) {
+ uni.showToast({
+ title: '闇�瑕佹巿鏉冪浉鏈烘潈闄�',
+ icon: 'none'
+ })
+ }
+ if (typeof imageOptions.fail === 'function') {
+ imageOptions.fail(err)
+ }
+ reject(err)
+ }
+ }))
+ })
+ })
+}
+
+export function checkLocationPermission() {
+ return new Promise((resolve) => {
+ if (typeof uni.getAppAuthorizeSetting === 'function') {
+ try {
+ const setting = uni.getAppAuthorizeSetting()
+ const locationAuthorized = setting.locationAuthorized
+ resolve(locationAuthorized === 'authorized' || locationAuthorized === 'authorizedAlways')
+ return
+ } catch (e) {
+ console.log('getAppAuthorizeSetting fail', e)
+ }
+ }
+
+ uni.getSetting({
+ success: (res) => {
+ const authSetting = res.authSetting || {}
+ resolve(!!authSetting['scope.userLocation'])
+ },
+ fail: () => {
+ resolve(false)
+ }
+ })
+ })
+}
--
Gitblit v1.9.3