@@ -159,7 +159,23 @@
|
||||
methods:{
|
||||
switchTheme(theme){
|
||||
myfunc.setTheme(theme,true);
|
||||
}
|
||||
},
|
||||
logout(){
|
||||
myfunc.dele("user_info")
|
||||
myfunc.dele("cookie")
|
||||
},
|
||||
updata_user_info_to_heard(){
|
||||
//h5先判断有没有cookie
|
||||
var cookie=myfunc.load_json("cookie")
|
||||
if (cookie){
|
||||
//判断cookie有没有过期
|
||||
}else{
|
||||
this.logout()
|
||||
}
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.updata_user_info_to_heard()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
+11
-1
@@ -1,9 +1,19 @@
|
||||
import { myfunc } from "./myfunc";
|
||||
|
||||
export const my_network_func = {
|
||||
host: "",
|
||||
port: 0,
|
||||
head_path: "/api/v1",
|
||||
|
||||
post_json(path, json,callback) {
|
||||
//把cookie插入json
|
||||
var data={}
|
||||
data['data']=json
|
||||
var cookie =myfunc.load_json("cookie")
|
||||
if(cookie)
|
||||
{
|
||||
data['cookie']=cookie
|
||||
}
|
||||
var re_data = {}
|
||||
uni.request({
|
||||
header: {
|
||||
@@ -11,7 +21,7 @@ export const my_network_func = {
|
||||
},
|
||||
url: this.head_path + path,
|
||||
method: 'POST',
|
||||
data: json,
|
||||
data: data,
|
||||
timeout: 10000,
|
||||
success(res) {
|
||||
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
right: 0;
|
||||
left: 0;
|
||||
|
||||
height: 100rpx;
|
||||
height: 85rpx;
|
||||
margin-left: 20rpx;
|
||||
margin-right: 20rpx;
|
||||
margin-top: 20rpx;
|
||||
|
||||
+26
-2
@@ -2,15 +2,39 @@ export const myfunc = {
|
||||
|
||||
themeStorageKey:"tablerTheme",
|
||||
defaultTheme:"light",
|
||||
|
||||
save(key,data){
|
||||
uni.setStorageSync(key, data)
|
||||
},
|
||||
load(key){
|
||||
return uni.getStorageSync(key)
|
||||
},
|
||||
dele(key){
|
||||
uni.removeStorageSync(key)
|
||||
},
|
||||
|
||||
save_json(key,data){
|
||||
this.save(key,JSON.stringify(data))
|
||||
},
|
||||
|
||||
load_json(key){
|
||||
var js_data=this.load(key)
|
||||
if(js_data){
|
||||
return JSON.parse(js_data)
|
||||
}else{
|
||||
return null
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
getThemefromStorge() {
|
||||
var storedTheme = localStorage.getItem(this.themeStorageKey);
|
||||
var storedTheme = this.load(this.themeStorageKey);
|
||||
return storedTheme ? storedTheme : this.defaultTheme;
|
||||
},
|
||||
|
||||
setTheme(selectedTheme,save) {
|
||||
if(save){
|
||||
localStorage.setItem(this.themeStorageKey, selectedTheme); // 保存到本地存储
|
||||
this.save(this.themeStorageKey, selectedTheme); // 保存到本地存储
|
||||
}
|
||||
if (selectedTheme === 'dark') {
|
||||
document.body.setAttribute("data-bs-theme", selectedTheme); // 暗色模式
|
||||
|
||||
+43
-13
@@ -35,14 +35,14 @@
|
||||
maxlength="100" v-model="post_data.password">
|
||||
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<!-- <div class="mb-2">
|
||||
<checkbox-group @change="chack_box_change">
|
||||
<label class="d-flex">
|
||||
<checkbox value="keep_login_in" />
|
||||
<span class="form-check-label">保持登录</span>
|
||||
</label>
|
||||
</checkbox-group>
|
||||
</div>
|
||||
</div> -->
|
||||
<div class="form-footer">
|
||||
<button class="btn btn-primary w-100" @click="submit_data">登录</button>
|
||||
</div>
|
||||
@@ -72,7 +72,7 @@
|
||||
<tabler-footer ref="footer"></tabler-footer>
|
||||
</view>
|
||||
|
||||
|
||||
|
||||
|
||||
</template>
|
||||
|
||||
@@ -80,24 +80,35 @@
|
||||
import {
|
||||
my_network_func
|
||||
} from '../my_network_func'
|
||||
import {
|
||||
myfunc
|
||||
} from '../myfunc'
|
||||
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
ph_username: "输入你的用户名",
|
||||
ph_password: "输入你的密码",
|
||||
ph_username: "",
|
||||
ph_password: "",
|
||||
is_username_err: false,
|
||||
is_password_err: false,
|
||||
post_data: {
|
||||
is_keep_login: false,
|
||||
is_keep_login: true,
|
||||
username: "",
|
||||
password: "",
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
initdata(){
|
||||
this.ph_username="输入你的用户名"
|
||||
this.ph_password="输入你的密码"
|
||||
this.is_username_err=false
|
||||
this.is_password_err=false
|
||||
this.post_data.is_keep_login=true
|
||||
this.post_data.username=""
|
||||
this.post_data.password=""
|
||||
},
|
||||
|
||||
chack_box_change(val) {
|
||||
//console.log(val.detail.value[0])
|
||||
@@ -110,8 +121,8 @@
|
||||
submit_data() {
|
||||
//提交登录数据,
|
||||
//先验证数据合法性
|
||||
this.$refs.footer.alert('success',"123")
|
||||
|
||||
|
||||
|
||||
if (this.post_data.username == "") {
|
||||
this.is_username_err = true
|
||||
this.ph_username = "用户名不能为空"
|
||||
@@ -132,14 +143,35 @@
|
||||
console.log(this.post_data)
|
||||
my_network_func.post_json("/user/login", this.post_data, (c) => {
|
||||
console.log(c)
|
||||
if (c.statusCode == 200) {
|
||||
if (c.data.err_code == 0) {
|
||||
this.$refs.footer.alert('success', "登录成功")
|
||||
myfunc.save_json("cookie", c.data.return.cookie)
|
||||
myfunc.save_json("user_info", c.data.return.user_info)
|
||||
this.initdata()
|
||||
setTimeout(() => {
|
||||
uni.navigateTo({
|
||||
url: '/'
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
} else {
|
||||
this.$refs.footer.alert('warning', "账号或密码不正确")
|
||||
}
|
||||
} else {
|
||||
this.$refs.footer.alert('danger', "网络连接错误:" + c.statusCode)
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.initdata()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -157,6 +189,4 @@
|
||||
font-size: 24px;
|
||||
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user