123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- <template>
- <view class="content">
- <view class="logo">
- <image style="height:104rpx;width:104rpx" src="/static/logo.png" mode="aspectFit" />
- <view class="app-name">计数通</view>
- </view>
- <!-- 账号密码登录 -->
- <template v-if="loginType == 1">
- <view class="inp_box">
- <input type="text" v-model="loginForm.username" @blur="getTenantUsername"
- :placeholder="this.$t('login.placeholder')" />
- </view>
- <view class="inp_box">
- <input type="password" v-model="loginForm.password"
- :placeholder="this.$t('login.passwordPlaceholder')" />
- </view>
- </template>
- <!-- 阅读同意/忘记密码 -->
- <view class="agree-forget">
- <view class="agree">
- <uni-data-checkbox selectedColor="#3275F5" multiple v-model="agree" checked=true :localdata="option">
- </uni-data-checkbox>
- <span>{{ $t("login.agree") }}</span>
- </view>
- <!-- <span class="forget" @click="toReset" v-if="loginType == 1">{{ $t('login.forgetPassword') }}</span> -->
- </view>
- <!-- 登录按钮 -->
- <view class="btn-wrap">
- <u-button type="primary" shape="circle" :disabled="!agree[0]"
- @click="loginType == 1 ? onAccountLogin() : onPhoneLogin()">{{ $t('login.login') }}</u-button>
- </view>
- <!-- 切换登陆方式/注册 -->
- <view class="login-opertion">
- <!-- <span class="flex" @click="changeLoginType">{{ loginType == 1 ? $t('login.phoneLogin') : $t('login.pwdLogin')
- }}</span>
- <span class="line"></span> -->
- <span class="flex" @click="toRegister">{{ $t('login.register') }}</span>
- </view>
- </view>
- </template>
- <script>
- import {
- userLogin,
- getTenantByUsername,
- getUserInfo
- } from "../../api/login"
- import {
- encryption,
- getTenantCacheList
- } from '../../utils/util'
- import {
- mapMutations
- } from 'vuex';
- export default {
- data() {
- return {
- time: 0,
- timer: undefined,
- isGetCode: false,
- loginType: 1,
- agree: [1],
- option: [{
- text: '',
- value: 1,
- }],
- currentLanguage: '',
- canLogin: false,
- needCode:false,
- loginForm: {
- username: "",
- password: "",
- code: "",
- randomStr: "blockPuzzle",
- },
- phoneLoginForm: {
- mobile: "",
- code: "",
- },
- }
- },
- onLoad(options) {
- if (uni.getStorageSync('CURRENT_LANG') == "en") {
- this.currentLanguage = 'English';
- } else if (uni.getStorageSync('CURRENT_LANG') == "pt") {
- this.currentLanguage = 'Português';
- } else if (uni.getStorageSync('CURRENT_LANG') == "uz") {
- this.currentLanguage = "O'zbekcha";
- } else if (uni.getStorageSync('CURRENT_LANG') == "ru") {
- this.currentLanguage = "Russian";
- }else {
- this.currentLanguage = '简体中文';
- }
- if (options.username) {
- this.loginForm.username = options.username
- this.phoneLoginForm.mobile = options.username
- this.getTenantUsername()
- }
- },
- methods: {
- ...mapMutations({
- setUserInfo: 'user/login'
- }),
- //去注册
- toRegister() {
- uni.navigateTo({
- url: '/pages/login/register'
- })
- },
- //账号登录
- onAccountLogin() {
- console.log("登录信息、", this.loginForm);
- if (this.noRegisterUserName == this.loginForm.username) {
- uni.showModal({
- content: this.$t('login.noRegister'),
- showCancel: false,
- })
- return
- }
-
- if (this.loginForm.username == '') {
- uni.showToast({
- title: this.$t('login.placeholder'),
- icon: "none",
- duration: 2500,
- })
- } else if (this.loginForm.password == '') {
- uni.showToast({
- title: this.$t('login.passwordPlaceholder'),
- icon: "none",
- duration: 2500,
- })
- } else {
- const userInfo = encryption({
- data: {
- username: this.loginForm.username,
- password: this.loginForm.password,
- delFlag: '0',
- source: 'mini'
- },
- key: 'pigxpigxpigxpigx',
- param: ['password'],
- source: 'mini'
- })
- userLogin(userInfo).then(res => {
- if (res.statusCode === 200) {
- var userId = res.data.user_id
- if (!userId) {
- userId = res.data.user_info.id
- }
- uni.setStorageSync('userId', userId)
- uni.setStorageSync('userName', this.loginForm.username)
- uni.setStorageSync('token', res.data.access_token)
- this.onGetUserInfo(true)
- }
- })
- }
- },
- //获取用户详情
- onGetUserInfo() {
- getUserInfo().then(res => {
- if (res.statusCode == 200 && res.data.code == 0) {
- console.log(res);
- var userType = res.data.data.sysUser.type;
- uni.setStorageSync('userInfo', res.data.data.sysUser)
- uni.setStorageSync('tenantInfo', res.data.data.tenantList)
- getApp().globalData.tabIndex = 'home'
- uni.switchTab({
- url: "/pages/home/home"
- })
- uni.showToast({
- title: this.$t('login.success'),
- icon: "none",
- duration: 2500,
- })
- this.setUserInfo(res.data.data.sysUser)
- } else if (res.statusCode != 200 || res.data.code === 1) {
- uni.showToast({
- title: res.data.error || res.data.msg,
- icon: 'none',
- duration: 2000
- })
- }
- })
- },
-
- //获取租户
- getTenantUsername() {
- if (
- !this.loginForm.username.length ||
- this.loginForm.username.length == 0
- ) {
- return false;
- }
- getTenantByUsername(this.loginForm.username).then(response => {
- let tenantList = response.data.data ? response.data.data : [];
- if(tenantList.length!=0){
- uni.setStorageSync('tenantId', tenantList[0].id);
- uni.setStorageSync('tenantName', tenantList[0].name);
- }else{
- uni.showToast({
- title: "获取租户失败",
- icon: 'none',
- duration: 2000
- });
- }
- });
- },
- }
- }
- </script>
- <style>
- /* #ifndef APP-NVUE */
- view {
- display: flex;
- box-sizing: border-box;
- flex-direction: column;
- }
- page {
- box-sizing: border-box;
- padding: 0 48rpx 80rpx;
- height: 100%;
- }
- /* #endif*/
- </style>
- <style lang="scss" scoped>
- @import '../../common/css/login.scss';
- </style>
|