login-withoutpwd.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <!-- 免密登录页 -->
  2. <template>
  3. <view class="uni-content">
  4. <view class="login-logo">
  5. <image :src="logo"></image>
  6. </view>
  7. <!-- 顶部文字 -->
  8. <text class="title">请选择登录方式</text>
  9. <!-- 快捷登录框 当url带参数时有效 -->
  10. <template v-if="['apple','weixin', 'weixinMobile'].includes(type)">
  11. <text class="tip">将根据第三方账号服务平台的授权范围获取你的信息</text>
  12. <view class="quickLogin">
  13. <image v-if="type !== 'weixinMobile'" @click="quickLogin" :src="imgSrc" mode="widthFix"
  14. class="quickLoginBtn"></image>
  15. <button v-else type="primary" open-type="getPhoneNumber" @getphonenumber="quickLogin"
  16. class="uni-btn">微信授权手机号登录</button>
  17. <uni-id-pages-agreements scope="register" ref="agreements"></uni-id-pages-agreements>
  18. </view>
  19. </template>
  20. <template v-else>
  21. <text class="tip">未注册的账号验证通过后将自动注册</text>
  22. <view class="phone-box">
  23. <view @click="chooseArea" class="area">+86</view>
  24. <uni-easyinput :focus="focusPhone" @blur="focusPhone = false" class="input-box" type="number"
  25. :inputBorder="false" v-model="phone" maxlength="11" placeholder="请输入手机号" />
  26. </view>
  27. <uni-id-pages-agreements scope="register" ref="agreements"></uni-id-pages-agreements>
  28. <button class="uni-btn" type="primary" @click="toSmsPage">获取验证码</button>
  29. </template>
  30. <!-- 固定定位的快捷登录按钮 -->
  31. <uni-id-pages-fab-login ref="uniFabLogin"></uni-id-pages-fab-login>
  32. </view>
  33. </template>
  34. <script>
  35. let currentWebview; //当前窗口对象
  36. import config from '@/uni_modules/uni-id-pages/config.js'
  37. import mixin from '@/uni_modules/uni-id-pages/common/login-page.mixin.js';
  38. export default {
  39. mixins: [mixin],
  40. data() {
  41. return {
  42. type: "", //快捷登录方式
  43. phone: "", //手机号码
  44. focusPhone: false,
  45. logo: "/static/logo.png"
  46. }
  47. },
  48. computed: {
  49. async loginTypes() { //读取配置的登录优先级
  50. return config.loginTypes
  51. },
  52. isPhone() { //手机号码校验正则
  53. return /^1\d{10}$/.test(this.phone);
  54. },
  55. imgSrc() { //大快捷登录按钮图
  56. return this.type == 'weixin' ? '/uni_modules/uni-id-pages/static/login/weixin.png' :
  57. '/uni_modules/uni-id-pages/static/app-plus/apple.png'
  58. }
  59. },
  60. async onLoad(e) {
  61. //获取通过url传递的参数type设置当前登录方式,如果没传递直接默认以配置的登录
  62. let type = e.type || config.loginTypes[0]
  63. this.type = type
  64. // console.log("this.type: -----------",this.type);
  65. if (type != 'univerify') {
  66. this.focusPhone = true
  67. }
  68. this.$nextTick(() => {
  69. //关闭重复显示的登录快捷方式
  70. if (['weixin', 'apple'].includes(type)) {
  71. this.$refs.uniFabLogin.servicesList = this.$refs.uniFabLogin.servicesList.filter(item =>
  72. item.id != type)
  73. }
  74. })
  75. uni.$on('uni-id-pages-setLoginType', type => {
  76. this.type = type
  77. })
  78. },
  79. onShow() {
  80. // #ifdef H5
  81. document.onkeydown = event => {
  82. let e = event || window.event;
  83. if (e && e.keyCode == 13) { //回车键的键值为13
  84. this.toSmsPage()
  85. }
  86. };
  87. // #endif
  88. },
  89. onUnload() {
  90. uni.$off('uni-id-pages-setLoginType')
  91. },
  92. onReady() {
  93. // 是否优先启动一键登录。即:页面一加载就启动一键登录
  94. //#ifdef APP-PLUS
  95. if (this.type == "univerify") {
  96. const pages = getCurrentPages();
  97. currentWebview = pages[pages.length - 1].$getAppWebview();
  98. currentWebview.setStyle({
  99. "top": "2000px" // 隐藏当前页面窗体
  100. })
  101. this.type == this.loginTypes[1]
  102. // console.log('开始一键登录');
  103. this.$refs.uniFabLogin.login_before('univerify')
  104. }
  105. //#endif
  106. },
  107. methods: {
  108. showCurrentWebview(){
  109. // 恢复当前页面窗体的显示 一键登录,默认不显示当前窗口
  110. currentWebview.setStyle({
  111. "top": 0
  112. })
  113. },
  114. quickLogin(e) {
  115. let options = {}
  116. if (e.detail?.code) {
  117. options.phoneNumberCode = e.detail.code
  118. }
  119. if (this.type === 'weixinMobile' && !e.detail?.code) return
  120. this.$refs.uniFabLogin.login_before(this.type, true, options)
  121. },
  122. toSmsPage() {
  123. if (!this.isPhone) {
  124. this.focusPhone = true
  125. return uni.showToast({
  126. title: "手机号码格式不正确",
  127. icon: 'none',
  128. duration: 3000
  129. });
  130. }
  131. if (this.needAgreements && !this.agree) {
  132. return this.$refs.agreements.popup(this.toSmsPage)
  133. }
  134. // 发送验证吗
  135. uni.navigateTo({
  136. url: '/uni_modules/uni-id-pages/pages/login/login-smscode?phoneNumber=' + this.phone
  137. });
  138. },
  139. //去密码登录页
  140. toPwdLogin() {
  141. uni.navigateTo({
  142. url: '../login/password'
  143. })
  144. },
  145. chooseArea() {
  146. uni.showToast({
  147. title: '暂不支持其他国家',
  148. icon: 'none',
  149. duration: 3000
  150. });
  151. },
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. @import "@/uni_modules/uni-id-pages/common/login-page.scss";
  157. @media screen and (min-width: 690px) {
  158. .uni-content {
  159. height: 350px;
  160. }
  161. }
  162. .uni-content,
  163. .quickLogin {
  164. /* #ifndef APP-NVUE */
  165. display: flex;
  166. flex-direction: column;
  167. /* #endif */
  168. }
  169. .phone-box {
  170. position: relative;
  171. /* #ifndef APP-NVUE */
  172. display: flex;
  173. /* #endif */
  174. }
  175. .area {
  176. position: absolute;
  177. left: 10px;
  178. z-index: 9;
  179. top: 12px;
  180. font-size: 14px;
  181. }
  182. .area::after {
  183. content: "";
  184. border: 3px solid transparent;
  185. border-top-color: #000;
  186. top: 12px;
  187. left: 3px;
  188. position: relative;
  189. }
  190. /* #ifdef MP */
  191. // 解决小程序端开启虚拟节点virtualHost引起的 class = input-box丢失的问题 [详情参考](https://uniapp.dcloud.net.cn/matter.html#%E5%90%84%E5%AE%B6%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%AE%9E%E7%8E%B0%E6%9C%BA%E5%88%B6%E4%B8%8D%E5%90%8C-%E5%8F%AF%E8%83%BD%E5%AD%98%E5%9C%A8%E7%9A%84%E5%B9%B3%E5%8F%B0%E5%85%BC%E5%AE%B9%E9%97%AE%E9%A2%98)
  192. .phone-box ::v-deep .uni-easyinput__content,
  193. /* #endif */
  194. .input-box {
  195. /* #ifndef APP-NVUE */
  196. box-sizing: border-box;
  197. /* #endif */
  198. flex: 1;
  199. padding-left: 45px;
  200. margin-bottom: 10px;
  201. border-radius: 0;
  202. }
  203. .quickLogin {
  204. height: 350px;
  205. align-items: center;
  206. justify-content: center;
  207. }
  208. .quickLoginBtn {
  209. margin: 20px 0;
  210. width: 450rpx;
  211. /* #ifndef APP-NVUE */
  212. max-width: 230px;
  213. /* #endif */
  214. height: 82rpx;
  215. }
  216. .tip {
  217. margin-top: -15px;
  218. margin-bottom: 20px;
  219. }
  220. @media screen and (min-width: 690px) {
  221. .quickLogin {
  222. height: auto;
  223. }
  224. }
  225. </style>