Files
2026-09-08 11:40:15 +08:00

79 lines
1.6 KiB
Vue

<script setup>
import { onLaunch } from '@dcloudio/uni-app'
import { getCurrentInstance } from 'vue'
const { proxy } = getCurrentInstance()
onLaunch(() => {
// iOS 静音键模式下 InnerAudioContext 默认不发声
// #ifdef MP-WEIXIN
try {
uni.setInnerAudioOption({
obeyMuteSwitch: false,
mixWithOther: true,
})
} catch (e) {
console.warn('setInnerAudioOption failed:', e)
}
// #endif
uni.login({
provider: 'weixin',
success: function (loginRes) {
if (uni.getStorageSync('token')) {
userinfo(loginRes.code)
} else {
wxcode(loginRes.code)
}
},
})
})
const wxcode = async (code) => {
try {
const res = await proxy.apiUrl(
{
url: '/api/login/mnpLogin',
method: 'POST',
data: {
code: code,
},
},
false
)
if (res && res.data && res.data.token) {
uni.setStorageSync('token', res.data.token)
uni.setStorageSync('userData', res.data)
}
} catch (err) {}
}
const userinfo = async (code) => {
try {
const res = await proxy.apiUrl(
{
url: '/api/user/info',
method: 'POST',
},
false
)
if (res.code == -1) {
wxcode(code)
return
}
if (res && res.data) {
uni.setStorageSync('userData', res.data)
}
} catch (err) {}
}
</script>
<style>
/* 全局基础 */
page {
background-color: #f4fbf4;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
sans-serif;
}
</style>