| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <template>
- <view>
- <u-toast ref="uToast" />
- <view class="d-flex f-column a-center top">
- <image src="../../static/logo.png" mode=""></image>
- <text class="main-color-text f-weight-bold m2">欢迎使用设备管理系统!</text>
- </view>
- <view class="f-weight-bold name text-center">账号登录</view>
- <view class="input">
- <input
- type="text"
- v-model="userName"
- placeholder="请输入用户名"
- placeholder-class="placeholder-class"
- />
- <input
- type="password"
- v-model="passWord"
- placeholder="请输入密码"
- placeholder-class="placeholder-class"
- />
- </view>
- <view class="tip" @tap="forgetPass">
- 忘记密码
- <text class="mx1">
- <u-icon name="question"></u-icon>
- </text>
- </view>
- <view class=" mui-input-row mui-checkbox ">
- <checkbox-group @change="checkboxChange">
- <checkbox
- id="chkRem"
- type="checkbox"
- :checked="rememberPsw"
- @tap="rememberPsw = !rememberPsw"
- class="RememberCheck"
- >
- 记住密码
- </checkbox>
- </checkbox-group>
- </view>
- <button class="main-color-bg text-color-white login" @tap="login">登录</button>
- <view class="wechat p-fixed left0 right0" style="bottom: 60rpx;">
- <button open-type="getUserInfo" @click="getUserInfo" class="d-flex j-center a-center">
- <image src="/static/images/weixin.png" mode=""></image>
- </button>
- </view>
- </view>
- </template>
- <script>
- import { encryptPassword } from '@/utils/password';
- export default {
- data() {
- return {
- userName: '', // 用户名
- passWord: '', // 密码
- rememberPsw: true, // 记住密码
- Code: '',
- session_key: '',
- openid: ''
- };
- },
- // 页面初始加载
- mounted() {
- const that = this;
- // 缓存的账号
- const cache_userName = uni.getStorageSync('cache_userName');
- // 缓存的密码
- const cache_passWord = uni.getStorageSync('cache_passWord');
- // 有缓存就赋值给文本没有就清空
- if (cache_userName && cache_passWord) {
- that.userName = cache_userName;
- that.passWord = cache_passWord;
- } else {
- that.userName = '';
- that.passWord = '';
- }
- },
- onShow() {
- if (this.$BaseTool.Util.isDev()) {
- this.userName = 'superadmin'
- this.passWord = '123456'
- }
- },
- methods: {
- // 找回密码
- forgetPass() {
- },
- // 复选框
- checkboxChange: function(e) {
- if (e.detail.value.length == 1) {
- // 获取缓存的账号
- uni.getStorageSync('cache_userName', this.userName);
- uni.getStorageSync('cache_passWord', this.passWord);
- } else {
- uni.removeStorageSync('cache_userName');
- uni.removeStorageSync('cache_passWord');
- }
- },
- // 登录
- login() {
- if (!this.userName) {
- return this.$refs.uToast.show({
- title: '请输入用户名',
- type: 'default',
- icon: false
- });
- } else if (!this.passWord) {
- return this.$refs.uToast.show({
- title: '请输入密码',
- type: 'default',
- icon: false
- });
- }
- this.$Http
- .mobileLogin({
- username: this.userName,
- password: encryptPassword(this.passWord),
- grant_type: 'password',
- scope: 'server'
- })
- .then(res => {
- // 缓存账号和密码
- if (this.rememberPsw) {
- uni.setStorageSync('cache_userName', this.userName);
- uni.setStorageSync('cache_passWord', this.passWord);
- } else {
- uni.removeStorageSync('cache_userName');
- uni.removeStorageSync('cache_passWord');
- }
- // 如果openId有,则绑定openId
- const openId = uni.getStorageSync('openId', this.userName);
- if (openId != null && openId !== '') {
- this.$Http
- .bindUserAndOpenId(openId)
- .then(res => {
- uni.removeStorageSync('openId');
- });
- }
- });
- },
- // 微信登录获取openid
- getUserInfo() {
- // 登录
- uni.login({
- provider: 'weixin',
- success: res => {
- // console.log('登录成功:', res);
- // 获取临时登录凭证code
- this.Code = res.code;
- // 获取openid,session_key
- const appid = 'wx38f46845be704faa' // 需替换
- const secret = '9bt1F6ojLU6JLv76Boo4qaeEU6PcW75nGjjLyauDtAF' // 需替换
- const url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret +
- '&js_code=' +
- this.Code + '&grant_type=authorization_code';
- uni.request({
- url: url, // 请求路径
- success: res => {
- // console.log('openid session_key:', res.data);
- this.openid = res.data.openid
- this.session_key = res.data.session_key
- console.log('openid:', this.openid)
- uni.showToast({ title: this.openid, icon: 'none' })
- },
- fail: err => {
- console.log('请求失败:', err)
- }
- });
- },
- fail: err => {
- console.log('登录失败:', err)
- }
- })
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .top {
- font-size: unit(28, rpx);
- padding-top: unit(90, rpx);
- image {
- width: unit(170, rpx);
- height: unit(123, rpx);
- }
- }
- .name {
- font-size: unit(42, rpx);
- color: #333333;
- margin: unit(80, rpx) 0 unit(80, rpx);
- }
- .input {
- width: unit(600, rpx);
- margin: 0 auto;
- input {
- border-bottom: unit(1, rpx) solid #e6e6e6;
- height: unit(100, rpx);
- line-height: unit(100, rpx);
- }
- }
- .login {
- width: unit(600, rpx);
- height: unit(100, rpx);
- margin: unit(100, rpx) auto 0;
- border-radius: unit(80, rpx);
- }
- .tip {
- width: unit(600, rpx);
- margin: unit(30, rpx) auto;
- text-align: right;
- font-size: unit(26, rpx);
- font-weight: 500;
- }
- .wechat{
- margin-top: unit(90, rpx);
- button{
- background-color: #FFFFFF;
- &::after{
- border: none;
- }
- image{
- width: unit(90, rpx);
- height: unit(90, rpx);
- }
- }
- }
- .mui-checkbox input[type='checkbox']:checked:before {
- color: #00bbb1;
- }
- .RememberPass {
- color: #adadad;
- margin-top: 5px;
- }
- .RememberCheck {
- margin-left: 30px;
- color: #adadad;
- }
- </style>
|