appIndex.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="page" :style="{'min-height':h+'px'}">
  3. <!-- 返回按钮 -->
  4. <c-nav-bar title=" " :showHome="false"></c-nav-bar>
  5. <view class="box">
  6. <view class="text">您好!欢迎使用<br>游嵊泗商家服务平台</view>
  7. <view class="login">
  8. <view class="item">
  9. <u--input
  10. placeholder="用户名"
  11. prefixIcon="account-fill"
  12. prefixIconStyle="font-size: 22px;color: #909399"
  13. labelColor="#ffffff"
  14. v-model="dataFrom.username"
  15. ></u--input>
  16. </view>
  17. <view class="item">
  18. <u--input
  19. placeholder="密码"
  20. prefixIcon="lock-fill"
  21. prefixIconStyle="font-size: 22px;color: #909399"
  22. labelColor="#ffffff"
  23. :type="showPassword ? 'text' : 'password'"
  24. :suffixIcon="passwordIcon"
  25. suffixIconStyle="font-size: 22px;color: #909399"
  26. v-model="dataFrom.password"
  27. @clickSuffixIcon="togglePassword"
  28. ></u--input>
  29. </view>
  30. <view class="item" @click="typeShow=true">
  31. <u--input
  32. placeholder="商家类型"
  33. prefixIcon="coupon-fill"
  34. suffixIcon="arrow-down"
  35. prefixIconStyle="font-size: 22px;color: #909399"
  36. suffixIconStyle="font-size: 22px;color: #909399"
  37. readonly
  38. v-model="userType"
  39. ></u--input>
  40. </view>
  41. <button @click="login">登录</button>
  42. <u-picker :immediateChange="true" :show="typeShow" :columns="columns" @close="typeShow=false" @cancel="typeShow=false" @confirm="confirm"></u-picker>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. export default {
  49. data() {
  50. return {
  51. h: uni.getSystemInfoSync().windowHeight,
  52. typeShow:false,
  53. userType:'',
  54. columns:[['酒店民宿','非酒店民宿']],
  55. typeCfg:{'酒店民宿':'1','非酒店民宿':'2'},
  56. showPassword: false, // 控制密码是否可见
  57. passwordIcon: 'eye-fill', // 密码显示图标
  58. dataFrom:{
  59. username:'',
  60. password:'',
  61. usertype:'2',
  62. captcha:'handset',
  63. uuid: "",
  64. grant_type: "password",
  65. }
  66. }
  67. },
  68. onLoad() {
  69. uni.clearStorageSync();
  70. },
  71. methods: {
  72. confirm(e){
  73. this.userType = e.value[0];
  74. this.typeShow = false;
  75. },
  76. // 切换密码显示/隐藏
  77. togglePassword() {
  78. this.showPassword = !this.showPassword;
  79. this.passwordIcon = this.showPassword ? 'eye-off' : 'eye-fill';
  80. },
  81. login(){
  82. this.dataFrom.usertype = this.typeCfg[this.userType]||'';
  83. if(!this.dataFrom.username) return this.$showToast('请输入用户名');
  84. if(!this.dataFrom.password) return this.$showToast('请输入密码');
  85. if(!this.dataFrom.usertype) return this.$showToast('请选择类型');
  86. uni.setStorageSync('authorization','Basic cmVucmVuaW86cmVucmVuaW8=');
  87. let that = this;
  88. this.$api.post("/auth/oauth/token", {
  89. ...this.dataFrom,
  90. username: this.dataFrom.username + "&&" + `${this.dataFrom.usertype}`,
  91. },false,true).then(res=>{
  92. if(res.data.code==0){
  93. uni.setStorageSync('authorization',res.data.token_type+' '+res.data.access_token);
  94. uni.setStorageSync('access_token',res.data.access_token);
  95. that.$api.get('/sys/user/info').then(resu=>{
  96. if(resu.data.code===0){
  97. that.$showToast('登录成功');
  98. uni.setStorageSync('userInfo',resu.data.data);
  99. setTimeout(()=>{
  100. uni.reLaunch({
  101. url:'/pages/login/select?userInfo='+encodeURIComponent(JSON.stringify(resu.data.data))
  102. })
  103. },1500)
  104. }else that.$showToast(resu.data.msg)
  105. })
  106. }else that.$showToast(res.data.msg)
  107. })
  108. },
  109. // 返回上一页
  110. goBack() {
  111. uni.navigateBack({
  112. delta: 1
  113. });
  114. }
  115. }
  116. }
  117. </script>
  118. <style scoped lang="less">
  119. .page{
  120. background: url(https://fsy.shengsi.gov.cn/file/20240109/472b6b7b9ea44652b85e73c796876378.png) no-repeat;
  121. background-size: 100% 100%;
  122. display: flex;
  123. align-items: center;
  124. justify-content: center;
  125. position: relative;
  126. .back-btn {
  127. position: absolute;
  128. top: 80rpx;
  129. left: 40rpx;
  130. width: 60rpx;
  131. height: 60rpx;
  132. display: flex;
  133. align-items: center;
  134. justify-content: center;
  135. z-index: 10;
  136. }
  137. .box{
  138. width: calc(100% - 180rpx);
  139. display: flex;
  140. flex-direction: column;
  141. align-items: center;
  142. image{
  143. width: 480rpx;
  144. height: 520rpx;
  145. }
  146. .text{
  147. text-align: center;
  148. font-size: 56rpx;
  149. font-family: PingFang SC, PingFang SC;
  150. font-weight: 800;
  151. color: #FFFFFF;
  152. line-height: 96rpx;
  153. }
  154. .login{
  155. margin-top: 80rpx;
  156. width: 100%;
  157. .item{
  158. margin-bottom: 40rpx;
  159. ::v-deep input{
  160. color: #FFFFFF !important;
  161. }
  162. }
  163. button{
  164. width: 100%;
  165. height: 100%;
  166. background: #FFFFFF;
  167. border-radius: 48rpx 48rpx 48rpx 48rpx;
  168. line-height: 96rpx;
  169. text-align: center;
  170. font-size: 34rpx;
  171. font-family: PingFang SC, PingFang SC;
  172. font-weight: 400;
  173. color: #145EE6;
  174. }
  175. }
  176. }
  177. }
  178. </style>