分类 默认分类 下的文章

// todo 获取当前位置经纬度
        handleLoacation(toast) {
            uni.getLocation({
                type: 'gcj02',
                success: res => {
                    console.log('success')
                    // 获取到经纬度后根据实际业务做处理,下面业务逻辑仅供参考

                    // 1、先把经纬度存入缓存中
                    // this.setLocation(res)
                    // 2、获取到经纬度后再请求对应数据
                    // this.getData()
                },
                fail: err => {
                    // 判断是否获取到了定位
                    // this.isLocation = false

                    // 根据不同需求做了两种类型提示,需要根据实际业务修改
                    if (toast) {
                        // this.$u.toast是用的框架里封装的弹出消息
                        let msg = '您已拒绝授权,相关功能会无法使用!'
                        console.log(dayjs().format('YYYY-MM-DD HH:mm:ss'), msg)
                        this.$u.toast(msg)
                        return
                    }
                    //用户已授权,但是获取地理位置失败,提示用户去系统设置中打开定位
                    uni.showModal({
                        title: '提示',
                        content: '请在系统设置中打开定位服务,重新进入小程序!'
                    })
                }
            })
        },
        // todo 定位获取位置信息授权逻辑
        getLocation() {
            let that = this
            // wx.getSetting是获取用户授权的信息的,除了应用在位置信息授权还能应用在用户信息授权等等
            uni.getSetting({
                success: res => {
                    console.log('获取用户的当前授权设置', res.authSetting)
                    // 微信返回 {scope.userLocation: false, scope.address: true, scope.invoice: true, scope.invoiceTitle: true, scope.userInfo: true}
                    // 支付宝返回 {location: false}
                    // 用户没有打开过小程序的位置授权设置时,支付宝没有location属性,微信没有scope.userLocation属性
                    // true说明已经授权,如果还拿不到定位信息,说明用户的手机没开启定位功能
                    let location = undefined
                    // #ifdef MP-WEIXIN
                    if (res.authSetting.hasOwnProperty('scope.userLocation')) location = res.authSetting['scope.userLocation']
                    // #endif
                    // #ifdef MP-ALIPAY
                    if (res.authSetting.hasOwnProperty('location')) location = res.authSetting['location']
                    // #endif
                    if (location === true) {
                        console.log('已经授权,非第一次')
                        //授权后默认加载,直接获取定位
                        that.handleLoacation()
                    }
                    // location === undefined 代表用户未授权且第一次登陆
                    else if (location === undefined) {
                        // 如果用户是第一次登陆且未授权的情况,会直接弹窗请求授权
                        // 使用 getlocation 获取用户 经纬度位置
                        console.log('第一次登陆且未授权')
                        that.handleLoacation(true)
                    }
                    // 小程序检测到用户不是第一次进入该页面,且未授权
                    else if (location !== undefined && location !== true) {
                        console.log('不是第一次进入该页面,且未授权')
                        that.handleLocationPermission()
                    }
                },
                fail: err => {
                    let msg = '未知错误,请重新打开小程序!'
                    console.log(dayjs().format('YYYY-MM-DD HH:mm:ss'), msg)
                    uni.showModal({
                        title: '提示',
                        content: msg
                    })
                }
            })
        },
        // todo 请求用户授权地理位置信息
        handleLocationPermission() {
            let that = this
            uni.showModal({
                title: '是否授权当前位置',
                content: '需要获取您的地理位置,请确认授权,否则无法获取门店数据',
                success: res => {
                    // 如果点击取消则显示授权失败
                    if (res.cancel) {
                        let msg = '您已拒绝授权!'
                        console.log(dayjs().format('YYYY-MM-DD HH:mm:ss'), msg)
                        this.$u.toast(msg)
                    }
                    // 如果点击确定会打开授权页请求二次授权
                    else if (res.confirm) {
                        uni.openSetting({
                            success: data => {
                                console.log('调起客户端小程序设置界面,返回用户设置的操作结果', data.authSetting)
                                // 微信返回 {scope.userLocation: false}
                                // 支付宝返回 {location: false, userInfo: false}
                                let location = undefined
                                // #ifdef MP-WEIXIN
                                if (data.authSetting.hasOwnProperty('scope.userLocation')) location = data.authSetting['scope.userLocation']
                                // #endif
                                // #ifdef MP-ALIPAY
                                if (data.authSetting.hasOwnProperty('location')) location = data.authSetting['location']
                                // #endif
                                if (location === true) {
                                    let msg = '授权成功'
                                    console.log(dayjs().format('YYYY-MM-DD HH:mm:ss'), msg)
                                    uni.showToast({
                                        title: msg,
                                        icon: 'success',
                                        duration: 2500
                                    });
                                    //再次授权,调用getLocationt的API
                                    that.handleLoacation()
                                } else {
                                    let msg = '授权失败'
                                    console.log(dayjs().format('YYYY-MM-DD HH:mm:ss'), msg)
                                    this.$u.toast(msg)
                                }
                            }
                        })
                    }
                }
            })
        },

Jquery Ajax设置withCredentials解决跨域请求
后端代码:

httpResponse.setHeader("Access-Control-Allow-Origin", httpServletRequest.getHeader("Origin"));
httpResponse.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");

前端代码:

 $.ajax({
            url: "http://localhost:8080/orders",
            type: "GET",
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
            success: function (data) {
                render(data);
            }
 });

跨域请求想要带上cookies必须在请求头里面加上{crossDomain: true, xhrFields: {withCredentials: true}}设置。

相关文章:https://blog.csdn.net/cckevincyh/article/details/81140443

先刷系统到miui9 7.11.16版本(hm2a的最后一个开发版)

hm2a只能刷到安卓4.4.4不支持安卓5的系统

打开开发版系统自带的root功能,然后网上找“一键解锁system.bat”进行完全root。之后直接使用系统自带的root管理权限。

安装Xposed框架,网上找“XposedInstaller_2.6.1_MIUI8.apk”必须安装miui专用的框架。

安装情迁红包1.5.5插件,网上找“cn.qssq666.redpacket_v73_12108f_0.apk”该插件完美匹配“QQ7.5.0.apk”,但是此插件匹配的微信已被限制登录。

这里微信新版本也限制在安卓4.4版本上安装,目前安卓4.4能使用的最后微信版本为7.0.6(该版本不匹配情迁红包1.5.5)打开插件后微信自动闪退。

总结:
QQ插件与微信不能同时使用!