accountSecurity.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <view>
  3. <navbar :config="config" backColor="#999999"></navbar>
  4. <view class="list">
  5. <view class="item" @click="goChangeAccount(1)">
  6. <view class="item_l">注销账户</view>
  7. <view class="item_r">
  8. <view class="tig">请谨慎操作</view>
  9. <text class="iconfont_yige">&#xe65f;</text>
  10. </view>
  11. </view>
  12. <view class="item" @click="goChangeAccount(2)">
  13. <view class="item_l">更换手机号</view>
  14. <view class="item_r">
  15. <view>{{user.mobile}}</view>
  16. <text class="iconfont_yige">&#xe65f;</text>
  17. </view>
  18. </view>
  19. </view>
  20. <!-- <view class="title">
  21. 第三方绑定
  22. </view> -->
  23. <view class="list">
  24. <view class="item">
  25. <view class="item_l">第三方绑定</view>
  26. <view class="item_r">
  27. <!-- <text class="iconfont_yige">&#xe65f;</text> -->
  28. </view>
  29. </view>
  30. <view class="item" @click="isOpenUnbindShow(0)" v-if="isInstallWx||platform!='ios'">
  31. <view class="item_l">微信</view>
  32. <view class="item_r">
  33. <view>{{thirdBindingInfo.bindingWechat?'已绑定':'去授权'}}</view>
  34. <text class="iconfont_yige">&#xe65f;</text>
  35. </view>
  36. </view>
  37. <view class="item" @click="isOpenUnbindShow(1)" v-if="isInstallZfb||platform!='ios'">
  38. <view class="item_l">支付宝</view>
  39. <view class="item_r">
  40. <view>{{thirdBindingInfo.bindingAlipay?'已绑定':'去授权'}}</view>
  41. <text class="iconfont_yige">&#xe65f;</text>
  42. </view>
  43. </view>
  44. <view class="item" v-if="osVersion >= 13 && platform=='ios'" @click="isOpenUnbindShow(3)">
  45. <view class="item_l">苹果</view>
  46. <view class="item_r">
  47. <view>{{thirdBindingInfo.bindingApple?'已绑定':'去授权'}}</view>
  48. <text class="iconfont_yige">&#xe65f;</text>
  49. </view>
  50. </view>
  51. </view>
  52. <u-modal v-model="unbindShow" :content="'确认解绑'+showThirdLab(thirdType)+'?'" show-cancel-button @confirm="unbind()" @cancel="unbindShow=false" confirm-color="#3EBCD0"></u-modal>
  53. </view>
  54. </template>
  55. <script>
  56. import {
  57. getUserInfo
  58. } from "@/api/government.js"
  59. export default {
  60. data() {
  61. return {
  62. config: {
  63. back: true, //false是tolbar页面 是则不写
  64. title: '账号安全',
  65. color: '#000',
  66. rightSlot: true,
  67. },
  68. user: {},
  69. unbindShow:false,
  70. thirdType:0,//0 微信 1支付宝
  71. thirdBindingInfo:{},
  72. osVersion:"",
  73. platform:"",
  74. thirdList:[
  75. {label:"微信",value:0},
  76. {label:"支付宝",value:1},
  77. {label:"苹果",value:3}
  78. ],
  79. isInstallWx:true,//是否安装微信
  80. isInstallZfb:true,//是否安装支付宝
  81. }
  82. },
  83. onLoad() {
  84. // 先判断 系统版本
  85. uni.getSystemInfo({
  86. success: (res) => {
  87. this.osVersion = res.osVersion
  88. this.platform = res.platform
  89. }
  90. })
  91. this.isInstallWx=plus.runtime.isApplicationExist({pname:'com.tencent.mm',action:'weixin://'});
  92. this.isInstallZfb=plus.runtime.isApplicationExist({pname:'com.eg.android.AlipayGphone',action:'alipay://'});
  93. },
  94. onShow() {
  95. this.getUserData();
  96. this.getThirdBindingInfo()
  97. },
  98. methods: {
  99. showThirdLab(e){
  100. for(let i=0;i<this.thirdList.length;i++){
  101. if(this.thirdList[i].value==e){
  102. return this.thirdList[i].label
  103. }
  104. }
  105. },
  106. goChangeAccount(val) {
  107. uni.navigateTo({
  108. url: "/pages/government/changeAccount?type=" + val + "&mobile=" + this.user.mobile
  109. })
  110. },
  111. getUserData() {
  112. getUserInfo().then(res => {
  113. this.user = res.data
  114. })
  115. },
  116. isOpenUnbindShow(e){
  117. this.thirdType=e;
  118. if(this.thirdBindingInfo.bindingWechat&&e===0||this.thirdBindingInfo.bindingAlipay&&e===1||this.thirdBindingInfo.bindingApple&&e===3){
  119. this.unbindShow=true
  120. }else if(e===0){
  121. this.WXBind()
  122. }else if(e===1){
  123. this.alipayBind()
  124. }else if(e===3){
  125. this.appleBind()
  126. }
  127. },
  128. appleBind() {
  129. // 判断是 iOS13版本
  130. uni.login({
  131. provider: 'apple',
  132. success: (loginRes) => {
  133. uni.getUserInfo({
  134. provider: 'apple',
  135. success: (userInfoRes) => {
  136. let param = {
  137. code: userInfoRes.userInfo.identityToken,
  138. thirdType: 3
  139. }
  140. this.$yghttp.post('/user/binding',param).then(res=>{
  141. this.getThirdBindingInfo()
  142. uni.showToast({
  143. title: '绑定成功!',
  144. icon: 'success',
  145. duration: 1500
  146. })
  147. })
  148. },
  149. fail: (err) => {
  150. console.log(err)
  151. }
  152. })
  153. },
  154. fail: (err) => {
  155. console.log(err)
  156. }
  157. })
  158. },
  159. WXBind(){
  160. uni.login({
  161. "provider": "weixin",
  162. "onlyAuthorize": true, // 微信登录仅请求授权认证
  163. success: (event)=>{
  164. const {code} = event
  165. // console.log(event)
  166. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  167. let param={
  168. thirdType:this.thirdType,
  169. code:code
  170. }
  171. this.$yghttp.post('/user/binding',param).then(res=>{
  172. this.getThirdBindingInfo()
  173. uni.showToast({
  174. title: '绑定成功!',
  175. icon: 'success',
  176. duration: 1500
  177. })
  178. })
  179. },
  180. fail:(err)=>{
  181. console.log(err)
  182. // 登录授权失败
  183. // err.code是错误码
  184. this.$u.toast('当前环境不支持微信操作!');
  185. }
  186. })
  187. },
  188. alipayBind(){
  189. const AlipayAuth = uni.requireNativePlugin("DHQ-AlipayAuth");
  190. AlipayAuth.login({
  191. appId: '2021004128667996', //你在支付宝平台申请的App ID
  192. scheme: 'ygfwUrlSchemes', // 需要传到支付宝SDK的scheme,注意需要在manifest.json-->App其他常用配置-->UrlSchemes中配置Android和iOS的
  193. scope: 'auth_user', //默认为auth_user
  194. init: 'init' //默认传入init
  195. },
  196. (res) => {
  197. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  198. let code = res.auth_code;
  199. if(code){
  200. let param={
  201. code:code,
  202. thirdType:this.thirdType
  203. }
  204. this.$yghttp.post('/user/binding',param).then(res=>{
  205. this.getThirdBindingInfo()
  206. uni.showToast({
  207. title: '绑定成功!',
  208. icon: 'success',
  209. duration: 1500
  210. })
  211. })
  212. }
  213. },(e)=>{
  214. this.$u.toast('当前环境不支持支付宝操作!');
  215. })
  216. },
  217. unbind(){
  218. let param={
  219. thirdType:this.thirdType,
  220. }
  221. this.$yghttp.post('/user/unbind',param).then(res=>{
  222. this.unbindShow=false;
  223. this.getThirdBindingInfo()
  224. uni.showToast({
  225. title: '解绑成功!',
  226. icon: 'success',
  227. duration: 1500
  228. })
  229. })
  230. },
  231. // 第三方身份绑定信息
  232. getThirdBindingInfo(){
  233. this.$yghttp.get('/user/thirdBindingInfo').then(res=>{
  234. this.thirdBindingInfo=res.data
  235. })
  236. }
  237. }
  238. }
  239. </script>
  240. <style>
  241. page {
  242. background-color: #F8F8F8;
  243. }
  244. </style>
  245. <style lang="scss" scoped>
  246. .list {
  247. padding: 0rpx 40rpx;
  248. background: #fff;
  249. border-radius: 20rpx;
  250. margin: 30rpx;
  251. .item {
  252. display: flex;
  253. justify-content: space-between;
  254. align-items: center;
  255. padding: 40rpx 0rpx;
  256. border-bottom: 1rpx solid rgba(239, 239, 239, .6);
  257. &:last-child{
  258. border-bottom:none;
  259. }
  260. .item_l {
  261. font-size: 30rpx;
  262. font-weight: 700;
  263. }
  264. .item_r {
  265. display: flex;
  266. align-items: center;
  267. .item_r_text {
  268. margin-right: 30rpx;
  269. }
  270. .tig {
  271. font-weight: 400;
  272. color: #3EBCD0;
  273. font-size: 24rpx;
  274. }
  275. }
  276. }
  277. .title {
  278. padding: 20rpx 30rpx;
  279. border-bottom: 1rpx solid rgba(239, 239, 239, .6);
  280. border-top: 30rpx solid rgba(239, 239, 239, .6);
  281. }
  282. }
  283. .iconfont_yige {
  284. color: #333333;
  285. opacity: 0.5;
  286. font-weight: 700;
  287. margin-left: 40rpx;
  288. }
  289. </style>