| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419 |
- <template>
- <view class="page-container">
- <view class="welcome-title">
- 智能营销系统,欢迎您!
- </view>
- <view class="main-card" style="margin-top:20%">
- <!-- <image class="logo" :src="imgurl+'/cjx/hexiao/lobin_lobin.png'" mode="aspectFit"></image>-->
- <view class="user-type-selector">
- <view
- class="type-button"
- :class="{ 'active': userType === 'distributor' }"
- @click="switchUserType('distributor')"
- >
- <uni-icons type="person" :color="userType === 'distributor' ? '#fff' : '#4a8af4'" size="20"></uni-icons>
- <text>经销商</text>
- </view>
- <view
- class="type-button"
- :class="{ 'active': userType === 'salesman' }"
- @click="switchUserType('salesman')"
- >
- <uni-icons type="staff" :color="userType === 'salesman' ? '#fff' : '#4a8af4'" size="20"></uni-icons>
- <text>业务员</text>
- </view>
- </view>
- <view >
- <view class="form-group">
- <view class="input-wrapper">
- <uni-icons type="person" size="24" color="#cccccc"></uni-icons>
- <input class="input-field" type="number" v-model="phone" placeholder="请输入手机号" placeholder-class="placeholder" />
- </view>
- <view class="input-wrapper">
- <uni-icons type="locked" size="24" color="#cccccc"></uni-icons>
- <input class="input-field" type="number" v-model="code" placeholder="请输入验证码" placeholder-class="placeholder" />
- <text
- class="code-btn"
- :class="{ 'disabled': isCountingDown }"
- @click="getVerificationCode"
- >
- {{ codeBtnText }}
- </text>
- </view>
- </view>
- <button class="login-btn" @click="handleLogin">登 录</button>
- </view>
- <!-- <view v-if="!showTel">-->
- <!-- <view>-->
- <!-- 请点击下方按钮进行授权登录-->
- <!-- </view>-->
- <!-- <button class="login-btn" open-type="getPhoneNumber" @getphonenumber="handlePhone">-->
- <!-- 授权登录-->
- <!-- </button>-->
- <!-- </view>-->
- <!-- <view style="font-size: 12px;margin-top:12%;" @click="showTel = !showTel">-->
- <!-- <view v-if="!showTel">使用手机号验证码登录</view>-->
- <!-- <view v-if="showTel">一键登录</view>-->
- <!-- </view>-->
- </view>
- </view>
- </template>
- <script>
- // 1. 导入你的API方法
- import { getVerificationCode, login ,oneKeyLogin} from '@/api/hexiao.js';
- import {getAdminInfo, getAdminToken, setAdminInfo, setAdminToken} from "@/utils/auth";
- import {
- getIsNoLogin
- } from '@/api/login'
- export default {
- data() {
- return {
- showTel: false,
- userType: 'distributor',
- phone: '',
- code: '',
- codeBtnText: '获取手机验证码',
- isCountingDown: false,
- countdown: 60,
- timer: null,
- imgurl:"https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu",
- tenantId:0,
- }
- },
- onUnload() {
- if (this.timer) {
- clearInterval(this.timer);
- this.timer = null;
- }
- },
- onLoad(opt){
- if(opt.uid){
- this.tenantId = opt.uid;
- }
- let self = this;
- uni.showLoading({
- mask: true
- })
- wx.login({
- success(resLogin) {
- if (resLogin.code) {
- getIsNoLogin({jsCode:resLogin.code}).then(res => {
- uni.hideLoading();
- if (res.code === 0){
- setAdminInfo(res.data);
- setAdminToken(res.data.sessionId)
- self.doLoginSuccess();
- }
- // 跳转登陆页
- })
- }else{
- uni.hideLoading();
- }
- }
- });
- // let token = getAdminToken()
- // if(token){
- // this.doLoginSuccess();
- // }
- },
- methods: {
- handlePhone(e) {
- if (e.detail.code) {
- // this.loginDate.iv = e.detail.iv;
- // this.loginDate.encryptedData = e.detail.encryptedData;
- uni.showLoading({ title: '登录中...' });
- let userType = 0;
- if(this.userType === 'distributor'){
- userType = 1;
- }
- if(this.userType === 'salesman'){
- userType = 2;
- }
- let self = this;
- uni.login({
- provider: 'weixin', //使用微信登录
- success: function (loginRes) {
- let jsCode = loginRes.code;
- oneKeyLogin( e.detail.code,userType,jsCode,self.tenantId).then(res => {
- // 登录成功 (res.code === 0)
- uni.hideLoading();
- if (res.code === 0) {
- setAdminToken(res.data.sessionId)
- self.setUserInfo(res.data);
- self.doLoginSuccess();
- } else {
- console.log('登录失败!' + res.msg);
- uni.showToast({ title: res.msg || '登录失败', icon: 'none' });
- }
- }).catch(err => {
- // 登录失败 (res.code !== 0 或网络错误)
- uni.hideLoading();
- console.error('登录失败:', err);
- uni.showToast({ title: err.msg || '登录失败', icon: 'none' });
- });
- }
- });
- }
- },
- doLoginSuccess(){
- let info = getAdminInfo()
- let userType = info.roleType;
- let pageUrl = '/pages/hexiao/ywy/index';
- if(userType === 1){
- pageUrl = '/pages/hexiao/jxs/index';
- }
- if(userType === 2){
- pageUrl = '/pages/hexiao/ywy/index';
- }
- uni.reLaunch({
- url: pageUrl
- });
- },
- switchUserType(type) {
- this.userType = type;
- },
- // --- 更新:调用获取验证码的API ---
- getVerificationCode() {
- if (this.isCountingDown) {
- return;
- }
- if(!this.phone) {
- uni.showToast({ title: '请输入手机号', icon: 'none' });
- return;
- }
- if(this.timer){
- clearInterval(this.timer);
- this.timer = null;
- }
- let userType = 0;
- if(this.userType === 'distributor'){
- userType = 1;
- }
- if(this.userType === 'salesman'){
- userType = 2;
- }
- // 调用API
- getVerificationCode(this.phone,userType,this.tenantId).then(res => {
- if(res.code !== 0){
- uni.showToast({ title: res.msg || '找不到用户信息,请确认', icon: 'none' });
- return;
- }
- console.log('验证码接口成功返回:', res);
- uni.showToast({ title: res.msg || '验证码已发送', icon: 'success' });
- // 开始倒计时
- this.isCountingDown = true;
- this.codeBtnText = `${this.countdown}s后重新获取`;
- this.timer = setInterval(() => {
- this.countdown--;
- if (this.countdown > 0) {
- this.codeBtnText = `${this.countdown}s后重新获取`;
- } else {
- clearInterval(this.timer);
- this.timer = null;
- this.countdown = 60;
- this.isCountingDown = false;
- this.codeBtnText = '获取手机验证码';
- }
- }, 1000);
- }).catch(err => {
- // if(res.code === -99){
- // uni.showToast({ title: err.msg || '找不到用户信息,请确认', icon: 'none' });
- // return;
- // }
- // console.error('验证码接口失败返回:', err);
- // uni.showToast({ title: err.msg || '发送失败,请重试', icon: 'none' });
- });
- },
- setUserInfo(res){
- setAdminInfo(res);
- },
- // --- 更新:调用登录的API ---
- handleLogin() {
- if(!this.phone || !this.code) {
- uni.showToast({ title: '请填写完整信息', icon: 'none' });
- return;
- }
- uni.showLoading({ title: '登录中...' });
- let userType = 0;
- if(this.userType === 'distributor'){
- userType = 1;
- }
- if(this.userType === 'salesman'){
- userType = 2;
- }
- let self = this;
- uni.login({
- provider: 'weixin', //使用微信登录
- success: function (loginRes) {
- let jsCode = loginRes.code;
- login(self.phone, self.code,userType,jsCode,this.tenantId).then(res => {
- // 登录成功 (res.code === 0)
- uni.hideLoading();
- if (res.code === 0) {
- setAdminToken(res.data.sessionId)
- self.setUserInfo(res.data);
- self.doLoginSuccess();
- } else {
- console.log('登录失败!' + res.msg);
- uni.showToast({ title: err.msg || '登录失败', icon: 'none' });
- }
- }).catch(err => {
- // 登录失败 (res.code !== 0 或网络错误)
- uni.hideLoading();
- console.error('登录失败:', err);
- uni.showToast({ title: err.msg || '登录失败', icon: 'none' });
- });
- }
- });
- // 调用API
- }
- }
- }
- </script>
- <style lang="scss">
- .page-container {
- width: 100vw;
- height: 100vh;
- display: flex;
- flex-direction: column;
- align-items: center;
- overflow: hidden;
- min-height: 100vh;
- background-image: url("https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/cjx/hexiao/login_bg.png");
- background-size: contain;
- background-position: center;
- background-repeat: no-repeat;
- position: relative;
- }
- .welcome-title {
- font-size: 48rpx;
- font-weight: bold;
- color: #488CFF;
- margin-top: 28%;
- margin-bottom: 40rpx;
- }
- .main-card {
- width: 88%;
- border-radius: 40rpx;
- padding: 40rpx;
- box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.05);
- display: flex;
- flex-direction: column;
- align-items: center;
- position: relative;
- top: 10%;
- height: 100%;
- }
- .logo {
- width: 150rpx;
- height: 150rpx;
- background-color: #f0f0f0;
- margin-bottom: 40rpx;
- border-radius: 20rpx;
- }
- .user-type-selector {
- display: flex;
- justify-content: center;
- width: 100%;
- margin-bottom: 50rpx;
- .type-button {
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 30rpx;
- padding: 15rpx 40rpx;
- border-radius: 50rpx;
- transition: all 0.3s ease;
- border: 1px solid #4a8af4;
- color: #4a8af4;
- background-color: #fff;
- margin: 0 15rpx;
- .uni-icons {
- margin-right: 10rpx;
- }
- &.active {
- background-color: #4a8af4;
- color: #ffffff;
- border-color: #4a8af4;
- }
- }
- }
- .form-group {
- width: 100%;
- }
- .input-wrapper {
- display: flex;
- align-items: center;
- width: 100%;
- padding: 20rpx 0;
- border-bottom: 1px solid #f0f0f0;
- margin-bottom: 30rpx;
- .input-field {
- flex: 1;
- font-size: 30rpx;
- margin-left: 20rpx;
- }
- .placeholder {
- color: #cccccc;
- }
- .code-btn {
- font-size: 28rpx;
- color: #4a8af4;
- white-space: nowrap;
- padding-left: 20rpx;
- transition: color 0.3s; // 添加颜色过渡效果
- // --- 新增:置灰样式 ---
- &.disabled {
- color: #cccccc;
- }
- }
- }
- .login-btn {
- width: 100%;
- background: #4a8af4;
- color: #ffffff;
- font-size: 32rpx;
- border-radius: 50rpx;
- margin-top: 40rpx;
- box-shadow: 0 10rpx 20rpx rgba(74, 138, 244, 0.3);
- }
- .version-info {
- margin-top: 40rpx;
- font-size: 24rpx;
- color: #b0b0b0;
- }
- </style>
|