gukai 9 months ago
parent 45e5d281e3
commit bf1ac3a37b

@ -11,4 +11,11 @@ export default {
data, data,
}); });
}, },
captch(data) {
return request({
url: "/admin/auth/captch",
method: "POST",
data,
});
},
}; };

@ -23,26 +23,36 @@
<view class="rounded-md overflow-hidden"> <view class="rounded-md overflow-hidden">
<wd-cell-group border size="large"> <wd-cell-group border size="large">
<wd-transition :duration="400" :show="true" name="fade-left"> <wd-transition :duration="400" :show="true" name="fade-left">
<wd-input size="large" label="用户名" label-width="100px" prop="username" clearable v-model="model.username" <wd-input size="large" label="用户名" label-width="100px" prop="username" clearable
placeholder="请输入用户名" :rules="[{ required: true, message: '请填写用户名' }]" /> v-model="model.username" placeholder="请输入用户名"
:rules="[{ required: true, message: '请填写用户名' }]" />
</wd-transition> </wd-transition>
<wd-transition :duration="450" :show="true" name="fade-left"> <wd-transition :duration="450" :show="true" name="fade-left">
<wd-input size="large" label="密码" label-width="100px" prop="password" show-password clearable v-model="model.password" <wd-input size="large" label="密码" label-width="100px" prop="password" show-password clearable
placeholder="请输入密码" :rules="[{ required: true, message: '请填写密码' }]" /> v-model="model.password" placeholder="请输入密码"
:rules="[{ required: true, message: '请填写密码' }]" />
</wd-transition> </wd-transition>
<wd-transition :duration="450" :show="true" name="fade-left">
<wd-input size="large" label="验证码" label-width="100px" clearable v-model="model.captch"
placeholder="请输入验证码" :rules="[{ required: true, message: '请填写验证码' }]" />
<view style="display: flex;justify-content: flex-end;padding: 10rpx 0;">
<image @click="getCaptch()" style="height: 60rpx;" :src="captch_img" mode="heightFix"></image>
</view>
</wd-transition>
</wd-cell-group> </wd-cell-group>
</view> </view>
<view class="footer mt-4 px-6" <view class="footer mt-4 px-6"
style="text-align: right;font-size: 28rpx;color: #999;display: flex;align-items: center;justify-content: flex-end;"> style="text-align: right;font-size: 28rpx;color: #999;display: flex;align-items: center;justify-content: flex-end;">
记住密码 记住密码
<!-- <checkbox v-model="is_save_user_pwd" style="transform:scale(0.7)" /> --> <!-- <checkbox v-model="is_save_user_pwd" style="transform:scale(0.7)" /> -->
<wd-checkbox v-model="is_save_user_pwd" shape="square"></wd-checkbox > <wd-checkbox v-model="is_save_user_pwd" shape="square"></wd-checkbox>
</view> </view>
<view class="footer mt-4 px-6"> <view class="footer mt-4 px-6">
<wd-transition :duration="500" :show="true" name="fade-left"> <wd-transition :duration="500" :show="true" name="fade-left">
<wd-button style="font-size: 20px;padding: 10px;" :loading="loading" type="primary" size="large" @click="handleSubmit" block>登录</wd-button> <wd-button style="font-size: 20px;padding: 10px;" :loading="loading" type="primary" size="large"
@click="handleSubmit" block>登录</wd-button>
</wd-transition> </wd-transition>
</view> </view>
</wd-form> </wd-form>
@ -50,125 +60,148 @@
</template> </template>
<script setup> <script setup>
import { ref } from 'vue' import {
import user from '@/api/modules/user.js' ref
import systemApi from '@/api/modules/system.js' } from 'vue'
import utils from '@/utils/utils.js' import user from '@/api/modules/user.js'
import md5 from 'js-md5'; import systemApi from '@/api/modules/system.js'
// uni.clearStorage(); // import utils from '@/utils/utils.js'
import md5 from 'js-md5';
const webInfo = ref({}) // uni.clearStorage(); //
const getWebInfo = () => { const webInfo = ref({})
systemApi.getSetting().then(res => {
webInfo.value = res.data const getWebInfo = () => {
systemApi.getSetting().then(res => {
webInfo.value = res.data
})
}
getWebInfo()
console.log(uni.getStorageSync('user_pwd'), 'user_pwd')
const model = ref({
username: "",
password: "",
...(uni.getStorageSync('user_pwd') || {}),
captch: ''
}) })
}
const loading = ref(false)
getWebInfo() const is_save_user_pwd = ref(true)
console.log(uni.getStorageSync('user_pwd'), 'user_pwd') const form = ref(null)
const model = ref({ const captch_img = ref(null)
username: "",
password: "", // if (token) {
...(uni.getStorageSync('user_pwd') || {}) // const user_info = uni.getStorageSync("user_info");
}) // if (user_info.type == 1) {
// utils.toUrl("/store/index/index")
const loading = ref(false) // }
const is_save_user_pwd = ref(true) // } else {
const form = ref(null) // utils.toUrl("/pages/login/index")
// }
// if (token) {
// const user_info = uni.getStorageSync("user_info"); getCaptch()
// if (user_info.type == 1) { function getCaptch() {
// utils.toUrl("/store/index/index") user.captch({
// }
// } else { }).then(res => {
// utils.toUrl("/pages/login/index") console.log(res, 'res')
// } if (res.code == 0) {
captch_img.value = res.data
function handleSubmit() { } else {
loading.value = true
form.value }
.validate() })
.then(({ valid, errors }) => { }
if (valid) {
if (is_save_user_pwd.value) { function handleSubmit() {
uni.setStorageSync("user_pwd", model.value); loading.value = true
} form.value
user.login({ .validate()
...model.value, .then(({
password: md5(model.value.password) valid,
}).then(res => { errors
}) => {
if (res.code == 0) { if (valid) {
uni.setStorageSync("token", res.data.access_token); if (is_save_user_pwd.value) {
uni.setStorageSync("user_info", res.data.user_info); uni.setStorageSync("user_pwd", model.value);
}
uni.showToast({ user.login({
icon: "none", ...model.value,
title: "登录成功", password: md5(model.value.password),
}); captch: model.value.captch
}).then(res => {
if (res.data.user_info.type == 1) {
utils.toUrl("/store/index/index", "redirectTo") if (res.code == 0) {
uni.setStorageSync("store_info", res.data.user_info); uni.setStorageSync("token", res.data.access_token);
} else if (res.data.user_info.type == 3) { uni.setStorageSync("user_info", res.data.user_info);
uni.setStorageSync("mall_token", res.data.access_token);
uni.setStorageSync("mall_info", res.data.user_info); uni.showToast({
utils.toUrl("/mall/index/index", "redirectTo") icon: "none",
title: "登录成功",
});
if (res.data.user_info.type == 1) {
utils.toUrl("/store/index/index", "redirectTo")
uni.setStorageSync("store_info", res.data.user_info);
} else if (res.data.user_info.type == 3) {
uni.setStorageSync("mall_token", res.data.access_token);
uni.setStorageSync("mall_info", res.data.user_info);
utils.toUrl("/mall/index/index", "redirectTo")
} else {
uni.showToast({
title: '登录平台开发中 ···',
icon: 'none'
})
}
loading.value = false
} else { } else {
uni.showToast({ uni.showToast({
title: '登录平台开发中 ···', title: res.message,
icon: 'none' icon: 'none'
}) })
getCaptch()
loading.value = false
} }
loading.value = false
} else {
uni.showToast({
title: res.message,
icon: 'none'
})
loading.value = false
}
loading.value = false
})
} else {
loading.value = false loading.value = false
}) }
} else { })
.catch((error) => {
console.log(error, 'error')
loading.value = false loading.value = false
} })
}) }
.catch((error) => {
console.log(error, 'error')
loading.value = false
})
}
</script> </script>
<style> <style>
.content { .content {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
min-height: 100vh; min-height: 100vh;
} }
.logo { .logo {
height: 200rpx; height: 200rpx;
width: 200rpx; width: 200rpx;
margin-top: 200rpx; margin-top: 200rpx;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
margin-bottom: 50rpx; margin-bottom: 50rpx;
} }
.text-area { .text-area {
display: flex; display: flex;
justify-content: center; justify-content: center;
} }
.title { .title {
font-size: 36rpx; font-size: 36rpx;
color: #8f8f94; color: #8f8f94;
} }
</style> </style>
Loading…
Cancel
Save