| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <template>
- <view class="content">
- <view class="head">
- <text>登录</text>
- </view>
- <view class="login-wrap">
- <view class="username item">
- <text>账号:</text>
- <!-- <text></text> -->
- <uni-easyinput :inputBorder="false" class="login_input" type="text" v-model="username" placeholder="请输入账号" />
- </view>
- <view class="password item">
- <text>密码:</text>
- <uni-easyinput :inputBorder="false" class="login_input" type="password" v-model="password" placeholder="请输入密码">
- </uni-easyinput>
- </view>
- <!-- <view class="tip">
- <text>没有账号去注册</text>
- </view> -->
- <button type="primary" @click="loginSubmit" class="submit-BT">登录</button>
- </view>
- </view>
- </template>
- <script>
- import store from '@/store/index.js'
- import { login ,wxWorkLogin} from '@/api/user';
- import { setToken } from '@/libs/auth';
- export default {
- data() {
- return {
- username: "",
- password: "",
- }
- },
- onLoad({username,password}) {
- if(username){
- this.username=username;
- this.password=password;
- }
- },
- methods: {
- loginSubmit() {
- let username = (this.username).trim();
- let password = (this.password).trim();
- if (username.length < 1) {
- uni.showToast({
- title: '请填写账号',
- icon: "error"
- })
- return;
- }
- if (password.length < 1) {
- uni.showToast({
- title: '请填写密码',
- icon: "error"
- })
- return;
- }
- login({
- username,
- password
- }).then((res) => {
- let token = res.data.accessToken;
- let accountInfo = JSON.stringify(res.data.user);
- const userId=res.data.user.userId;
- setToken(token);
- uni.setStorageSync('accountInfo', accountInfo);
- store.commit('setToken', token);
- let info=uni.getSystemInfoSync();
- if(info.environment==="wxwork"){
- if(!userId)
- {
- uni.showToast({
- icon:"none",
- title:"未获取到userId!"
- })
- return;
- }
- wx.qy.login({
- success:(res)=>{
- console.log(res)
- let code=res.code;
- wxWorkLogin({
- userId,code
- }).then((res)=>{
- if(res.code===0){
- uni.switchTab({
- url: '/pages/index/index'
- })
- }else{
- uni.showToast({
- icon:"none",
- title:"wxWork登录失败"
- })
- }
- })
- }
- })
- }else{
- //#ifdef APP-PLUS
- this.jpushInit(userId);
- return;
- //#endif
- uni.switchTab({
- url: '/pages/index/index'
- })
- }
- }).catch((res)=>{
- console.log(res)
- })
- },
- //极光推送初始化
- jpushInit(userId){
- //#ifdef APP-PLUS
- let jpushModule=store.state.jpush;
- jpushModule.setAlias({
- 'alias':`push${userId}`
- })
- setTimeout(()=>{
- uni.switchTab({
- url: '/pages/index/index'
- })
- },1000)
- //#endif
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .content {
- .head {
- font-size: 50upx;
- text-align: center;
- padding: 40upx 0;
- letter-spacing: 2upx;
- }
- .login-wrap {
- width: 90%;
- margin: 50upx auto 0;
- box-sizing: border-box;
- padding: 20upx;
- border-radius: 8upx;
- .item {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- height: 100upx;
- font-size: 32upx;
- line-height: 100upx;
- width: 150%;
- input {
- font-size: 32upx;
- height: 100upx;
- border: 0;
- }
- .login_input {
- width: 580upx;
- border: none;
- }
- }
- .tip {
- text-align: right;
- padding: 18upx 0;
- font-size: 28upx;
- }
- .submit-BT {
- border-radius: 16upx;
- margin-top: 50upx;
- background-color: var(--sysblue);
- }
- }
- }
- </style>
|