authorize.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <view class="container">
  3. <u-cell-group :border="false">
  4. <u-cell-item title="未注册" value="点击注册" @click="goToRegister()" v-if="!haveAuthorizeCode"></u-cell-item>
  5. <u-cell-item title="是否拥有授权码" :arrow="false">
  6. <u-switch v-model="haveAuthorizeCode" active-color="#51A539"></u-switch>
  7. </u-cell-item>
  8. <u-field label="授权码" placeholder="请输入授权码" v-model="authorizeCode" v-if="haveAuthorizeCode"></u-field>
  9. </u-cell-group>
  10. <view class="form-handle" v-if="haveAuthorizeCode">
  11. <u-button type="success" shape="circle" :ripple="true" @click="goToSignIn" class="handle-custom" :disabled="!authorizeCode">登录</u-button>
  12. </view>
  13. <u-top-tips ref="uTips"></u-top-tips>
  14. </view>
  15. </template>
  16. <script>
  17. const NET = require('@/utils/request')
  18. const API = require('@/config/api')
  19. export default {
  20. data() {
  21. return {
  22. haveAuthorizeCode: false,
  23. authorizeCode: '',
  24. }
  25. },
  26. onLoad() {},
  27. methods: {
  28. // 注册
  29. goToRegister() {
  30. uni.navigateTo({
  31. url: '/pages/index/register?type=add'
  32. });
  33. },
  34. // 登录
  35. goToSignIn() {
  36. NET.request(API.authorizeSignIn, {authCode: this.authorizeCode}, 'GET').then(res => {
  37. this.$refs.uTips.show({
  38. title: '授权码登录成功,请重新登录',
  39. type: 'success',
  40. })
  41. setTimeout(() => {
  42. uni.switchTab({
  43. url: '/pages/index/index'
  44. });
  45. }, 2000)
  46. }).catch(res => {
  47. this.$refs.uTips.show({
  48. title: '授权码登录失败',
  49. type: 'warning',
  50. })
  51. })
  52. },
  53. },
  54. }
  55. </script>
  56. <style lang="less" scoped>
  57. page {
  58. width: 100%;
  59. height: 100%;
  60. }
  61. .container {
  62. width: 100%;
  63. height: 100%;
  64. float: left;
  65. box-sizing: border-box;
  66. padding-bottom: 70px;
  67. overflow-y: auto;
  68. .form-handle {
  69. width: calc(100% - 30px);
  70. height: 40px;
  71. position: fixed;
  72. bottom: 20px;
  73. left: 15px;
  74. .handle-custom {
  75. background-color: #51A539;
  76. }
  77. /deep/.u-btn--success--disabled {
  78. background-color: #999999 !important;
  79. }
  80. }
  81. }
  82. </style>