modify
This commit is contained in:
parent
80783f4486
commit
5271a56f48
|
|
@ -14,14 +14,15 @@
|
||||||
:columns="2"
|
:columns="2"
|
||||||
:height="'80vh'"
|
:height="'80vh'"
|
||||||
@image-click="handlerClick"
|
@image-click="handlerClick"
|
||||||
|
@load-more-action = "queryList"
|
||||||
>
|
>
|
||||||
|
|
||||||
<template #empty>
|
<!-- <template #empty>
|
||||||
<view class="custom-empty">
|
<view class="custom-empty">
|
||||||
<image src="/static/images/no-videos.png" />
|
<image src="/static/images/no-videos.png" />
|
||||||
<text>没有找到视频内容</text>
|
<text>没有找到视频内容</text>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template> -->
|
||||||
</image-grid-simple>
|
</image-grid-simple>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -32,54 +33,13 @@
|
||||||
return {
|
return {
|
||||||
current:0,
|
current:0,
|
||||||
tabs:[],
|
tabs:[],
|
||||||
list:[
|
list:[],
|
||||||
{
|
pageInfo:{
|
||||||
|
index:1,
|
||||||
"id":1,
|
size:10,
|
||||||
"title":"1",
|
isEnd:false,
|
||||||
"src":"../../static/images/default.png"
|
sub_category_id:0
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":2,
|
|
||||||
"title":2,
|
|
||||||
"src":"../../static/images/default.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":3,
|
|
||||||
"title":3,
|
|
||||||
"src":"../../static/images/default.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":9,
|
|
||||||
"title":9,
|
|
||||||
"src":"../../static/images/default.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":4,
|
|
||||||
"title":4,
|
|
||||||
"src":"../../static/images/default.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":5,
|
|
||||||
"title":5,
|
|
||||||
"src":"../../static/images/default.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":6,
|
|
||||||
"title":6,
|
|
||||||
"src":"../../static/images/default.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":7,
|
|
||||||
"title":7,
|
|
||||||
"src":"../../static/images/default.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":8,
|
|
||||||
"title":8,
|
|
||||||
"src":"../../static/images/default.png"
|
|
||||||
}
|
}
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
|
|
@ -88,21 +48,69 @@
|
||||||
methods: {
|
methods: {
|
||||||
getCategory() {
|
getCategory() {
|
||||||
// 获取分类
|
// 获取分类
|
||||||
this.tabs = [
|
let param = {
|
||||||
{label:"拉布布",value:"labubu"},
|
index:1,
|
||||||
{label:"科幻",value:"kh"},
|
size:1000,
|
||||||
{label:"酷炫汽车1",value:"car1"},
|
target:'sub'
|
||||||
{label:"酷炫汽车2",value:"car2"},
|
}
|
||||||
{label:"酷炫汽车3",value:"car3"},
|
try {
|
||||||
{label:"酷炫汽车4",value:"car4"},
|
this.$http.get('/category/list',param).then((resp)=>{
|
||||||
{label:"酷炫汽车5",value:"car5"},
|
this.tabs = [];
|
||||||
{label:"雏田",value:"ct"}
|
resp.data?.list.forEach((item,idx)=>{
|
||||||
]
|
this.tabs.push({
|
||||||
|
id:item?.id,
|
||||||
|
label:item?.name,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.pageInfo.sub_category_id = this.tabs[this.current].id
|
||||||
|
this.queryList()
|
||||||
|
})
|
||||||
|
} catch(err){
|
||||||
|
console.log("query category error",err)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
handleTabChange(idx) {
|
handleTabChange(idx) {
|
||||||
this.current = idx;
|
this.current = idx;
|
||||||
console.log(this.tabs[idx])
|
this.pageInfo.sub_category_id = this.tabs[this.current].id
|
||||||
|
},
|
||||||
|
queryList() {
|
||||||
|
if (this.pageInfo.isEnd) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '没有更多数据了哦!^v^',
|
||||||
|
icon: 'none',
|
||||||
|
complete: () => {
|
||||||
|
console.log("no more data")
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let param = {
|
||||||
|
...this.pageInfo
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
uni.$http.get('/resource/list',param).then((resp) => {
|
||||||
|
console.log("resp data",resp.data);
|
||||||
|
resp.data?.list.forEach((item,idx)=>{
|
||||||
|
this.list.push({
|
||||||
|
id:item?.id,
|
||||||
|
name:item?.name,
|
||||||
|
src:item?.thumb_src,
|
||||||
|
android_src:item?.android_src,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
console.log("length:",this.list.length,resp.data.page.rows,resp.data.page)
|
||||||
|
if (this.list.length >= resp.data.page.rows) {
|
||||||
|
this.pageInfo.isEnd = true
|
||||||
|
} else {
|
||||||
|
this.pageInfo.isEnd = false
|
||||||
|
this.pageInfo.index++
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}catch(err) {
|
||||||
|
console.log("catch query list err:",err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,11 @@
|
||||||
if (options.id) {
|
if (options.id) {
|
||||||
this.id = options.id;
|
this.id = options.id;
|
||||||
// 这里可以根据id发起请求获取详情数据等操作
|
// 这里可以根据id发起请求获取详情数据等操作
|
||||||
this.$http.get('/resource/'+this.id).then((resp)=>{
|
this.$http.get('/resource/detail/'+this.id).then((resp)=>{
|
||||||
this.url = resp.url
|
console.log("detail:",resp.data)
|
||||||
|
this.url = resp.data?.item.android_src
|
||||||
|
console.log("detail-url:",this.url)
|
||||||
|
|
||||||
}).catch((err)=>{
|
}).catch((err)=>{
|
||||||
console.log('请求异常')
|
console.log('请求异常')
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,9 @@
|
||||||
{ label: '最新', name: 'new', badge: 0 },
|
{ label: '最新', name: 'new', badge: 0 },
|
||||||
],
|
],
|
||||||
page:1,
|
page:1,
|
||||||
size:4,
|
size:6,
|
||||||
tag:'hot',
|
tag:'hot',
|
||||||
|
isEnd:false,
|
||||||
videoConfig:{
|
videoConfig:{
|
||||||
"columns":2
|
"columns":2
|
||||||
},
|
},
|
||||||
|
|
@ -55,6 +56,10 @@
|
||||||
handleTabChange(idx) {
|
handleTabChange(idx) {
|
||||||
this.current = idx;
|
this.current = idx;
|
||||||
this.tag = this.tabs[idx]?.name
|
this.tag = this.tabs[idx]?.name
|
||||||
|
this.isEnd = false
|
||||||
|
this.list = []
|
||||||
|
this.page = 1
|
||||||
|
this.queryList()
|
||||||
},
|
},
|
||||||
handlerClick(item) {
|
handlerClick(item) {
|
||||||
console.log("video click",item)
|
console.log("video click",item)
|
||||||
|
|
@ -68,8 +73,18 @@
|
||||||
handleLoginSuccess(event) {
|
handleLoginSuccess(event) {
|
||||||
console.log('检测到登录成功,刷新首页数据');
|
console.log('检测到登录成功,刷新首页数据');
|
||||||
this.queryList()
|
this.queryList()
|
||||||
},
|
},
|
||||||
queryList() {
|
queryList() {
|
||||||
|
if (this.isEnd) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '没有更多数据了哦!^v^',
|
||||||
|
icon: 'none',
|
||||||
|
complete: () => {
|
||||||
|
console.log("no more data")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return
|
||||||
|
}
|
||||||
let param = {
|
let param = {
|
||||||
index:this.page,
|
index:this.page,
|
||||||
size:this.size,
|
size:this.size,
|
||||||
|
|
@ -84,8 +99,14 @@
|
||||||
name:item?.name,
|
name:item?.name,
|
||||||
src:item?.thumb_src,
|
src:item?.thumb_src,
|
||||||
android_src:item?.android_src,
|
android_src:item?.android_src,
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
console.log("length:",this.list.length,resp.data.page.rows,resp.data.page)
|
||||||
|
if (this.list.length >= resp.data.page.rows) {
|
||||||
|
this.isEnd = true
|
||||||
|
} else {
|
||||||
|
this.isEnd = false
|
||||||
|
}
|
||||||
this.page++
|
this.page++
|
||||||
})
|
})
|
||||||
}catch(err) {
|
}catch(err) {
|
||||||
|
|
|
||||||
|
|
@ -1,58 +1,17 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
const common_vendor = require("../../common/vendor.js");
|
const common_vendor = require("../../common/vendor.js");
|
||||||
const common_assets = require("../../common/assets.js");
|
|
||||||
const _sfc_main = {
|
const _sfc_main = {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
current: 0,
|
current: 0,
|
||||||
tabs: [],
|
tabs: [],
|
||||||
list: [
|
list: [],
|
||||||
{
|
pageInfo: {
|
||||||
"id": 1,
|
index: 1,
|
||||||
"title": "1",
|
size: 10,
|
||||||
"src": "../../static/images/default.png"
|
isEnd: false,
|
||||||
},
|
sub_category_id: 0
|
||||||
{
|
|
||||||
"id": 2,
|
|
||||||
"title": 2,
|
|
||||||
"src": "../../static/images/default.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 3,
|
|
||||||
"title": 3,
|
|
||||||
"src": "../../static/images/default.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 9,
|
|
||||||
"title": 9,
|
|
||||||
"src": "../../static/images/default.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 4,
|
|
||||||
"title": 4,
|
|
||||||
"src": "../../static/images/default.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 5,
|
|
||||||
"title": 5,
|
|
||||||
"src": "../../static/images/default.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 6,
|
|
||||||
"title": 6,
|
|
||||||
"src": "../../static/images/default.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 7,
|
|
||||||
"title": 7,
|
|
||||||
"src": "../../static/images/default.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 8,
|
|
||||||
"title": 8,
|
|
||||||
"src": "../../static/images/default.png"
|
|
||||||
}
|
}
|
||||||
]
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
|
|
@ -60,20 +19,69 @@ const _sfc_main = {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getCategory() {
|
getCategory() {
|
||||||
this.tabs = [
|
let param = {
|
||||||
{ label: "拉布布", value: "labubu" },
|
index: 1,
|
||||||
{ label: "科幻", value: "kh" },
|
size: 1e3,
|
||||||
{ label: "酷炫汽车1", value: "car1" },
|
target: "sub"
|
||||||
{ label: "酷炫汽车2", value: "car2" },
|
};
|
||||||
{ label: "酷炫汽车3", value: "car3" },
|
try {
|
||||||
{ label: "酷炫汽车4", value: "car4" },
|
this.$http.get("/category/list", param).then((resp) => {
|
||||||
{ label: "酷炫汽车5", value: "car5" },
|
var _a;
|
||||||
{ label: "雏田", value: "ct" }
|
this.tabs = [];
|
||||||
];
|
(_a = resp.data) == null ? void 0 : _a.list.forEach((item, idx) => {
|
||||||
|
this.tabs.push({
|
||||||
|
id: item == null ? void 0 : item.id,
|
||||||
|
label: item == null ? void 0 : item.name
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.pageInfo.sub_category_id = this.tabs[this.current].id;
|
||||||
|
this.queryList();
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.log("query category error", err);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
handleTabChange(idx) {
|
handleTabChange(idx) {
|
||||||
this.current = idx;
|
this.current = idx;
|
||||||
console.log(this.tabs[idx]);
|
this.pageInfo.sub_category_id = this.tabs[this.current].id;
|
||||||
|
},
|
||||||
|
queryList() {
|
||||||
|
if (this.pageInfo.isEnd) {
|
||||||
|
common_vendor.index.showToast({
|
||||||
|
title: "没有更多数据了哦!^v^",
|
||||||
|
icon: "none",
|
||||||
|
complete: () => {
|
||||||
|
console.log("no more data");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let param = {
|
||||||
|
...this.pageInfo
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
common_vendor.index.$http.get("/resource/list", param).then((resp) => {
|
||||||
|
var _a;
|
||||||
|
console.log("resp data", resp.data);
|
||||||
|
(_a = resp.data) == null ? void 0 : _a.list.forEach((item, idx) => {
|
||||||
|
this.list.push({
|
||||||
|
id: item == null ? void 0 : item.id,
|
||||||
|
name: item == null ? void 0 : item.name,
|
||||||
|
src: item == null ? void 0 : item.thumb_src,
|
||||||
|
android_src: item == null ? void 0 : item.android_src
|
||||||
|
});
|
||||||
|
});
|
||||||
|
console.log("length:", this.list.length, resp.data.page.rows, resp.data.page);
|
||||||
|
if (this.list.length >= resp.data.page.rows) {
|
||||||
|
this.pageInfo.isEnd = true;
|
||||||
|
} else {
|
||||||
|
this.pageInfo.isEnd = false;
|
||||||
|
this.pageInfo.index++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.log("catch query list err:", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -96,8 +104,8 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||||
scrollEnable: true,
|
scrollEnable: true,
|
||||||
activeColor: "#19c324"
|
activeColor: "#19c324"
|
||||||
}),
|
}),
|
||||||
c: common_assets._imports_0,
|
c: common_vendor.o(_ctx.handlerClick),
|
||||||
d: common_vendor.o(_ctx.handlerClick),
|
d: common_vendor.o($options.queryList),
|
||||||
e: common_vendor.p({
|
e: common_vendor.p({
|
||||||
imageList: $data.list,
|
imageList: $data.list,
|
||||||
columns: 2,
|
columns: 2,
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
<smart-tabs wx:if="{{b}}" bindchange="{{a}}" u-i="684df9a6-0" bind:__l="__l" u-p="{{b}}"></smart-tabs><view class="video-container"><image-grid-simple wx:if="{{e}}" u-s="{{['empty']}}" bindimageClick="{{d}}" u-i="684df9a6-1" bind:__l="__l" u-p="{{e}}"><view class="custom-empty" slot="empty"><image src="{{c}}"/><text>没有找到视频内容</text></view></image-grid-simple></view>
|
<smart-tabs wx:if="{{b}}" bindchange="{{a}}" u-i="684df9a6-0" bind:__l="__l" u-p="{{b}}"></smart-tabs><view class="video-container"><image-grid-simple wx:if="{{e}}" bindimageClick="{{c}}" bindloadMoreAction="{{d}}" u-i="684df9a6-1" bind:__l="__l" u-p="{{e}}"></image-grid-simple></view>
|
||||||
|
|
@ -33,8 +33,11 @@ const _sfc_main = {
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
if (options.id) {
|
if (options.id) {
|
||||||
this.id = options.id;
|
this.id = options.id;
|
||||||
this.$http.get("/resource/" + this.id).then((resp) => {
|
this.$http.get("/resource/detail/" + this.id).then((resp) => {
|
||||||
this.url = resp.url;
|
var _a;
|
||||||
|
console.log("detail:", resp.data);
|
||||||
|
this.url = (_a = resp.data) == null ? void 0 : _a.item.android_src;
|
||||||
|
console.log("detail-url:", this.url);
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.log("请求异常");
|
console.log("请求异常");
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,9 @@ const _sfc_main = {
|
||||||
{ label: "最新", name: "new", badge: 0 }
|
{ label: "最新", name: "new", badge: 0 }
|
||||||
],
|
],
|
||||||
page: 1,
|
page: 1,
|
||||||
size: 4,
|
size: 6,
|
||||||
tag: "hot",
|
tag: "hot",
|
||||||
|
isEnd: false,
|
||||||
videoConfig: {
|
videoConfig: {
|
||||||
"columns": 2
|
"columns": 2
|
||||||
},
|
},
|
||||||
|
|
@ -32,6 +33,10 @@ const _sfc_main = {
|
||||||
var _a;
|
var _a;
|
||||||
this.current = idx;
|
this.current = idx;
|
||||||
this.tag = (_a = this.tabs[idx]) == null ? void 0 : _a.name;
|
this.tag = (_a = this.tabs[idx]) == null ? void 0 : _a.name;
|
||||||
|
this.isEnd = false;
|
||||||
|
this.list = [];
|
||||||
|
this.page = 1;
|
||||||
|
this.queryList();
|
||||||
},
|
},
|
||||||
handlerClick(item) {
|
handlerClick(item) {
|
||||||
console.log("video click", item);
|
console.log("video click", item);
|
||||||
|
|
@ -47,6 +52,16 @@ const _sfc_main = {
|
||||||
this.queryList();
|
this.queryList();
|
||||||
},
|
},
|
||||||
queryList() {
|
queryList() {
|
||||||
|
if (this.isEnd) {
|
||||||
|
common_vendor.index.showToast({
|
||||||
|
title: "没有更多数据了哦!^v^",
|
||||||
|
icon: "none",
|
||||||
|
complete: () => {
|
||||||
|
console.log("no more data");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
let param = {
|
let param = {
|
||||||
index: this.page,
|
index: this.page,
|
||||||
size: this.size,
|
size: this.size,
|
||||||
|
|
@ -64,6 +79,12 @@ const _sfc_main = {
|
||||||
android_src: item == null ? void 0 : item.android_src
|
android_src: item == null ? void 0 : item.android_src
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
console.log("length:", this.list.length, resp.data.page.rows, resp.data.page);
|
||||||
|
if (this.list.length >= resp.data.page.rows) {
|
||||||
|
this.isEnd = true;
|
||||||
|
} else {
|
||||||
|
this.isEnd = false;
|
||||||
|
}
|
||||||
this.page++;
|
this.page++;
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
||||||
|
|
@ -13,16 +13,16 @@ const silentLogin = async () => {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
console.log("静默登录", token);
|
console.log("静默登录", token);
|
||||||
let newToken;
|
let data;
|
||||||
if (utils_config.PLATFORM === "mp-weixin") {
|
if (utils_config.PLATFORM === "mp-weixin") {
|
||||||
newToken = await wxSilentLogin();
|
data = await wxSilentLogin();
|
||||||
console.log("newToken~~~~~~~~~");
|
|
||||||
}
|
}
|
||||||
if (newToken) {
|
if (data) {
|
||||||
console.log("静默登录-----", newToken);
|
console.log("静默登录-----", data.token);
|
||||||
saveLocalToken(newToken);
|
saveLocalToken(data.token);
|
||||||
common_vendor.index.$emit("LOGIN_SUCCESS", { token: newToken });
|
saveUserInfo(data.user);
|
||||||
return newToken;
|
common_vendor.index.$emit("LOGIN_SUCCESS", { token: data.token });
|
||||||
|
return data.token;
|
||||||
}
|
}
|
||||||
throw new Error("静默登录失败");
|
throw new Error("静默登录失败");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -60,8 +60,8 @@ const wxSilentLogin = async () => {
|
||||||
fail: reject
|
fail: reject
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
if (response.code === 200 && response.data.token) {
|
if (response.code === 200) {
|
||||||
return response.data.token;
|
return response.data;
|
||||||
}
|
}
|
||||||
throw new Error(response.msg || "微信登录失败");
|
throw new Error(response.msg || "微信登录失败");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -103,8 +103,8 @@ const ksSilentLogin = async () => {
|
||||||
fail: reject
|
fail: reject
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
if (res.code === 0 && res.data.token) {
|
if (res.code === 0) {
|
||||||
return res.data.token;
|
return res.data;
|
||||||
}
|
}
|
||||||
throw new Error(res.msg || "快手登录失败");
|
throw new Error(res.msg || "快手登录失败");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -120,6 +120,9 @@ const saveLocalToken = (token) => {
|
||||||
const tokenKey = "wx_token";
|
const tokenKey = "wx_token";
|
||||||
common_vendor.index.setStorageSync(tokenKey, token);
|
common_vendor.index.setStorageSync(tokenKey, token);
|
||||||
};
|
};
|
||||||
|
const saveUserInfo = (user) => {
|
||||||
|
common_vendor.index.setStorageSync("user-info", user);
|
||||||
|
};
|
||||||
const checkLoginStatus = async () => {
|
const checkLoginStatus = async () => {
|
||||||
try {
|
try {
|
||||||
const token = getLocalToken();
|
const token = getLocalToken();
|
||||||
|
|
|
||||||
|
|
@ -17,23 +17,23 @@ export const silentLogin = async () => {
|
||||||
|
|
||||||
console.log("静默登录",token)
|
console.log("静默登录",token)
|
||||||
// 2. 执行平台静默登录
|
// 2. 执行平台静默登录
|
||||||
let newToken;
|
let data;
|
||||||
if (PLATFORM === 'mp-weixin') {
|
if (PLATFORM === 'mp-weixin') {
|
||||||
newToken = await wxSilentLogin();
|
data = await wxSilentLogin();
|
||||||
console.log("newToken~~~~~~~~~")
|
|
||||||
} else if (PLATFORM === 'mp-kuaishou') {
|
} else if (PLATFORM === 'mp-kuaishou') {
|
||||||
newToken = await ksSilentLogin();
|
data = await ksSilentLogin();
|
||||||
} else {
|
} else {
|
||||||
// 待处理
|
// 待处理
|
||||||
throw new Error("当前平台不支持")
|
throw new Error("当前平台不支持")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 保存token
|
// 3. 保存token
|
||||||
if (newToken) {
|
if (data) {
|
||||||
console.log("静默登录-----",newToken)
|
console.log("静默登录-----",data.token)
|
||||||
saveLocalToken(newToken);
|
saveLocalToken(data.token);
|
||||||
uni.$emit('LOGIN_SUCCESS', { token: newToken });
|
saveUserInfo(data.user)
|
||||||
return newToken;
|
uni.$emit('LOGIN_SUCCESS', { token: data.token });
|
||||||
|
return data.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('静默登录失败');
|
throw new Error('静默登录失败');
|
||||||
|
|
@ -81,8 +81,8 @@ const wxSilentLogin = async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// 4. 处理登录响应
|
// 4. 处理登录响应
|
||||||
if (response.code === 200 && response.data.token) {
|
if (response.code === 200) {
|
||||||
return response.data.token;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(response.msg || '微信登录失败');
|
throw new Error(response.msg || '微信登录失败');
|
||||||
|
|
@ -135,8 +135,8 @@ const ksSilentLogin = async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// 3. 返回token
|
// 3. 返回token
|
||||||
if (res.code === 0 && res.data.token) {
|
if (res.code === 0) {
|
||||||
return res.data.token;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(res.msg || '快手登录失败');
|
throw new Error(res.msg || '快手登录失败');
|
||||||
|
|
@ -158,6 +158,11 @@ const saveLocalToken = (token) => {
|
||||||
uni.setStorageSync(tokenKey, token);
|
uni.setStorageSync(tokenKey, token);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 保存用户信息
|
||||||
|
const saveUserInfo = (user) => {
|
||||||
|
uni.setStorageSync('user-info', user);
|
||||||
|
};
|
||||||
|
|
||||||
// 获取用户信息(需要授权)
|
// 获取用户信息(需要授权)
|
||||||
export const getUserInfo = async () => {
|
export const getUserInfo = async () => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue