123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- <template>
- <view>
- <navbar :config="config" backColor="#999999"></navbar>
- <view class="list">
- <view class="item" @click="goChangeAccount(1)">
- <view class="item_l">注销账户</view>
- <view class="item_r">
- <view class="tig">请谨慎操作</view>
- <text class="iconfont_yige"></text>
- </view>
- </view>
- <view class="item" @click="goChangeAccount(2)">
- <view class="item_l">更换手机号</view>
- <view class="item_r">
- <view>{{user.mobile}}</view>
- <text class="iconfont_yige"></text>
- </view>
- </view>
- </view>
- <!-- <view class="title">
- 第三方绑定
- </view> -->
- <view class="list">
- <view class="item">
- <view class="item_l">第三方绑定</view>
- <view class="item_r">
- <!-- <text class="iconfont_yige"></text> -->
- </view>
- </view>
- <view class="item" @click="isOpenUnbindShow(0)" v-if="isInstallWx||platform!='ios'">
- <view class="item_l">微信</view>
- <view class="item_r">
- <view>{{thirdBindingInfo.bindingWechat?'已绑定':'去授权'}}</view>
- <text class="iconfont_yige"></text>
- </view>
- </view>
- <view class="item" @click="isOpenUnbindShow(1)" v-if="isInstallZfb||platform!='ios'">
- <view class="item_l">支付宝</view>
- <view class="item_r">
- <view>{{thirdBindingInfo.bindingAlipay?'已绑定':'去授权'}}</view>
- <text class="iconfont_yige"></text>
- </view>
- </view>
- <view class="item" v-if="osVersion >= 13 && platform=='ios'" @click="isOpenUnbindShow(3)">
- <view class="item_l">苹果</view>
- <view class="item_r">
- <view>{{thirdBindingInfo.bindingApple?'已绑定':'去授权'}}</view>
- <text class="iconfont_yige"></text>
- </view>
- </view>
- </view>
- <u-modal v-model="unbindShow" :content="'确认解绑'+showThirdLab(thirdType)+'?'" show-cancel-button @confirm="unbind()" @cancel="unbindShow=false" confirm-color="#3EBCD0"></u-modal>
- </view>
- </template>
- <script>
- import {
- getUserInfo
- } from "@/api/government.js"
- export default {
- data() {
- return {
- config: {
- back: true, //false是tolbar页面 是则不写
- title: '账号安全',
- color: '#000',
- rightSlot: true,
- },
- user: {},
- unbindShow:false,
- thirdType:0,//0 微信 1支付宝
- thirdBindingInfo:{},
- osVersion:"",
- platform:"",
- thirdList:[
- {label:"微信",value:0},
- {label:"支付宝",value:1},
- {label:"苹果",value:3}
- ],
- isInstallWx:true,//是否安装微信
- isInstallZfb:true,//是否安装支付宝
- }
- },
- onLoad() {
- // 先判断 系统版本
- uni.getSystemInfo({
- success: (res) => {
- this.osVersion = res.osVersion
- this.platform = res.platform
- }
- })
- this.isInstallWx=plus.runtime.isApplicationExist({pname:'com.tencent.mm',action:'weixin://'});
- this.isInstallZfb=plus.runtime.isApplicationExist({pname:'com.eg.android.AlipayGphone',action:'alipay://'});
- },
- onShow() {
- this.getUserData();
- this.getThirdBindingInfo()
- },
- methods: {
- showThirdLab(e){
- for(let i=0;i<this.thirdList.length;i++){
- if(this.thirdList[i].value==e){
- return this.thirdList[i].label
- }
- }
- },
- goChangeAccount(val) {
- uni.navigateTo({
- url: "/pages/government/changeAccount?type=" + val + "&mobile=" + this.user.mobile
- })
- },
- getUserData() {
- getUserInfo().then(res => {
- this.user = res.data
- })
- },
- isOpenUnbindShow(e){
- this.thirdType=e;
- if(this.thirdBindingInfo.bindingWechat&&e===0||this.thirdBindingInfo.bindingAlipay&&e===1||this.thirdBindingInfo.bindingApple&&e===3){
- this.unbindShow=true
- }else if(e===0){
- this.WXBind()
- }else if(e===1){
- this.alipayBind()
- }else if(e===3){
- this.appleBind()
- }
- },
- appleBind() {
- // 判断是 iOS13版本
- uni.login({
- provider: 'apple',
- success: (loginRes) => {
- uni.getUserInfo({
- provider: 'apple',
- success: (userInfoRes) => {
- let param = {
- code: userInfoRes.userInfo.identityToken,
- thirdType: 3
- }
- this.$yghttp.post('/user/binding',param).then(res=>{
- this.getThirdBindingInfo()
- uni.showToast({
- title: '绑定成功!',
- icon: 'success',
- duration: 1500
- })
- })
- },
- fail: (err) => {
- console.log(err)
- }
- })
- },
- fail: (err) => {
- console.log(err)
- }
- })
- },
- WXBind(){
- uni.login({
- "provider": "weixin",
- "onlyAuthorize": true, // 微信登录仅请求授权认证
- success: (event)=>{
- const {code} = event
- // console.log(event)
- //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
- let param={
- thirdType:this.thirdType,
- code:code
- }
- this.$yghttp.post('/user/binding',param).then(res=>{
- this.getThirdBindingInfo()
- uni.showToast({
- title: '绑定成功!',
- icon: 'success',
- duration: 1500
- })
- })
-
- },
- fail:(err)=>{
- console.log(err)
- // 登录授权失败
- // err.code是错误码
- this.$u.toast('当前环境不支持微信操作!');
- }
- })
-
- },
- alipayBind(){
- const AlipayAuth = uni.requireNativePlugin("DHQ-AlipayAuth");
- AlipayAuth.login({
- appId: '2021004128667996', //你在支付宝平台申请的App ID
- scheme: 'ygfwUrlSchemes', // 需要传到支付宝SDK的scheme,注意需要在manifest.json-->App其他常用配置-->UrlSchemes中配置Android和iOS的
- scope: 'auth_user', //默认为auth_user
- init: 'init' //默认传入init
- },
- (res) => {
- //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
- let code = res.auth_code;
- if(code){
- let param={
- code:code,
- thirdType:this.thirdType
- }
- this.$yghttp.post('/user/binding',param).then(res=>{
- this.getThirdBindingInfo()
- uni.showToast({
- title: '绑定成功!',
- icon: 'success',
- duration: 1500
- })
- })
- }
- },(e)=>{
- this.$u.toast('当前环境不支持支付宝操作!');
- })
- },
- unbind(){
- let param={
- thirdType:this.thirdType,
- }
- this.$yghttp.post('/user/unbind',param).then(res=>{
- this.unbindShow=false;
- this.getThirdBindingInfo()
- uni.showToast({
- title: '解绑成功!',
- icon: 'success',
- duration: 1500
- })
- })
- },
- // 第三方身份绑定信息
- getThirdBindingInfo(){
- this.$yghttp.get('/user/thirdBindingInfo').then(res=>{
- this.thirdBindingInfo=res.data
- })
- }
- }
- }
- </script>
- <style>
- page {
- background-color: #F8F8F8;
- }
- </style>
- <style lang="scss" scoped>
- .list {
- padding: 0rpx 40rpx;
- background: #fff;
- border-radius: 20rpx;
- margin: 30rpx;
- .item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 40rpx 0rpx;
- border-bottom: 1rpx solid rgba(239, 239, 239, .6);
- &:last-child{
- border-bottom:none;
- }
- .item_l {
- font-size: 30rpx;
- font-weight: 700;
- }
- .item_r {
- display: flex;
- align-items: center;
- .item_r_text {
- margin-right: 30rpx;
- }
- .tig {
- font-weight: 400;
- color: #3EBCD0;
- font-size: 24rpx;
- }
- }
- }
- .title {
- padding: 20rpx 30rpx;
- border-bottom: 1rpx solid rgba(239, 239, 239, .6);
- border-top: 30rpx solid rgba(239, 239, 239, .6);
- }
- }
- .iconfont_yige {
- color: #333333;
- opacity: 0.5;
- font-weight: 700;
- margin-left: 40rpx;
- }
- </style>
|