login.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view class="content">
  3. <view class="inner">
  4. <view class="form-box">
  5. <view class="form-item">
  6. <text class="label">员工帐号</text>
  7. <input type="text" v-model="form.userName" placeholder="登录帐号" placeholder-class="form-input" />
  8. </view>
  9. <view class="form-item">
  10. <text class="label">员工密码</text>
  11. <input type="password" v-model="form.password" placeholder="登录密码" placeholder-class="form-input" />
  12. </view>
  13. </view>
  14. </view>
  15. <view class="tips">
  16. <checkbox :checked="isAgreement" @click="handleAgreement()" />
  17. <view @click="handleAgreement()">您同意并接受</view>
  18. <view class="btn" @click="openContent('userHealth')">《健康客服协议》</view>
  19. </view>
  20. <view class="btn-box">
  21. <view class="sub-btn" :style="{opacity: isLoading ? 0.6 : 1}" @click="submit()">{{isLoading ? '登录中...' : '员工登录'}}</view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import {login} from '@/api/companyUser'
  27. import IMSDK from "openim-uniapp-polyfill";
  28. import { callingModule, meetingModule } from "@/pages_im/util/imCommon";
  29. export default {
  30. data() {
  31. return {
  32. form:{
  33. userName:null,
  34. password:null
  35. },
  36. isAgreement:false,
  37. registrationID:"",
  38. isAgreePrivacy:false,
  39. isLoading:false,
  40. }
  41. },
  42. computed: {
  43. },
  44. onLoad() {
  45. // #ifdef APP-PLUS
  46. this.isAgreePrivacy = this.$isAgreePrivacy();
  47. if (this.isAgreePrivacy) {
  48. this.getRegistrationID();
  49. }
  50. // #endif
  51. },
  52. onHide() {
  53. },
  54. onUnload() {
  55. },
  56. mounted() {
  57. },
  58. methods: {
  59. getRegistrationID() {
  60. this.registrationID = uni.getStorageSync("registrationID");
  61. this.form.jpushId=this.registrationID;
  62. if (this.registrationID == null || this.registrationID == "") {
  63. uni.getPushClientId({success: res => {
  64. uni.setStorageSync("registrationID", res.cid);
  65. this.registrationID = res.cid;
  66. this.form.jpushId=this.registrationID;
  67. }
  68. });
  69. }
  70. },
  71. openContent(type){
  72. uni.navigateTo({
  73. url:"/pages/user/agreement?type="+type
  74. });
  75. },
  76. handleAgreement(){
  77. this.isAgreement=!this.isAgreement;
  78. },
  79. submit(){
  80. if(this.isLoading) return;
  81. if(!this.isAgreement){
  82. uni.showToast({
  83. icon:'none',
  84. title: "请先同意协议后再登录",
  85. });
  86. return;
  87. }
  88. this.isLoading = true;
  89. uni.showLoading({ title: '登录中..', mask: true });
  90. login(this.form).then(res => {
  91. if(res.code==200){
  92. uni.showLoading({ title: '登录中..', mask: true });
  93. uni.setStorageSync('companyId',res.user.companyId);
  94. uni.setStorageSync('companyUserId',res.user.userId);
  95. uni.setStorageSync('companyUser',JSON.stringify(res.user));
  96. uni.setStorageSync('CompanyUserToken',res.companyUserToken);
  97. IMSDK.asyncApi(IMSDK.IMMethods.Logout, IMSDK.uuid()).then(() => {
  98. callingModule?.endCall();
  99. meetingModule?.endCall();
  100. uni.removeStorage({ key: 'IMToken' });
  101. uni.removeStorage({ key: 'IMUserID' });
  102. uni.removeStorage({key: "IMHasLogin" });
  103. uni.hideLoading();
  104. uni.showToast({icon:'success',title: "登录成功", mask: true});
  105. uni.$emit('refreshIM');
  106. setTimeout(()=>{
  107. uni.$emit('refreshIMMenu');
  108. uni.redirectTo({url: '/pages/company/index' });
  109. },2000);
  110. }).catch((err) => {
  111. uni.hideLoading();
  112. this.isLoading = false;
  113. uni.showToast({
  114. title:"登录失败",
  115. icon:"error"
  116. })
  117. }).finally(() => {
  118. });
  119. }else{
  120. this.isLoading = false;
  121. uni.showToast({
  122. icon:'none',
  123. title: res.msg,
  124. });
  125. }
  126. }).catch(err => {
  127. this.isLoading = false;
  128. uni.hideLoading();
  129. uni.showToast({
  130. title:"登录失败",
  131. icon:"error"
  132. });
  133. console.error(err);
  134. });
  135. },
  136. },
  137. }
  138. </script>
  139. <style lang="scss">
  140. page{
  141. height: 100%;
  142. }
  143. .content{
  144. display: flex;
  145. flex-direction: column;
  146. justify-content: flex-start;
  147. .inner{
  148. padding: 20upx;
  149. .form-box{
  150. padding: 0 30upx;
  151. background: #FFFFFF;
  152. border-radius: 16upx;
  153. .form-item{
  154. padding: 30upx 0;
  155. display: flex;
  156. align-items: flex-start;
  157. border-bottom: 1px solid #F1F1F1;
  158. &:last-child{
  159. border-bottom: none;
  160. }
  161. .label{
  162. width: 150upx;
  163. text-align: left;
  164. font-size: 30upx;
  165. line-height: 44upx;
  166. font-family: PingFang SC;
  167. font-weight: 500;
  168. color: #222222;
  169. flex-shrink: 0;
  170. }
  171. input{
  172. text-align: left;
  173. }
  174. .form-input{
  175. font-size: 30upx;
  176. font-family: PingFang SC;
  177. font-weight: 500;
  178. color: #999999;
  179. text-align: left;
  180. }
  181. }
  182. }
  183. }
  184. .btn-box{
  185. height: 120upx;
  186. padding: 0 30upx;
  187. display: flex;
  188. align-items: center;
  189. justify-content: center;
  190. .sub-btn{
  191. width: 100%;
  192. height: 88upx;
  193. line-height: 88upx;
  194. text-align: center;
  195. font-size: 30upx;
  196. font-family: PingFang SC;
  197. font-weight: bold;
  198. color: #FFFFFF;
  199. background: #FF5030;
  200. border-radius: 44upx;
  201. }
  202. }
  203. }
  204. .tips{
  205. margin-top: 15rpx;
  206. padding: 0rpx 30rpx;
  207. display: flex;
  208. justify-content: flex-start;
  209. align-items: center;
  210. font-size: 28rpx;
  211. color: #000;
  212. checkbox{
  213. }
  214. .btn{
  215. color: #FF5030;
  216. }
  217. }
  218. </style>