index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <view class="content">
  3. <view class="head">
  4. <text>登录</text>
  5. </view>
  6. <view class="login-wrap">
  7. <view class="username item">
  8. <text>账号:</text>
  9. <!-- <text></text> -->
  10. <input type="text" v-model="username" placeholder="请输入账号" />
  11. </view>
  12. <view class="password item">
  13. <text>密码:</text>
  14. <!-- <text></text> -->
  15. <input type="text" v-model="password" placeholder="请输入密码" />
  16. </view>
  17. <navigator class="tip" url="/views/toRegister/index"><text>没有账号去注册</text></navigator>
  18. <button type="primary" @click="loginSubmit" class="submit-BT">登录</button>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import {login,getInfo} from '@/api/user';
  24. import {getInfoByAccountId} from '@/api/doctor';
  25. import {setToken} from '@/libs/auth';
  26. export default{
  27. data(){
  28. return{
  29. username:"",
  30. password:""
  31. }
  32. },
  33. onLoad({username,password}) {
  34. if(username){
  35. this.username=username;
  36. this.password=password;
  37. }
  38. },
  39. methods:{
  40. async loginSubmit(){
  41. let {userType,id}= await this.loginApi();
  42. let {data}= await this.saveUserInfo();
  43. uni.setStorageSync('userInfo',data);
  44. if(userType===1){//是医生登录检测是否审核通过
  45. getInfoByAccountId(id).then((result)=>{
  46. let doctorAudit=result.data.doctorAudit;
  47. if(doctorAudit===1){
  48. uni.reLaunch({
  49. url:'/pages/home/index'
  50. })
  51. }else if(doctorAudit===0){
  52. uni.showToast({
  53. title:"当前账号正在审核中,请耐心等候!",
  54. icon:"none"
  55. })
  56. }else if(doctorAudit===2){
  57. uni.setStorageSync('doctorAccountInfo',result.data);
  58. uni.showModal({
  59. title:"提示!",
  60. content:"当前账号被驳回!请补充资料",
  61. confirmText:"补充资料",
  62. success: function (res) {
  63. if (res.confirm) {
  64. uni.navigateTo({
  65. url:"/views/doctorItems/updateDoctorInfo/index",
  66. fail(err) {
  67. console.log(err)
  68. }
  69. })
  70. } else if (res.cancel) {
  71. uni.showToast('取消无法登录!')
  72. }
  73. }
  74. })
  75. }else{
  76. uni.showToast({
  77. title:"当前账号不能登录!请联系管理员",
  78. icon:"none"
  79. })
  80. }
  81. })
  82. }else if(userType===2){
  83. uni.reLaunch({
  84. url:'/pages/home/index'
  85. })
  86. }
  87. else{//其他类型账号
  88. uni.showToast({
  89. title:"当前账号不支持小程序登录!",
  90. icon:"none"
  91. })
  92. }
  93. },
  94. loginApi(){
  95. return new Promise((resolve, reject) => {
  96. let username=(this.username).trim();
  97. let password=(this.password).trim();
  98. if(username.length<1){
  99. uni.showToast({
  100. title:'请填写账号',
  101. icon:"error"
  102. })
  103. return;
  104. }
  105. if(password.length<1){
  106. uni.showToast({
  107. title:'请填写密码',
  108. icon:"error"
  109. })
  110. return;
  111. }
  112. login({
  113. username,password
  114. }).then((res)=>{
  115. let token=res.data.token;
  116. let userType=res.data.userType;
  117. setToken(token);
  118. this.$store.commit('setUserType',userType)
  119. this.$store.commit('setToken',token);
  120. uni.setStorageSync('accountInfo',res.data); //保存账号信息
  121. resolve(res.data)
  122. }).catch((error)=>{
  123. reject(error)
  124. })
  125. })
  126. },
  127. saveUserInfo(){//保存用户信息
  128. return new Promise((resolve, reject) => {
  129. getInfo().then((res)=>{
  130. resolve(res)
  131. }).catch((error)=>{
  132. reject(error)
  133. })
  134. })
  135. }
  136. }
  137. }
  138. </script>
  139. <style lang="scss" scoped>
  140. .content{
  141. .head{
  142. font-size: 50upx;
  143. text-align: center;
  144. padding: 40upx 0;
  145. letter-spacing: 2upx;
  146. }
  147. .login-wrap{
  148. width: 90%;
  149. margin:50upx auto 0;
  150. box-sizing: border-box;
  151. padding: 20upx;
  152. border-radius: 8upx;
  153. .item{
  154. display: flex;
  155. justify-content: flex-start;
  156. align-items: center;
  157. height: 100upx;
  158. border-bottom: 1px solid #e5e5e5;
  159. font-size: 32upx;
  160. line-height:100upx;
  161. input{
  162. font-size: 32upx;
  163. height: 100upx;
  164. border: 0;
  165. }
  166. }
  167. .tip{
  168. text-align: right;
  169. padding: 18upx 0;
  170. font-size: 28upx;
  171. display: block;
  172. background-color: #fff;
  173. &:active{
  174. background-color: #fff;
  175. }
  176. }
  177. .submit-BT{
  178. border-radius: 16upx;
  179. margin-top: 50upx;
  180. background-color: var(--sysblue);
  181. }
  182. }
  183. }
  184. </style>