Signed-off-by: 吴文峰 <kevin@lmve.net>
This commit is contained in:
2026-04-17 20:46:21 +08:00
parent 3bb51d0794
commit 8dce0346a7
10 changed files with 370 additions and 78 deletions
+39 -1
View File
@@ -6,14 +6,21 @@
<button class="submit-btn" @click="handleLogin">登录</button>
</view>
</view>
<my-toast ref="toast" />
</template>
<script setup>
import { ref } from 'vue'
import { useConfigStore } from '../../stores/config'
import { userApi } from '../../api/user'
const useConfig =useConfigStore()
const username = ref('')
const password = ref('')
const toast = ref(null)
const handleLogin = () => {
if (!username.value || !password.value) {
uni.showToast({
@@ -23,7 +30,38 @@ const handleLogin = () => {
return
}
// TODO: 调用登录接口
console.log('登录信息:', username.value, password.value)
console.log('登录信息:', username.value, password.value,useConfig.getApiBaseUrl())
//userApi.login(username.value,password.value,true)
uni.request({
url: useConfig.getApiBaseUrl()+"/users/login",
method: 'POST',
timeout:1000,
header: {
'Content-Type': 'application/json'
},
data:{
"username": username.value,
"password": password.value,
"remember": true
},
success: (res) => {
console.log('成功', res)
switch(res.statusCode){
case 200:
toast.value.success('成功')
break;
default:
toast.value.error('服务异常')
break
}
},
fail: (err) => {
console.log('失败', err)
toast.value.error('网异常')
},
})
}
</script>