feat: 登录态处理

This commit is contained in:
eric
2022-11-21 17:37:24 +08:00
parent 692799c503
commit df6e9e7820
7 changed files with 120 additions and 8 deletions

View File

@@ -1,10 +1,16 @@
import { Button, Cell } from "@antmjs/vantui";
import { Button, Cell, Toast } from "@antmjs/vantui";
import { RichText, View } from "@tarojs/components";
import Taro, { getCurrentInstance } from "@tarojs/taro";
import react, { useEffect, useState } from "react";
import { getTable, getTableid } from "../../../../utils/index";
import {
addTable,
getTable,
getTableid,
updateTableid,
} from "../../../../utils/index";
import "./index.scss";
import { Image } from "@antmjs/vantui";
import _ from "lodash";
const details = () => {
const [dataSource, setdataSource] = useState<any>([]);
@@ -39,6 +45,33 @@ const details = () => {
// console.log('SafeAreaResult',Taro.getSystemInfoSync())
const btnStatus = [
{
label: "活动待开放",
value: "0",
},
{
label: "立即报名", //开放中
value: "1",
},
{
label: "活动已取消",
value: "2",
},
{
label: "活动进行中",
value: "3",
},
{
label: "活动已结束",
value: "4",
},
{
label: "活动已关闭",
value: "5",
},
];
return (
<View className={`detailContent`}>
<View>
@@ -58,6 +91,13 @@ const details = () => {
// linkType="navigateTo"
// url="/pages/dashboard/index"
/>
<Cell
icon="clock"
title={`结束时间 ${dataSource?.endTime}`}
// isLink
// linkType="navigateTo"
// url="/pages/dashboard/index"
/>
<Cell
isLink
icon="location"
@@ -68,7 +108,7 @@ const details = () => {
<Cell
icon="friends"
title={`已报名人数 ${dataSource?.useridArr?.length??0}`}
title={`已报名人数 ${dataSource?.useridArr?.length ?? 0}`}
// isLink
// linkType="navigateTo"
// url="/pages/dashboard/index"
@@ -100,11 +140,77 @@ const details = () => {
<View
className={`detailBtn`}
style={{ bottom: `${bottomheight ?? 0}px` }}
onClick={() => {
// 检查登录态,获取openid
Taro.checkSession({
success: function (res: any) {
//session_key 未过期,并且在本生命周期一直有效
console.log("res", res);
// 获取用户openid
},
fail: function (err: any) {
console.log("err", err);
// session_key 已经失效,需要重新执行登录流程
//重新登录- 跳转到我的页面
Toast.fail({
message: '请先登录',
selector: '#vanToast-demo2',
duration:2000,
onClose: () => {
// 跳转到目的页面,打开新页面
Taro.navigateTo({
url: "/pages/my/index",
});
},
})
// Taro.login({
// success:(res:any)=>{
// console.log('sures--',res)
// // 获取code,获取用户的openid
// },fail:(err:any)=>{
// console.log("err",err)
// }
// })
},
});
// console.log('id',id)
// // 立即报名
// let postData={
// // env: "any",
// id:id,
// tableName: "details",
// objData: {
// // ..._.cloneDeep(dataSource),
// useridArr:['openid']
// },
// okFun: (res:any)=>{
// console.log('res',res)
// }
// }
// console.log('postData',postData)
// updateTableid({...postData})
}}
>
{/* style={{width:'375px'}} */}
<Button type="primary" block>
立即参加
<Button
type="primary"
block
disabled={!["1"].includes(dataSource?.Status)}
>
{/* 立即参加 */}
{btnStatus.map((item: any) => {
let status: any = dataSource?.Status;
if (item?.value === status) {
return item?.label;
}
})}
</Button>
<Toast id="vanToast-demo2" />
</View>
</View>
);

View File

@@ -36,6 +36,7 @@ export const addTable: any = ({ env,tableName, objData, okFun }: Typeint) => {
});
};
// 获取指定集合数据表
export const getTable: any = ({ env,tableName, okFun }: Typeint) => {
// 数据库环境
@@ -77,6 +78,7 @@ export const updateTableid: any = ({ env,tableName,objData, id, okFun }: Typeint
});
let nowtable: any = db?.collection(tableName);
nowtable.doc(id).update({
// nowtable.doc(id).set({
// data 传入需要局部更新的数据
data: objData,
success: (res: any) => {