login.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="app-page bg-white flex flex-col flex-center">
  3. <view class="content pt-36 pb-36 pl-12 pr-12 bg-white round-6">
  4. <tm-form @submit="submit">
  5. <tm-sheet :shadow="0" :margin="[0, 0]" :padding="[0, 0]">
  6. <view class="text-weight-b text-size-xl ma-24 mb-36 text-align-center text-bg-gradient-light-blue-accent">登录后台管理</view>
  7. <image v-if="false" class="avatar " :src="$utils.checkAvatarUrl(bloggerInfo.avatar)" mode="aspectFill" @click="miniProfileCard.show = true"></image>
  8. <tm-input
  9. :round="12"
  10. color="grey"
  11. bg-color="grey-lighten-5"
  12. :border-bottom="false"
  13. required
  14. prefixp-icon="icon-account"
  15. :vertical="true"
  16. :clear="true"
  17. name="username"
  18. v-model="form.username"
  19. placeholder="请输入用户名"
  20. :focus="true"
  21. :verify="verifyUsername"
  22. ></tm-input>
  23. <tm-input
  24. :round="12"
  25. color="grey"
  26. bg-color="grey-lighten-5"
  27. :border-bottom="false"
  28. required
  29. prefixp-icon="icon-lock"
  30. :vertical="true"
  31. :clear="true"
  32. name="password"
  33. input-type="password"
  34. v-model="form.password"
  35. placeholder="请输入登录密码"
  36. :verify="verifyPassword"
  37. ></tm-input>
  38. <view class="pa-24 mt-12 pl-30 pr-30">
  39. <tm-button :round="25" navtie-type="form" theme="bg-gradient-blue-accent" block :loading="loading">立即登录</tm-button>
  40. <view v-if="false" class="mt-36 text-size-m text-grey-darken-1 text-align-center" @click="fnFindPassword()">忘记密码?立即重置</view>
  41. </view>
  42. </tm-sheet>
  43. </tm-form>
  44. </view>
  45. <view v-if="showCopyright" class="copyright text-size-s text-grey text-align-center">「 2022 uni-halo 丨 开源项目@小莫唐尼 」</view>
  46. <image class="top" src="@/static/login/login_top2.jpg" mode="aspectFill"></image>
  47. <image class="bottom" src="@/static/login/login_bottom_bg.jpg" mode="aspectFill"></image>
  48. </view>
  49. </template>
  50. <script>
  51. import tmForm from '@/tm-vuetify/components/tm-form/tm-form.vue';
  52. import tmInput from '@/tm-vuetify/components/tm-input/tm-input.vue';
  53. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  54. import tmSheet from '@/tm-vuetify/components/tm-sheet/tm-sheet.vue';
  55. export default {
  56. components: { tmSheet, tmForm, tmInput, tmButton },
  57. data() {
  58. return {
  59. loading: false,
  60. form: {
  61. // authcode: '', // 二次验证
  62. username: undefined,
  63. password: undefined
  64. },
  65. verifyUsername: () => {
  66. return val => {
  67. return {
  68. check: val != ''
  69. // text: '错误提示:请输入用户名!'
  70. };
  71. };
  72. },
  73. verifyPassword: () => {
  74. return val => {
  75. return {
  76. check: val != ''
  77. // text: '错误提示:请输入登录密码!'
  78. };
  79. };
  80. }
  81. };
  82. },
  83. computed: {
  84. bloggerInfo() {
  85. return this.$tm.vx.getters().getBlogger;
  86. },
  87. showCopyright() {
  88. return getApp().globalData.showCopyright;
  89. }
  90. },
  91. onBackPress() {
  92. uni.switchTab({
  93. url: '/pages/tabbar/about/about'
  94. });
  95. },
  96. methods: {
  97. submit(e) {
  98. if (e === false) return uni.$tm.toast('请检查用户名和密码!');
  99. uni.showLoading({
  100. title: '登录中...',
  101. mask: true
  102. });
  103. this.loading = true;
  104. uni.$tm.vx
  105. .actions('user/adminLogin', this.form)
  106. .then(res => {
  107. if (res.status == 200) {
  108. uni.showToast({
  109. mask: true,
  110. icon: 'none',
  111. title: '登录成功,正在跳转...'
  112. });
  113. setTimeout(() => {
  114. uni.redirectTo({
  115. url: '/pagesB/admin/admin'
  116. });
  117. }, 1200);
  118. } else {
  119. uni.$tm.toast('登录失败:' + res.message);
  120. this.loading = false;
  121. }
  122. })
  123. .catch(err => {
  124. uni.$tm.toast('登录失败:' + err.message);
  125. this.loading = false;
  126. });
  127. },
  128. fnFindPassword() {
  129. uni.$tm.toast('找回密码功能');
  130. }
  131. }
  132. };
  133. </script>
  134. <style scoped lang="scss">
  135. .app-page {
  136. position: relative;
  137. width: 100vw;
  138. min-height: 100vh;
  139. .top {
  140. position: absolute;
  141. left: 0;
  142. top: 0;
  143. width: 100vw;
  144. height: 45vh;
  145. z-index: 0;
  146. }
  147. .bottom {
  148. position: absolute;
  149. left: 0;
  150. bottom: 0;
  151. width: 100vw;
  152. }
  153. .content {
  154. position: relative;
  155. box-sizing: border-box;
  156. box-shadow: 0rpx 2rpx 24rpx rgba(0, 0, 0, 0.07);
  157. z-index: 2;
  158. width: 82vw;
  159. .avatar {
  160. position: absolute;
  161. left: 50%;
  162. top: -75rpx;
  163. transform: translateX(-50%);
  164. width: 150rpx;
  165. height: 150rpx;
  166. box-sizing: border-box;
  167. border: 6rpx solid #fff;
  168. box-shadow: 0rpx 4rpx 48rpx rgba(13, 179, 242, 0.07);
  169. border-radius: 50%;
  170. }
  171. }
  172. .copyright {
  173. position: absolute;
  174. bottom: 24rpx;
  175. left: 0;
  176. width: 100vw;
  177. z-index: 2;
  178. }
  179. }
  180. </style>