c-pop-auth.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <view class="mask" catchtouchmove="true" :class="maskState===0 ? 'none' : maskState===1 ? 'show' : ''" @click.stop="maskClickHandel">
  3. <view class="mask-content" @click.stop.prevent="stopPrevent">
  4. <view class="mask-content-inner">
  5. <view class="head">
  6. <view class="icon" hover-class="hover" hover-stay-time="100" @click="maskClickHandel">
  7. <u-icon name="arrow-left" color="#000" size="28"></u-icon>
  8. </view>
  9. <view class="head__text">用户登陆</view>
  10. </view>
  11. <view class="body">
  12. <view class="autho-info">获取微信用户信息</view>
  13. <view class="explain-info">
  14. <text class="text">为了更好的为您服务,需要获取您的头像和昵称</text>
  15. </view>
  16. </view>
  17. <view class="action-wrap">
  18. <u-button type="primary" openType="getUserInfo" @getuserinfo="getUserInfo" shape="round" size="large" text="微信用户一键登录" @click="getUserInfo2"></u-button>
  19. </view>
  20. <view class="action-msg">
  21. <c-radio v-model="isAuth"></c-radio>
  22. <view class="action-msg-textwrap" style="padding-left: 10rpx;">
  23. <text class="text-info" style="margin-left: 0rpx;" @click="isAuth = !isAuth">登录代表您已同意</text>
  24. <text class="text-warning" style="margin-left: 10rpx;" @click="getContract(1)">《服务协议》</text>
  25. <text class="text-info">、</text>
  26. <text class="text-warning" style="margin-left: 10rpx;" @click="getContract(2)">《隐私政策》</text>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- <u-code :seconds="seconds" @end="end" @start="start" ref="uCode" @change="codeChange"></u-code> -->
  32. <u-toast ref="uToast"></u-toast>
  33. </view>
  34. </template>
  35. <script>
  36. import { mapActions, mapState, mapGetters } from 'vuex';
  37. export default {
  38. name:"c-pop-auth",
  39. data() {
  40. return {
  41. maskState: 0,
  42. isAuth: false,
  43. tips: '获取验证码',
  44. seconds: 60,
  45. send: false,
  46. form: {
  47. phone: '',
  48. code: '',
  49. }
  50. };
  51. },
  52. props: {
  53. onComplate: {
  54. type: Function,
  55. default(){
  56. return () => { }
  57. }
  58. },
  59. },
  60. computed: {
  61. ...mapGetters(['isLogin'])
  62. },
  63. mounted() {
  64. },
  65. methods: {
  66. ...mapActions({
  67. 'login': 'login',
  68. 'loginRefresh': 'loginRefresh',
  69. 'cacheUserInfo': 'cacheUserInfo',
  70. }),
  71. stopPrevent(){
  72. },
  73. toggleMask(type){
  74. let timer = type === 'show' ? 10 : 0;
  75. let state = type === 'show' ? 1 : 0;
  76. this.maskState = 2;
  77. setTimeout(()=>{
  78. this.maskState = state;
  79. }, timer)
  80. },
  81. /**
  82. * @description 确认
  83. * @param {Object} title: String desc: String
  84. */
  85. $confirm(options = {}){
  86. console.log("启动权限校验")
  87. this.appInstance = getApp()
  88. // 继承原来的
  89. // this.defautlOptions = Object.assign(this.defautlOptions, options);
  90. return new Promise((resolve,reject)=> {
  91. if(!this.isLogin){
  92. wx.hideTabBar()
  93. this.toggleMask('show')
  94. }
  95. console.log(this.appInstance)
  96. // wx 事件监听确认
  97. this.appInstance._confirm = () => {
  98. resolve(1)
  99. this._confirm = null;
  100. }
  101. // wx 事件监听取消
  102. this.appInstance._cancel = () => {
  103. resolve(0)
  104. this._cancel = null;
  105. }
  106. console.log(this.isLogin, '用户判断是否')
  107. if(this.isLogin){
  108. this.confirm()
  109. }
  110. })
  111. },
  112. confirm() {
  113. wx.showTabBar()
  114. // 发送事件
  115. if(this.appInstance._confirm){
  116. this.appInstance._confirm()
  117. this.toggleMask();
  118. }
  119. },
  120. cancel() {
  121. wx.showTabBar()
  122. // 发送事件
  123. if(this.appInstance._cancel){
  124. this.appInstance._cancel()
  125. this.toggleMask();
  126. }
  127. },
  128. getUserInfo2(e) {
  129. if(this.isAuth){
  130. uni.getUserProfile({
  131. desc: "用于完善会员资料",
  132. lang: "zh_CN",
  133. success: (e) => {
  134. console.log('-----允许获取用户信息------')
  135. this.$refs.uToast.show({
  136. type: 'loading',
  137. message: '正在登录,请稍后',
  138. })
  139. this.cacheUserInfo({detail: e}).then(res => {
  140. this.$refs.uToast.hide()
  141. // uni.$u.toast('登录成功')
  142. // if(res.code == 1){
  143. // // 这里此提示会被this.start()方法中的提示覆盖
  144. // // 通知验证码组件内部开始倒计时
  145. // this.$refs.uCode.start()
  146. // }
  147. // 直接登陆
  148. if(res == 2){
  149. this.confirm();
  150. this.toggleMask();
  151. this.onComplate();
  152. } else {
  153. this.toggleMask();
  154. this.onComplate();
  155. }
  156. })
  157. },
  158. fail: (e) => {
  159. console.log('-----拒绝获取用户信息------')
  160. console.log(e)
  161. }
  162. })
  163. } else {
  164. uni.$u.toast('需要同意协议')
  165. }
  166. },
  167. async getUserInfo(e) {
  168. // const {userInfo, signature} = e.detail;
  169. // // 如果同意登陆 表示可以登录
  170. // wx.getUserProfile((e) => {
  171. // console.log(e)
  172. // })
  173. // return
  174. },
  175. maskClickHandel(e) {
  176. this.cancel()
  177. },
  178. getContract(type){
  179. this.$u.route({
  180. url: '/pages/signs/contract/contract',
  181. type: "navigateTo",
  182. params: {
  183. type: type
  184. }
  185. })
  186. },
  187. end() {
  188. this.send = false;
  189. },
  190. start() {
  191. this.send = true;
  192. },
  193. loginAction() {
  194. }
  195. },
  196. }
  197. </script>
  198. <style lang="scss" scoped>
  199. .mask{
  200. display: flex;
  201. flex-direction: column;
  202. align-items: flex-end;
  203. justify-content: flex-end;
  204. position: fixed;
  205. left: 0;
  206. top: var(--window-top);
  207. bottom: 0;
  208. width: 100vw;
  209. height: 100vh;
  210. background: rgba(0,0,0,0);
  211. z-index: 10001;
  212. transition: .3s;
  213. .mask-content{
  214. background-color: #fff;
  215. width: 100vw;
  216. align-self: stretch;
  217. min-height: 597rpx;
  218. transform: translateY(1597rpx);
  219. }
  220. &.none{
  221. display: none;
  222. }
  223. &.show{
  224. background: rgba(0,0,0,.6);
  225. .mask-content{
  226. transform: translateY(0);
  227. }
  228. }
  229. .mask-content-inner{
  230. position: relative;
  231. display: flex;
  232. flex-direction: column;
  233. align-items: center;
  234. .head{
  235. align-self: stretch;
  236. padding: 0 15rpx;
  237. display: flex;
  238. align-items: center;
  239. height: 94rpx;
  240. border-bottom: 1px solid #efefef;
  241. .icon{
  242. display: flex;
  243. justify-content: center;
  244. align-content: center;
  245. width: 60rpx;
  246. height: 60rpx;
  247. margin-right: 30rpx;
  248. &.hover{
  249. background-color: #efefef;
  250. }
  251. }
  252. .head__text{
  253. font-size: 32rpx;
  254. color: #333;
  255. }
  256. }
  257. .body{
  258. align-self: stretch;
  259. padding-top: 40rpx;
  260. padding-left: 30rpx;
  261. padding-right: 30rpx;
  262. display: flex;
  263. flex-direction: column;
  264. .autho-info{
  265. font-size: 38rpx;
  266. color: #000;
  267. font-weight: 500;
  268. }
  269. .explain-info{
  270. padding-top: 15rpx;
  271. padding-left: 10rpx;
  272. .text{
  273. color: #999;
  274. font-size: 24rpx;
  275. }
  276. .link{
  277. color: #FD8701;
  278. font-size: 24rpx;
  279. }
  280. }
  281. }
  282. .action-wrap{
  283. margin-top: 60rpx;
  284. padding: 0 30rpx;
  285. align-self: stretch;
  286. }
  287. .action-msg{
  288. margin-top: 10rpx;
  289. display: flex;
  290. padding: 0 40rpx;
  291. flex-direction: row;
  292. align-items: center;
  293. .action-msg-textwrap{
  294. display: flex;
  295. flex-direction: row;
  296. flex-wrap: wrap;
  297. display: flex;
  298. flex-direction: row;
  299. font-size:24rpx;
  300. }
  301. }
  302. }
  303. }
  304. .c-button {
  305. color: #fff;
  306. width: 510rpx;
  307. margin-top: 20rpx;
  308. }
  309. .c-input-wrap{
  310. margin: 0 auto;
  311. width: 510rpx;
  312. height: 70rpx;
  313. background-color: #F0F2F4;
  314. border-radius: 35px;
  315. padding: 0 14px;
  316. box-sizing: border-box;
  317. margin-bottom: 30rpx;
  318. display: flex;
  319. align-items: center;
  320. .divide{
  321. width: 1px;
  322. height: 40rpx;
  323. border-left: 1px solid #FD8701;
  324. }
  325. .tip-btn{
  326. text-align: center;
  327. min-width: 178rpx;
  328. flex-shrink: 0;
  329. font-size: 24rpx;
  330. font-family: PingFang SC;
  331. font-weight: 500;
  332. color: #FD8701;
  333. &.disable{
  334. color: #999;
  335. }
  336. }
  337. & /deep/ .inner_input{
  338. display: flex;
  339. height: 100%;
  340. }
  341. }
  342. </style>