作者 韩昌

g

@@ -3,6 +3,7 @@ import { genTestUserSig, aegisID } from './debug/index.js' @@ -3,6 +3,7 @@ import { genTestUserSig, aegisID } from './debug/index.js'
3 import { TIM, TIMUploadPlugin, Aegis } from './debug/tim.js' 3 import { TIM, TIMUploadPlugin, Aegis } from './debug/tim.js'
4 import UseSetCidHandler from '@/hooks/useSetCidHandler' 4 import UseSetCidHandler from '@/hooks/useSetCidHandler'
5 import { getLocationHandler } from './utils/getLocation' 5 import { getLocationHandler } from './utils/getLocation'
  6 +import { getDeviceType } from './utils/getDeviceType'
6 const aegis = new Aegis({ 7 const aegis = new Aegis({
7 id: aegisID, // 项目key 8 id: aegisID, // 项目key
8 reportApiSpeed: true // 接口测速 9 reportApiSpeed: true // 接口测速
@@ -33,6 +34,7 @@ uni.$TUICallKit = TUICallKit // 全局引入 @@ -33,6 +34,7 @@ uni.$TUICallKit = TUICallKit // 全局引入
33 // #endif 34 // #endif
34 export default { 35 export default {
35 onLaunch: function () { 36 onLaunch: function () {
  37 + getDeviceType()
36 // this.bindTIMEvent() 38 // this.bindTIMEvent()
37 // this.login() 39 // this.login()
38 // #ifdef APP-PLUS 40 // #ifdef APP-PLUS
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 "backToExit" : "false", 9 "backToExit" : "false",
10 "second" : { 10 "second" : {
11 "title" : "确认提示", 11 "title" : "确认提示",
12 - "message" : "  进入应用前,你需先同意<a href='https://doctor.apple02.brofirst.cn/serviceText/'>《服务协议》</a>和<a href='https://doctor.apple02.brofirst.cn/userPrivacy/'>《隐私政策》</a>,否则将退出应用。", 12 + "message" : "  进入应用前,你需先同意<a href=\"https://doctor.apple02.brofirst.cn/serviceText/\">《用户服务协议》</a>和<a href=\"https://doctor.apple02.brofirst.cn/userPrivacy/\">《用户隐私协议》</a>,否则将退出应用。",
13 "buttonAccept" : "同意并继续", 13 "buttonAccept" : "同意并继续",
14 "buttonRefuse" : "退出应用" 14 "buttonRefuse" : "退出应用"
15 }, 15 },
@@ -55,6 +55,7 @@ export const updateChange_phone = (data: EditPhoneType) => request({ url: '/vete @@ -55,6 +55,7 @@ export const updateChange_phone = (data: EditPhoneType) => request({ url: '/vete
55 export const updateChange_invite_paper = (data: RecordsInvitePaper) => request({ url: '/veterinary/invite_paper', method: 'POST', data }) // 记录用户分享海报 55 export const updateChange_invite_paper = (data: RecordsInvitePaper) => request({ url: '/veterinary/invite_paper', method: 'POST', data }) // 记录用户分享海报
56 export const updateChange_pwd = (data: ChangePwdType) => request({ url: '/veterinary/change_pwd', method: 'POST', data }) // 修改密码 56 export const updateChange_pwd = (data: ChangePwdType) => request({ url: '/veterinary/change_pwd', method: 'POST', data }) // 修改密码
57 export const fetchDelUser = () => request({ url: '/veterinary/delUser', method: 'GET' }) // 注销账号 57 export const fetchDelUser = () => request({ url: '/veterinary/delUser', method: 'GET' }) // 注销账号
  58 +export const getCustomerServicePhone = () => request({ url: '/veterinary/getCustomerServicePhone', method: 'GET' }) // 注销账号
58 59
59 // 消息 60 // 消息
60 export const getMsg_count = () => request({ url: '/veterinary/msg_count', method: 'GET' }) // 未读消息数量 61 export const getMsg_count = () => request({ url: '/veterinary/msg_count', method: 'GET' }) // 未读消息数量
@@ -2,8 +2,8 @@ @@ -2,8 +2,8 @@
2 "name" : "宠研兽医", 2 "name" : "宠研兽医",
3 "appid" : "__UNI__AB7B27B", 3 "appid" : "__UNI__AB7B27B",
4 "description" : "", 4 "description" : "",
5 - "versionName" : "1.0.0",  
6 - "versionCode" : "100", 5 + "versionName" : "1.0.1",
  6 + "versionCode" : 1010,
7 "transformPx" : false, 7 "transformPx" : false,
8 "extensions" : { 8 "extensions" : {
9 "uni-cloud-verify" : {} // 启用一键登录扩展,值为空对象即可 9 "uni-cloud-verify" : {} // 启用一键登录扩展,值为空对象即可
@@ -49,6 +49,10 @@ @@ -49,6 +49,10 @@
49 "<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>", 49 "<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
50 "<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>" 50 "<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
51 ], 51 ],
  52 + "permissionExternalStorage" : {
  53 + "request" : "none",
  54 + "prompt" : "应用保存运行状态等信息,需要获取读写手机储存(系统提示为访问设备上的图片,媒体内容和文件)权限,请允许"
  55 + },
52 "minSdkVersion" : 21, 56 "minSdkVersion" : 21,
53 "targetSdkVersion" : 30 57 "targetSdkVersion" : 30
54 }, 58 },
@@ -61,6 +65,11 @@ @@ -61,6 +65,11 @@
61 "applinks:static-mp-8ab296ea-35dc-49cc-92d3-9a750639c63d.next.bspapp.com" 65 "applinks:static-mp-8ab296ea-35dc-49cc-92d3-9a750639c63d.next.bspapp.com"
62 ] 66 ]
63 } 67 }
  68 + },
  69 + "privacyDescription" : {
  70 + "NSPhotoLibraryUsageDescription" : "上传资质信息、更改头像信息等模块手动选择上传相册内的照片需要读取相册内容,是否允许读取相册内容",
  71 + "NSPhotoLibraryAddUsageDescription" : "下载图片需要保存到相册,是否允许保存照片到相册",
  72 + "NSCameraUsageDescription" : "上传资质信息、更改头像信息等模块拍照上传照片需要使用摄像头,是否允许使用摄像头"
64 } 73 }
65 }, 74 },
66 /* SDK配置 */ 75 /* SDK配置 */
@@ -109,19 +118,34 @@ @@ -109,19 +118,34 @@
109 }, 118 },
110 "icons" : { 119 "icons" : {
111 "android" : { 120 "android" : {
112 - "xxxhdpi" : "static/images/logo.png" 121 + "xxxhdpi" : "unpackage/res/icons/192x192.png",
  122 + "hdpi" : "unpackage/res/icons/72x72.png",
  123 + "xhdpi" : "unpackage/res/icons/96x96.png",
  124 + "xxhdpi" : "unpackage/res/icons/144x144.png"
113 }, 125 },
114 "ios" : { 126 "ios" : {
115 "iphone" : { 127 "iphone" : {
116 - "app@2x" : "static/logo/logo120.png",  
117 - "spotlight@3x" : "static/logo/logo120.png" 128 + "app@2x" : "unpackage/res/icons/120x120.png",
  129 + "spotlight@3x" : "unpackage/res/icons/120x120.png",
  130 + "notification@2x" : "unpackage/res/icons/40x40.png",
  131 + "app@3x" : "unpackage/res/icons/180x180.png",
  132 + "notification@3x" : "unpackage/res/icons/60x60.png",
  133 + "settings@2x" : "unpackage/res/icons/58x58.png",
  134 + "settings@3x" : "unpackage/res/icons/87x87.png",
  135 + "spotlight@2x" : "unpackage/res/icons/80x80.png"
118 }, 136 },
119 "ipad" : { 137 "ipad" : {
120 - "app" : "static/logo/logo76.png",  
121 - "app@2x" : "static/logo/logo152.png",  
122 - "proapp@2x" : "static/logo/logo167.png" 138 + "app" : "unpackage/res/icons/76x76.png",
  139 + "app@2x" : "unpackage/res/icons/152x152.png",
  140 + "proapp@2x" : "unpackage/res/icons/167x167.png",
  141 + "spotlight" : "unpackage/res/icons/40x40.png",
  142 + "notification@2x" : "unpackage/res/icons/40x40.png",
  143 + "notification" : "unpackage/res/icons/20x20.png",
  144 + "settings" : "unpackage/res/icons/29x29.png",
  145 + "settings@2x" : "unpackage/res/icons/58x58.png",
  146 + "spotlight@2x" : "unpackage/res/icons/80x80.png"
123 }, 147 },
124 - "appstore" : "static/images/logo.png" 148 + "appstore" : "unpackage/res/icons/1024x1024.png"
125 } 149 }
126 } 150 }
127 }, 151 },
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 <image src="/static/images/mAvatar.png" class="mine-avatar" mode="aspectFill" @click.stop="proxy.$h.previewImage('/static/images/mAvatar.png')" /> 11 <image src="/static/images/mAvatar.png" class="mine-avatar" mode="aspectFill" @click.stop="proxy.$h.previewImage('/static/images/mAvatar.png')" />
12 </view> 12 </view>
13 <view> 13 <view>
14 - <view class="flexA" style="margin-bottom: 10rpx;flex-wrap: wrap;"> 14 + <view class="flexA" style="margin-bottom: 10rpx; flex-wrap: wrap">
15 <view class="mine-username">{{ UserInfo?.nickname ?? '去登录' }}</view> 15 <view class="mine-username">{{ UserInfo?.nickname ?? '去登录' }}</view>
16 <view class="mine-toptag flexC" v-if="![null, undefined, ''].includes(UserInfo?.hospitalName)">{{ UserInfo?.hospitalName ?? '去登录' }}</view> 16 <view class="mine-toptag flexC" v-if="![null, undefined, ''].includes(UserInfo?.hospitalName)">{{ UserInfo?.hospitalName ?? '去登录' }}</view>
17 </view> 17 </view>
@@ -93,7 +93,7 @@ import { onLoad, onShow, onPageScroll } from '@dcloudio/uni-app' @@ -93,7 +93,7 @@ import { onLoad, onShow, onPageScroll } from '@dcloudio/uni-app'
93 import Tabbar from '@/components/Tabbar' 93 import Tabbar from '@/components/Tabbar'
94 import NavBar from '@/components/NavBar' 94 import NavBar from '@/components/NavBar'
95 import TurnDown from '@/components/TurnDown' 95 import TurnDown from '@/components/TurnDown'
96 -import { getMy, getCareer, getDepartment, getIndex, getMsg_count } from '@/api' 96 +import { getMy, getCareer, getDepartment, getIndex, getMsg_count, getCustomerServicePhone } from '@/api'
97 import type { Result, UserInfoType, IndexListType, IndexType, MineJumpListType, MessageCountType } from '../../types' 97 import type { Result, UserInfoType, IndexListType, IndexType, MineJumpListType, MessageCountType } from '../../types'
98 98
99 const { proxy } = getCurrentInstance() as { proxy: ComponentPublicInstance } 99 const { proxy } = getCurrentInstance() as { proxy: ComponentPublicInstance }
@@ -118,7 +118,8 @@ const jumpList: MineJumpListType[] = [ @@ -118,7 +118,8 @@ const jumpList: MineJumpListType[] = [
118 { title: '问诊记录', iconUrl: '/static/images/mineicon2.png', url: `/pages2/order/index?orderState=0&subOrderState=3&isRecords=success`, requiredAuth: 'err' }, 118 { title: '问诊记录', iconUrl: '/static/images/mineicon2.png', url: `/pages2/order/index?orderState=0&subOrderState=3&isRecords=success`, requiredAuth: 'err' },
119 // { title: '问诊价格', iconUrl: '/static/images/mineicon3.png', requiredAuth: 'err' }, 119 // { title: '问诊价格', iconUrl: '/static/images/mineicon3.png', requiredAuth: 'err' },
120 { title: '邀请分享', iconUrl: '/static/images/mineicon4.png', url: `/pages2/mineinfo/qrcode`, requiredAuth: 'success' }, 120 { title: '邀请分享', iconUrl: '/static/images/mineicon4.png', url: `/pages2/mineinfo/qrcode`, requiredAuth: 'success' },
121 - { title: '账户设置', iconUrl: '/static/images/accountsetting.png', url: `/pages2/money/account`, requiredAuth: 'err' } 121 + { title: '账户设置', iconUrl: '/static/images/accountsetting.png', url: `/pages2/money/account`, requiredAuth: 'err' },
  122 + { title: '联系客服', iconUrl: '/static/images/kefu.png', url: `/pages2/money/account`, requiredAuth: 'err', type: 'showModal' }
122 ] 123 ]
123 124
124 const UserInfo = ref<UserInfoType>() 125 const UserInfo = ref<UserInfoType>()
@@ -141,9 +142,22 @@ const getIndexDataHandler = async () => { @@ -141,9 +142,22 @@ const getIndexDataHandler = async () => {
141 IndexData.value = result 142 IndexData.value = result
142 } 143 }
143 144
144 -const jumpHandler = (_: MineJumpListType) => { 145 +const jumpHandler = async (_: MineJumpListType) => {
145 if (_.requiredAuth === 'success' && ![20, '20'].includes(IndexData.value?.examineState)) return uni.$u.toast('请先完成认证') 146 if (_.requiredAuth === 'success' && ![20, '20'].includes(IndexData.value?.examineState)) return uni.$u.toast('请先完成认证')
146 147
  148 + if (_.type === 'showModal') {
  149 + const { result } = await getCustomerServicePhone()
  150 +
  151 + return uni.showModal({
  152 + content: result,
  153 + showCancel: true,
  154 + confirmText: '复制',
  155 + success: ({ confirm }) => {
  156 + if (confirm) proxy.$h.copyText(result)
  157 + }
  158 + })
  159 + }
  160 +
147 proxy.$h.jumpUrl(_.url) 161 proxy.$h.jumpUrl(_.url)
148 } 162 }
149 163
@@ -91,7 +91,7 @@ const settingList1 = ref<SettingItemType[]>([ @@ -91,7 +91,7 @@ const settingList1 = ref<SettingItemType[]>([
91 const settingList2 = ref<SettingItemType[]>([ 91 const settingList2 = ref<SettingItemType[]>([
92 { title: '设置问诊价格', text: '', type: 'jump', url: '/pages2/order/consultationFee' }, 92 { title: '设置问诊价格', text: '', type: 'jump', url: '/pages2/order/consultationFee' },
93 { title: '意见反馈', text: '', type: 'jump', url: '/pages/mine/feedback' }, 93 { title: '意见反馈', text: '', type: 'jump', url: '/pages/mine/feedback' },
94 - { title: '关于我们', text: '', value: 'xxx', type: 'input' } 94 + { title: '关于我们', text: '', value: '', type: 'jump', url:'/pages/login/agreement?title=关于我们&type=1' }
95 ]) 95 ])
96 96
97 const settingList3 = ref<SettingItemType[]>([{ title: '退出登录', text: '', type: 'SignOUT' }]) 97 const settingList3 = ref<SettingItemType[]>([{ title: '退出登录', text: '', type: 'SignOUT' }])
@@ -629,6 +629,7 @@ export interface MineJumpListType { @@ -629,6 +629,7 @@ export interface MineJumpListType {
629 iconUrl?: string 629 iconUrl?: string
630 url?: string 630 url?: string
631 requiredAuth?: string 631 requiredAuth?: string
  632 + [property: string]: any;
632 } 633 }
633 634
634 export interface GetUserCardType { 635 export interface GetUserCardType {
  1 +interface DeviceInfo {
  2 + platform: 'android' | 'ios' | 'unknown';
  3 +}
  4 +
  5 +
  6 +export const getDeviceType = (): Promise<string> => {
  7 + return new Promise((resolve, reject) => {
  8 + let deviceType = uni.getStorageSync('deviceType');
  9 + if (deviceType) {
  10 + resolve(deviceType);
  11 + } else {
  12 + uni.getSystemInfo({
  13 + success: function(res: DeviceInfo) {
  14 + if (res.platform === 'android') {
  15 + uni.setStorageSync('deviceType', 'android');
  16 + resolve('android');
  17 + } else if (res.platform === 'ios') {
  18 + uni.setStorageSync('deviceType', 'ios');
  19 + resolve('ios');
  20 + } else {
  21 + uni.setStorageSync('deviceType', '未知');
  22 + reject(new Error('无法识别当前设备类型'));
  23 + }
  24 + },
  25 + fail: function(err: any) {
  26 + reject(err);
  27 + }
  28 + });
  29 + }
  30 + });
  31 +}
  32 +
  33 +// 调用工具函数获取当前设备类型
  34 +// getDeviceType().then(deviceType => {
  35 +// console.log('当前设备类型是:', deviceType);
  36 +// }).catch(err => {
  37 +// console.error('获取设备类型失败:', err);
  38 +// });
1 -// export const baseURL = 'http://192.168.10.63:8080/jeecg-boot' // 本地  
2 -// export const baseURL = 'http://t5qnpc.natappfree.cc/jeecg-boot' // 本地  
3 -export const baseURL = 'https://doctor.apple02.brofirst.cn/jeecg-boot' // 本地  
4 -// export const baseURL = 'http://114.115.178.175:8799/jeecg-boot' // 测试 1 +// export const baseURL = 'http://192.168.10.167:8080/jeecg-boot'
  2 +// export const baseURL = 'http://t5qnpc.natappfree.cc/jeecg-boot'
  3 +export const baseURL = 'https://doctor.apple02.brofirst.cn/jeecg-boot'
  4 +// export const baseURL = 'http://114.115.178.175:8799/jeecg-boot'
5 // export const baseURL = 'http://127.0.0.1:4523/m1/3332971-0-default/jeecg-boot' // mock 5 // export const baseURL = 'http://127.0.0.1:4523/m1/3332971-0-default/jeecg-boot' // mock
6 6
7 interface optionsType { 7 interface optionsType {
1 import { baseURL } from './http' 1 import { baseURL } from './http'
  2 +import { permision } from './permission'
2 3
3 // immuneStatus: { 1:'',2:'',3: '',4: '' } 4 // immuneStatus: { 1:'',2:'',3: '',4: '' }
4 const GlobalData = { 5 const GlobalData = {
@@ -36,7 +37,17 @@ export default { @@ -36,7 +37,17 @@ export default {
36 return GlobalData[object][key] || GlobalData[object][err] 37 return GlobalData[object][key] || GlobalData[object][err]
37 }, 38 },
38 // 上传图片 39 // 上传图片
39 - upload(url: string, callBack: (e: any) => void) { 40 + async upload(url: string, callBack: (e: any) => void) {
  41 + // #ifdef APP-PLUS
  42 + if(uni.getStorageSync('deviceType') === 'android') {
  43 + const result = await permision.premissionCheck("EXTERNAL_STORAGE")
  44 + if (result != 1) {
  45 + console.log('拒绝')
  46 + return
  47 + }
  48 + }
  49 + // #endif
  50 +
40 let arr = {} 51 let arr = {}
41 uni.chooseImage({ 52 uni.chooseImage({
42 count: 3, 53 count: 3,
@@ -156,7 +167,7 @@ export default { @@ -156,7 +167,7 @@ export default {
156 } 167 }
157 }) 168 })
158 }, 169 },
159 - copyText(text: string) { 170 + copyText(text: string | number) {
160 //#ifndef H5 171 //#ifndef H5
161 uni.setClipboardData({ 172 uni.setClipboardData({
162 data: String(text), 173 data: String(text),
  1 +var isIos
  2 +// #ifdef APP-PLUS
  3 +isIos = (plus.os.name == "iOS")
  4 +// #endif
  5 +
  6 +// 判断推送权限是否开启
  7 +function judgeIosPermissionPush() {
  8 + var result = false;
  9 + var UIApplication = plus.ios.import("UIApplication");
  10 + var app = UIApplication.sharedApplication();
  11 + var enabledTypes = 0;
  12 + if (app.currentUserNotificationSettings) {
  13 + var settings = app.currentUserNotificationSettings();
  14 + enabledTypes = settings.plusGetAttribute("types");
  15 + console.log("enabledTypes1:" + enabledTypes);
  16 + if (enabledTypes == 0) {
  17 + console.log("推送权限没有开启");
  18 + } else {
  19 + result = true;
  20 + console.log("已经开启推送功能!")
  21 + }
  22 + plus.ios.deleteObject(settings);
  23 + } else {
  24 + enabledTypes = app.enabledRemoteNotificationTypes();
  25 + if (enabledTypes == 0) {
  26 + console.log("推送权限没有开启!");
  27 + } else {
  28 + result = true;
  29 + console.log("已经开启推送功能!")
  30 + }
  31 + console.log("enabledTypes2:" + enabledTypes);
  32 + }
  33 + plus.ios.deleteObject(app);
  34 + plus.ios.deleteObject(UIApplication);
  35 + return result;
  36 +}
  37 +
  38 +// 判断定位权限是否开启
  39 +function judgeIosPermissionLocation() {
  40 + var result = false;
  41 + var cllocationManger = plus.ios.import("CLLocationManager");
  42 + var status = cllocationManger.authorizationStatus();
  43 + result = (status != 2)
  44 + console.log("定位权限开启:" + result);
  45 + // 以下代码判断了手机设备的定位是否关闭,推荐另行使用方法 checkSystemEnableLocation
  46 + /* var enable = cllocationManger.locationServicesEnabled();
  47 + var status = cllocationManger.authorizationStatus();
  48 + console.log("enable:" + enable);
  49 + console.log("status:" + status);
  50 + if (enable && status != 2) {
  51 + result = true;
  52 + console.log("手机定位服务已开启且已授予定位权限");
  53 + } else {
  54 + console.log("手机系统的定位没有打开或未给予定位权限");
  55 + } */
  56 + plus.ios.deleteObject(cllocationManger);
  57 + return result;
  58 +}
  59 +
  60 +// 判断麦克风权限是否开启
  61 +function judgeIosPermissionRecord() {
  62 + var result = false;
  63 + var avaudiosession = plus.ios.import("AVAudioSession");
  64 + var avaudio = avaudiosession.sharedInstance();
  65 + var permissionStatus = avaudio.recordPermission();
  66 + console.log("permissionStatus:" + permissionStatus);
  67 + if (permissionStatus == 1684369017 || permissionStatus == 1970168948) {
  68 + console.log("麦克风权限没有开启");
  69 + } else {
  70 + result = true;
  71 + console.log("麦克风权限已经开启");
  72 + }
  73 + plus.ios.deleteObject(avaudiosession);
  74 + return result;
  75 +}
  76 +
  77 +// 判断相机权限是否开启
  78 +function judgeIosPermissionCamera() {
  79 + var result = false;
  80 + var AVCaptureDevice = plus.ios.import("AVCaptureDevice");
  81 + var authStatus = AVCaptureDevice.authorizationStatusForMediaType('vide');
  82 + console.log("authStatus:" + authStatus);
  83 + if (authStatus == 3) {
  84 + result = true;
  85 + console.log("相机权限已经开启");
  86 + } else {
  87 + console.log("相机权限没有开启");
  88 + }
  89 + plus.ios.deleteObject(AVCaptureDevice);
  90 + return result;
  91 +}
  92 +
  93 +// 判断相册权限是否开启
  94 +function judgeIosPermissionPhotoLibrary() {
  95 + var result = false;
  96 + var PHPhotoLibrary = plus.ios.import("PHPhotoLibrary");
  97 + var authStatus = PHPhotoLibrary.authorizationStatus();
  98 + console.log("authStatus:" + authStatus);
  99 + if (authStatus == 3) {
  100 + result = true;
  101 + console.log("相册权限已经开启");
  102 + } else {
  103 + console.log("相册权限没有开启");
  104 + }
  105 + plus.ios.deleteObject(PHPhotoLibrary);
  106 + return result;
  107 +}
  108 +
  109 +// 判断通讯录权限是否开启
  110 +function judgeIosPermissionContact() {
  111 + var result = false;
  112 + var CNContactStore = plus.ios.import("CNContactStore");
  113 + var cnAuthStatus = CNContactStore.authorizationStatusForEntityType(0);
  114 + if (cnAuthStatus == 3) {
  115 + result = true;
  116 + console.log("通讯录权限已经开启");
  117 + } else {
  118 + console.log("通讯录权限没有开启");
  119 + }
  120 + plus.ios.deleteObject(CNContactStore);
  121 + return result;
  122 +}
  123 +
  124 +// 判断日历权限是否开启
  125 +function judgeIosPermissionCalendar() {
  126 + var result = false;
  127 + var EKEventStore = plus.ios.import("EKEventStore");
  128 + var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(0);
  129 + if (ekAuthStatus == 3) {
  130 + result = true;
  131 + console.log("日历权限已经开启");
  132 + } else {
  133 + console.log("日历权限没有开启");
  134 + }
  135 + plus.ios.deleteObject(EKEventStore);
  136 + return result;
  137 +}
  138 +
  139 +// 判断备忘录权限是否开启
  140 +function judgeIosPermissionMemo() {
  141 + var result = false;
  142 + var EKEventStore = plus.ios.import("EKEventStore");
  143 + var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(1);
  144 + if (ekAuthStatus == 3) {
  145 + result = true;
  146 + console.log("备忘录权限已经开启");
  147 + } else {
  148 + console.log("备忘录权限没有开启");
  149 + }
  150 + plus.ios.deleteObject(EKEventStore);
  151 + return result;
  152 +}
  153 +
  154 +// Android权限查询
  155 +function requestAndroidPermission(permissionID) {
  156 + return new Promise((resolve, reject) => {
  157 + plus.android.requestPermissions(
  158 + permissionID.split(","),
  159 + // [permissionID], // 理论上支持多个权限同时查询,但实际上本函数封装只处理了一个权限的情况。有需要的可自行扩展封装
  160 + function(resultObj) {
  161 + var result = 0;
  162 + for (var i = 0; i < resultObj.granted.length; i++) {
  163 + var grantedPermission = resultObj.granted[i];
  164 + console.log('已获取的权限:' + grantedPermission);
  165 + result = 1
  166 + }
  167 + for (var i = 0; i < resultObj.deniedPresent.length; i++) {
  168 + var deniedPresentPermission = resultObj.deniedPresent[i];
  169 + console.log('拒绝本次申请的权限:' + deniedPresentPermission);
  170 + result = 0
  171 + }
  172 + for (var i = 0; i < resultObj.deniedAlways.length; i++) {
  173 + var deniedAlwaysPermission = resultObj.deniedAlways[i];
  174 + console.log('永久拒绝申请的权限:' + deniedAlwaysPermission);
  175 + result = -1
  176 + }
  177 + resolve(result);
  178 + // 若所需权限被拒绝,则打开APP设置界面,可以在APP设置界面打开相应权限
  179 + // if (result != 1) {
  180 + // gotoAppPermissionSetting()
  181 + // }
  182 + },
  183 + function(error) {
  184 + console.log('申请权限错误:' + error.code + " = " + error.message);
  185 + resolve({
  186 + code: error.code,
  187 + message: error.message
  188 + });
  189 + }
  190 + );
  191 + });
  192 +}
  193 +
  194 +// 使用一个方法,根据参数判断权限
  195 +function judgeIosPermission(permissionID) {
  196 + if (permissionID == "location") {
  197 + return judgeIosPermissionLocation()
  198 + } else if (permissionID == "camera") {
  199 + return judgeIosPermissionCamera()
  200 + } else if (permissionID == "photoLibrary") {
  201 + return judgeIosPermissionPhotoLibrary()
  202 + } else if (permissionID == "record") {
  203 + return judgeIosPermissionRecord()
  204 + } else if (permissionID == "push") {
  205 + return judgeIosPermissionPush()
  206 + } else if (permissionID == "contact") {
  207 + return judgeIosPermissionContact()
  208 + } else if (permissionID == "calendar") {
  209 + return judgeIosPermissionCalendar()
  210 + } else if (permissionID == "memo") {
  211 + return judgeIosPermissionMemo()
  212 + }
  213 + return false;
  214 +}
  215 +
  216 +// 跳转到**应用**的权限页面
  217 +function gotoAppPermissionSetting() {
  218 + if (isIos) {
  219 + var UIApplication = plus.ios.import("UIApplication");
  220 + var application2 = UIApplication.sharedApplication();
  221 + var NSURL2 = plus.ios.import("NSURL");
  222 + // var setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES");
  223 + var setting2 = NSURL2.URLWithString("app-settings:");
  224 + application2.openURL(setting2);
  225 +
  226 + plus.ios.deleteObject(setting2);
  227 + plus.ios.deleteObject(NSURL2);
  228 + plus.ios.deleteObject(application2);
  229 + } else {
  230 + // console.log(plus.device.vendor);
  231 + var Intent = plus.android.importClass("android.content.Intent");
  232 + var Settings = plus.android.importClass("android.provider.Settings");
  233 + var Uri = plus.android.importClass("android.net.Uri");
  234 + var mainActivity = plus.android.runtimeMainActivity();
  235 + var intent = new Intent();
  236 + intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
  237 + var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
  238 + intent.setData(uri);
  239 + mainActivity.startActivity(intent);
  240 + }
  241 +}
  242 +
  243 +// 检查系统的设备服务是否开启
  244 +// var checkSystemEnableLocation = async function () {
  245 +function checkSystemEnableLocation() {
  246 + if (isIos) {
  247 + var result = false;
  248 + var cllocationManger = plus.ios.import("CLLocationManager");
  249 + var result = cllocationManger.locationServicesEnabled();
  250 + console.log("系统定位开启:" + result);
  251 + plus.ios.deleteObject(cllocationManger);
  252 + return result;
  253 + } else {
  254 + var context = plus.android.importClass("android.content.Context");
  255 + var locationManager = plus.android.importClass("android.location.LocationManager");
  256 + var main = plus.android.runtimeMainActivity();
  257 + var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
  258 + var result = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER);
  259 + console.log("系统定位开启:" + result);
  260 + return result
  261 + }
  262 +}
  263 +
  264 +let permissionMap = {
  265 + "android": {
  266 + "CAMERA_EXTERNAL_STORAGE": {
  267 + "name": "android.permission.READ_EXTERNAL_STORAGE,android.permission.WRITE_EXTERNAL_STORAGE,android.permission.CAMERA",
  268 + "title": "相机/相册权限说明",
  269 + "content": "便于您使用该功能上传您的照片/图片/视频及用于更换头像、发布产品/需求、下载、与客服沟通等场景中读取和写入相册和文件内容"
  270 + },
  271 + "CAMERA": {
  272 + "name": "android.permission.CAMERA",
  273 + "title": "相机权限说明",
  274 + "content": "便于您使用该功能上传图片,用于与客服沟通等场景中发送拍摄图片"
  275 + },
  276 + "EXTERNAL_STORAGE": {
  277 + "name": "android.permission.READ_EXTERNAL_STORAGE,android.permission.WRITE_EXTERNAL_STORAGE",
  278 + "title": "相册权限说明",
  279 + "content": "便于您使用该功能上传您的照片/图片/视频及用于更换头像、发布产品/需求、下载、与客服沟通等场景中读取和写入相册和文件内容"
  280 + }
  281 + },
  282 + "ios": {}
  283 +}
  284 +
  285 +let view = null;
  286 +
  287 +function showViewDesc(permission) {
  288 + let plat = isIos ? "ios" : "android";
  289 + view = new plus.nativeObj.View('per-modal', {
  290 + top: '0px',
  291 + left: '0px',
  292 + width: '100%',
  293 + backgroundColor: 'rgba(0,0,0,0.2)',
  294 + //opacity: '.9'
  295 + })
  296 + view.drawRect({
  297 + color: '#fff',
  298 + radius: '5px'
  299 + }, {
  300 + top: '30px',
  301 + left: '5%',
  302 + width: '90%',
  303 + height: "100px",
  304 + })
  305 + view.drawText(permissionMap[plat][permission]["title"], {
  306 + top: '40px',
  307 + left: "8%",
  308 + height: "30px"
  309 + }, {
  310 + align: "left",
  311 + color: "#000",
  312 + }, {
  313 + onClick: function(e) {
  314 + console.log(e);
  315 + }
  316 + })
  317 + view.drawText(permissionMap[plat][permission]["content"], {
  318 + top: '65px',
  319 + height: "60px",
  320 + left: "8%",
  321 + width: "84%"
  322 + }, {
  323 + whiteSpace: 'normal',
  324 + size: "14px",
  325 + align: "left",
  326 + color: "#656563"
  327 + })
  328 + view.show()
  329 +}
  330 +
  331 +function premissionCheck(permission) {
  332 + return new Promise(async (resolve, reject) => {
  333 + let plat = isIos ? "ios" : "android";
  334 + if (isIos) { // ios
  335 + // const camera = permission.judgeIosPermission("camera");//判断ios是否给予摄像头权限
  336 + // //ios相册没权限,系统会自动弹出授权框
  337 + // //let photoLibrary = permission.judgeIosPermission("photoLibrary");//判断ios是否给予相册权限
  338 + // if(camera){
  339 + // resolve();
  340 + // }else{
  341 + // reject('需要开启相机使用权限');
  342 + // }
  343 + resolve(1)
  344 + } else { // android
  345 + let permission_arr = permissionMap[plat][permission]["name"].split(",");
  346 + let flag = true;
  347 + for(let i = 0;i<permission_arr.length;i++) {
  348 + let status = plus.navigator.checkPermission(permission_arr[i]);
  349 + if(status == "undetermined") {
  350 + flag = false;
  351 + }
  352 + }
  353 + console.log("flag", flag)
  354 + if (flag == false) { // 未完全授权
  355 + showViewDesc(permission);
  356 + requestAndroidPermission(permissionMap[plat][permission]["name"]).then((res) => {
  357 + view.close();
  358 + if (res == -1) {
  359 + uni.showModal({
  360 + title: '提示',
  361 + content: '操作权限已被拒绝,请手动前往设置',
  362 + confirmText: "立即设置",
  363 + success: (res) => {
  364 + if (res.confirm) {
  365 + gotoAppPermissionSetting()
  366 + }
  367 + }
  368 + })
  369 + }
  370 + resolve(res)
  371 + })
  372 + } else {
  373 + resolve(1)
  374 + }
  375 + }
  376 + })
  377 +}
  378 +
  379 +// module.exports = {
  380 +// judgeIosPermission: judgeIosPermission,
  381 +// requestAndroidPermission: requestAndroidPermission,
  382 +// checkSystemEnableLocation: checkSystemEnableLocation,
  383 +// gotoAppPermissionSetting: gotoAppPermissionSetting,
  384 +// premissionCheck: premissionCheck
  385 +// }
  386 +
  387 +export const permision = {
  388 + judgeIosPermission: judgeIosPermission,
  389 + requestAndroidPermission: requestAndroidPermission,
  390 + checkSystemEnableLocation: checkSystemEnableLocation,
  391 + gotoAppPermissionSetting: gotoAppPermissionSetting,
  392 + premissionCheck: premissionCheck
  393 +}