|
@@ -21,7 +21,15 @@
|
|
:maxlength="20"
|
|
:maxlength="20"
|
|
></wd-input>
|
|
></wd-input>
|
|
<view class="border border-full h-1"></view>
|
|
<view class="border border-full h-1"></view>
|
|
- <wd-input key="username" label-width="115rpx" label="密码:" show-password v-model="password" clearable placeholder="请输入密码"></wd-input>
|
|
|
|
|
|
+ <wd-input
|
|
|
|
+ key="username"
|
|
|
|
+ label-width="115rpx"
|
|
|
|
+ label="密码:"
|
|
|
|
+ show-password
|
|
|
|
+ v-model="password"
|
|
|
|
+ clearable
|
|
|
|
+ placeholder="请输入密码"
|
|
|
|
+ ></wd-input>
|
|
<wd-input
|
|
<wd-input
|
|
key="username"
|
|
key="username"
|
|
label-width="115rpx"
|
|
label-width="115rpx"
|
|
@@ -40,8 +48,14 @@
|
|
<view class="h-20"></view>
|
|
<view class="h-20"></view>
|
|
<wd-button size="large" block type="success" @click="doLogin">登录</wd-button>
|
|
<wd-button size="large" block type="success" @click="doLogin">登录</wd-button>
|
|
<view class="h-20"></view>
|
|
<view class="h-20"></view>
|
|
- <view style="color: #333; font-size: 28rpx" class="text-center" @click="openPrivacyContract">
|
|
|
|
- <wd-checkbox :modelValue="isAuth" shape="square"><text style="color: #333">《用户隐私保护指引》</text></wd-checkbox>
|
|
|
|
|
|
+ <view
|
|
|
|
+ style="color: #333; font-size: 28rpx"
|
|
|
|
+ class="text-center"
|
|
|
|
+ @click="openPrivacyContract"
|
|
|
|
+ >
|
|
|
|
+ <wd-checkbox :modelValue="isAuth" shape="square">
|
|
|
|
+ <text style="color: #333">《用户隐私保护指引》</text>
|
|
|
|
+ </wd-checkbox>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
@@ -50,28 +64,30 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
-import { useToast } from 'wot-design-uni/components/wd-toast'
|
|
|
|
-import md from 'js-md5'
|
|
|
|
-const username = ref<string>('') // 用户名
|
|
|
|
-const name = ref<string>('') // 密码
|
|
|
|
-const password = ref<string>('')
|
|
|
|
|
|
+import { useToast } from 'wot-design-uni/components/wd-toast';
|
|
|
|
+import md from 'js-md5';
|
|
|
|
+const username = ref<string>(''); // 用户名
|
|
|
|
+const name = ref<string>(''); // 密码
|
|
|
|
+const password = ref<string>('');
|
|
// 验证码
|
|
// 验证码
|
|
-const code = ref('')
|
|
|
|
-const type = ref<number>(0) // 单选框
|
|
|
|
-const toast = useToast()
|
|
|
|
-const { userInfo } = storeToRefs(useAuthStore()) // 解构pinia的store
|
|
|
|
-const router = useRouter() // 路由
|
|
|
|
|
|
+const code = ref('');
|
|
|
|
+const type = ref<number>(0); // 单选框
|
|
|
|
+const toast = useToast();
|
|
|
|
+const { userInfo } = storeToRefs(useAuthStore()); // 解构pinia的store
|
|
|
|
+const router = useRouter(); // 路由
|
|
|
|
|
|
// 登录按钮是否禁用
|
|
// 登录按钮是否禁用
|
|
const disabled = computed(() => {
|
|
const disabled = computed(() => {
|
|
- return !username.value || !name.value || !code.value
|
|
|
|
-})
|
|
|
|
|
|
+ return !username.value || !name.value || !code.value;
|
|
|
|
+});
|
|
// 验证码图片地址
|
|
// 验证码图片地址
|
|
-const codeSrc = ref<string>('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7')
|
|
|
|
-const codeKeyData = ref<string>('')
|
|
|
|
|
|
+const codeSrc = ref<string>(
|
|
|
|
+ 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
|
|
|
|
+);
|
|
|
|
+const codeKeyData = ref<string>('');
|
|
// 验证码焦点
|
|
// 验证码焦点
|
|
-const codeFocus = ref(false)
|
|
|
|
-const codekey = ref('')
|
|
|
|
|
|
+const codeFocus = ref(false);
|
|
|
|
+const codekey = ref('');
|
|
// 获取验证码
|
|
// 获取验证码
|
|
function getCode() {
|
|
function getCode() {
|
|
// 获取image验证码
|
|
// 获取image验证码
|
|
@@ -79,65 +95,69 @@ function getCode() {
|
|
url: 'https://miniapp.zhangmushiye.com/api/blade-auth/oauth/captcha',
|
|
url: 'https://miniapp.zhangmushiye.com/api/blade-auth/oauth/captcha',
|
|
method: 'GET',
|
|
method: 'GET',
|
|
success: (res) => {
|
|
success: (res) => {
|
|
- codeSrc.value = res.data.image
|
|
|
|
- codeKeyData.value = res.data.key
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ codeSrc.value = res.data.image;
|
|
|
|
+ codeKeyData.value = res.data.key;
|
|
|
|
+ },
|
|
|
|
+ });
|
|
}
|
|
}
|
|
-getCode()
|
|
|
|
|
|
+getCode();
|
|
|
|
|
|
// 登录接口
|
|
// 登录接口
|
|
async function doLogin() {
|
|
async function doLogin() {
|
|
if (!isAuth.value) {
|
|
if (!isAuth.value) {
|
|
- toast.error('请先阅读《用户隐私保护指引》')
|
|
|
|
- return
|
|
|
|
|
|
+ toast.error('请先阅读《用户隐私保护指引》');
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
- toast.loading({ loadingType: 'ring', msg: '登录中' })
|
|
|
|
|
|
+ toast.loading({ loadingType: 'ring', msg: '登录中' });
|
|
uni.request({
|
|
uni.request({
|
|
- url: `https://miniapp.zhangmushiye.com/api/blade-auth/oauth/token?password=${md(password.value)}&username=${username.value}&tenantId=000000`,
|
|
|
|
|
|
+ url: `https://miniapp.zhangmushiye.com/api/blade-auth/oauth/token?password=${md(
|
|
|
|
+ password.value
|
|
|
|
+ )}&username=${username.value}&tenantId=000000`,
|
|
data: {
|
|
data: {
|
|
password: md(password.value),
|
|
password: md(password.value),
|
|
username: username.value,
|
|
username: username.value,
|
|
- tenantId: '000000'
|
|
|
|
|
|
+ tenantId: '000000',
|
|
},
|
|
},
|
|
method: 'post',
|
|
method: 'post',
|
|
header: {
|
|
header: {
|
|
'Captcha-Key': codeKeyData.value,
|
|
'Captcha-Key': codeKeyData.value,
|
|
- 'Captcha-Code': code.value
|
|
|
|
|
|
+ 'Captcha-Code': code.value,
|
|
},
|
|
},
|
|
success: (res) => {
|
|
success: (res) => {
|
|
- console.log('🚀 ~ doLogin ~ res:', res)
|
|
|
|
|
|
+ console.log('🚀 ~ doLogin ~ res:', res);
|
|
if (res.data.error_code === 400) {
|
|
if (res.data.error_code === 400) {
|
|
- toast.close()
|
|
|
|
- toast.error(res.data.error_description)
|
|
|
|
- getCode()
|
|
|
|
- return
|
|
|
|
|
|
+ toast.close();
|
|
|
|
+ toast.error(res.data.error_description);
|
|
|
|
+ getCode();
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
if (res.data.access_token) {
|
|
if (res.data.access_token) {
|
|
- toast.close()
|
|
|
|
- toast.success('登录成功')
|
|
|
|
- userInfo.value = res.data
|
|
|
|
|
|
+ toast.close();
|
|
|
|
+ toast.success('登录成功');
|
|
|
|
+ userInfo.value = res.data;
|
|
|
|
+ // 存储token到本地缓存
|
|
|
|
+ uni.setStorageSync('token', res.data.access_token);
|
|
// pages/home/Home
|
|
// pages/home/Home
|
|
uni.switchTab({
|
|
uni.switchTab({
|
|
- url: '/pages/home/Home'
|
|
|
|
- })
|
|
|
|
|
|
+ url: '/pages/home/Home',
|
|
|
|
+ });
|
|
}
|
|
}
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ },
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
// 隐私是否授权
|
|
// 隐私是否授权
|
|
-const isAuth = ref(false)
|
|
|
|
|
|
+const isAuth = ref(false);
|
|
const openPrivacyContract = () => {
|
|
const openPrivacyContract = () => {
|
|
wx.openPrivacyContract({
|
|
wx.openPrivacyContract({
|
|
success: (res) => {
|
|
success: (res) => {
|
|
- isAuth.value = true
|
|
|
|
|
|
+ isAuth.value = true;
|
|
},
|
|
},
|
|
fail: (err) => {
|
|
fail: (err) => {
|
|
- isAuth.value = false
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
-}
|
|
|
|
|
|
+ isAuth.value = false;
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+};
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|