feat: 上传打卡记录
This commit is contained in:
@@ -11,6 +11,8 @@ export default {
|
||||
"pages/my/index",
|
||||
"pages/my/components/Version/index",
|
||||
"pages/my/components/AbountUs/index",
|
||||
"pages/my/components/CheckinDetail/index", //打卡详情
|
||||
|
||||
|
||||
],
|
||||
permission: {
|
||||
|
||||
@@ -17,11 +17,14 @@ import { getCurrentInstance } from "@tarojs/taro";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import "./index.scss";
|
||||
import { Uploader } from "@antmjs/vantui";
|
||||
import { getparams, getTable, updateTableid } from "../../../../utils/index";
|
||||
|
||||
const CheckIn = () => {
|
||||
const formIt = Form.useForm();
|
||||
const [bottomheight, setbottomheight] = useState(0);
|
||||
const [cloudfileID, setcloudfileID] = useState();
|
||||
const [address, setaddress] = useState(); //地址
|
||||
const [openid, setopenid] = useState();
|
||||
|
||||
const [value, setValue] = useState([
|
||||
// {
|
||||
@@ -62,9 +65,12 @@ const CheckIn = () => {
|
||||
definePageConfig({
|
||||
navigationBarTitleText: "打卡签到",
|
||||
});
|
||||
|
||||
|
||||
}, []);
|
||||
|
||||
let $instance: any = getCurrentInstance();
|
||||
console.log('$instance?.router?.params;',$instance?.router?.params)
|
||||
const { fileID } = $instance?.router?.params;
|
||||
console.log("fileID---", fileID);
|
||||
|
||||
@@ -72,6 +78,15 @@ const CheckIn = () => {
|
||||
if ($instance?.router?.params?.fileID) {
|
||||
uploadTaro([fileID]);
|
||||
}
|
||||
|
||||
Taro.cloud.callFunction({
|
||||
name: "getOpenid",
|
||||
complete: async (res: any) => {
|
||||
// console.log("callFunction test result: ", res);
|
||||
let openid = res?.result?.event?.userInfo?.openId;
|
||||
setopenid(openid);
|
||||
},
|
||||
});
|
||||
}, []);
|
||||
|
||||
const uploadTaro = (tempFilePaths: any) => {
|
||||
@@ -128,53 +143,86 @@ const CheckIn = () => {
|
||||
value=""
|
||||
icon="location"
|
||||
isLink
|
||||
onClick={() => {
|
||||
Taro.chooseLocation({
|
||||
success: (res: any) => {
|
||||
console.log("res", res);
|
||||
const { address } = res;
|
||||
setaddress(res?.address);
|
||||
// setaddress(res?.name)
|
||||
|
||||
// address: "广东省深圳市宝安区创业一路1号"
|
||||
// errMsg: "chooseLocation:ok"
|
||||
// latitude: 22.55329 //纬度
|
||||
// longitude: 113.88308 //经度
|
||||
// name: "宝安区创业一路(深圳市宝安区人民政府)"
|
||||
},
|
||||
});
|
||||
}}
|
||||
renderTitle={
|
||||
<View>
|
||||
<View className="title">深圳梧桐山</View>
|
||||
<View className="address">{address}</View>
|
||||
</View>
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
|
||||
{/* 文件上传 */}
|
||||
{/* <Uploader
|
||||
fileList={value}
|
||||
onAfterRead={afterRead}
|
||||
onDelete={deleteAction}
|
||||
deletable
|
||||
maxCount={1}
|
||||
/> */}
|
||||
|
||||
<View
|
||||
style={{
|
||||
bottom: `${bottomheight ?? 0}px`,
|
||||
position: "fixed",
|
||||
width: "95%",
|
||||
}}
|
||||
onClick={() => {
|
||||
onClick={async () => {
|
||||
// formIt?.submit()
|
||||
formIt?.validateFields((errorMessage: any, fieldValues: any) => {
|
||||
console.log("fieldValues---", fieldValues);
|
||||
|
||||
// 提交打卡记录
|
||||
let postData = {
|
||||
imagePath: cloudfileID,
|
||||
remark: fieldValues?.remark,
|
||||
};
|
||||
// xxxsubmit()
|
||||
Toast.success({
|
||||
message: "打卡成功",
|
||||
selector: "#vanToast-demo2",
|
||||
duration: 2000,
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
// 返回首页 [上一页]
|
||||
Taro.navigateBack({
|
||||
// url: "/pages/home/index",
|
||||
delta: 1,
|
||||
});
|
||||
}, 2000);
|
||||
let postData = {
|
||||
tableName: "userInfo",
|
||||
keyValue: { openId: openid },
|
||||
okFun: (res: any) => {
|
||||
console.log("提交打卡,res", res);
|
||||
|
||||
let newobj = {
|
||||
tableName: "userInfo",
|
||||
id: res?.data?.[0]?._id,
|
||||
objData: {
|
||||
checkInArr: [
|
||||
...(res?.data?.[0]?.checkInArr ?? []),
|
||||
{
|
||||
imageUrl: cloudfileID,
|
||||
remark: fieldValues?.remark,
|
||||
location: address,
|
||||
},
|
||||
],
|
||||
},
|
||||
okFun: (okFunres: any) => {
|
||||
console.log("提交打卡,res", okFunres);
|
||||
Toast.success({
|
||||
message: "打卡成功",
|
||||
selector: "#vanToast-demo2",
|
||||
duration: 2000,
|
||||
onClose: () => {
|
||||
// 跳转到打卡页面
|
||||
|
||||
// 返回首页 [上一页]
|
||||
Taro.navigateBack({
|
||||
// url: "/pages/home/index",
|
||||
delta: 1,
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
updateTableid({ ...newobj });
|
||||
},
|
||||
};
|
||||
|
||||
// 查询openid
|
||||
getTable({ ...postData });
|
||||
});
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -17,7 +17,7 @@ import { NoticeBar } from "@antmjs/vantui";
|
||||
import Taro from "@tarojs/taro";
|
||||
import { Tabbar, TabbarItem } from "@antmjs/vantui";
|
||||
import TabbarCom from "../components/TabbarCom";
|
||||
import { getTable, getTableid } from "../../utils/index";
|
||||
import { getTable, getTableid, phoneLogin } from "../../utils/index";
|
||||
import { Icon } from "@antmjs/vantui";
|
||||
import "./index.scss";
|
||||
import { Search } from "@antmjs/vantui";
|
||||
@@ -39,6 +39,8 @@ const Home = () => {
|
||||
// 系统配置
|
||||
const [systemConfig, setsystemConfig] = useState<any>({});
|
||||
|
||||
// const [openid,setopenid]=useState()
|
||||
|
||||
const onChange = (e) => {};
|
||||
|
||||
useEffect(() => {
|
||||
@@ -56,11 +58,12 @@ const Home = () => {
|
||||
success() {},
|
||||
});
|
||||
|
||||
getdetails(); //获取活动详情
|
||||
getsystemConfig(); //获取系统配置
|
||||
getdetails(); //获取活动详情
|
||||
|
||||
}, []);
|
||||
|
||||
const getdetails = () => {
|
||||
const getdetails = async () => {
|
||||
let objParams = {
|
||||
tableName: "details",
|
||||
// id: "80516fb66370bcf300b8f43c5f4dd52b",
|
||||
@@ -69,10 +72,10 @@ const Home = () => {
|
||||
setdetails(res?.data ?? []);
|
||||
},
|
||||
};
|
||||
getTable(objParams);
|
||||
await getTable(objParams);
|
||||
};
|
||||
|
||||
const getsystemConfig = () => {
|
||||
const getsystemConfig = async () => {
|
||||
let objParams = {
|
||||
tableName: "systemConfig",
|
||||
// id: "80516fb66370bcf300b8f43c5f4dd52b",
|
||||
@@ -81,7 +84,7 @@ const Home = () => {
|
||||
setsystemConfig(res?.data ?? []);
|
||||
},
|
||||
};
|
||||
getTable(objParams);
|
||||
await getTable(objParams);
|
||||
};
|
||||
|
||||
const uploadTaro = (tempFilePaths: any) => {
|
||||
@@ -265,7 +268,11 @@ const Home = () => {
|
||||
className="iconStyle"
|
||||
onClick={() => {
|
||||
// getLocation();
|
||||
chooseImage();
|
||||
let isin:any=phoneLogin()
|
||||
if(isin){
|
||||
chooseImage();
|
||||
}
|
||||
|
||||
}}
|
||||
/>
|
||||
<GridItem
|
||||
@@ -350,7 +357,6 @@ const Home = () => {
|
||||
);
|
||||
})}
|
||||
|
||||
|
||||
{/* 直播live专区 */}
|
||||
{/* <View>视频号直播</View> */}
|
||||
|
||||
|
||||
@@ -201,7 +201,12 @@ const my = (props: any) => {
|
||||
</View> */}
|
||||
|
||||
<View className="cellArr">
|
||||
<Cell icon="manager" title="打卡记录" isLink />
|
||||
<Cell icon="manager" title="打卡记录" isLink onClick={()=>{
|
||||
// 跳转到目的页面,打开新页面
|
||||
Taro.navigateTo({
|
||||
url: "/pages/my/components/CheckinDetail/index",
|
||||
});
|
||||
}}/>
|
||||
{/* <Cell icon="manager" title="个人资料" isLink /> */}
|
||||
|
||||
<Cell
|
||||
|
||||
@@ -16,9 +16,10 @@ interface Typeint {
|
||||
okFun: any;
|
||||
}
|
||||
|
||||
const params = () => {
|
||||
// 获取params参数
|
||||
export const getparams = () => {
|
||||
let $instance: any = getCurrentInstance();
|
||||
return $instance.router.params;
|
||||
return $instance?.router?.params;
|
||||
};
|
||||
// 添加数据
|
||||
export const addTable: any = ({ env, tableName, objData, okFun }: Typeint) => {
|
||||
@@ -38,14 +39,14 @@ export const addTable: any = ({ env, tableName, objData, okFun }: Typeint) => {
|
||||
};
|
||||
|
||||
// 获取指定集合数据表
|
||||
export const getTable: any = ({ env, tableName, keyValue, okFun }: Typeint) => {
|
||||
export const getTable: any = ({ env, tableName, keyValue={}, okFun }: Typeint) => {
|
||||
// 数据库环境
|
||||
const db: any = Taro.cloud.database({
|
||||
env: env,
|
||||
});
|
||||
|
||||
let nowtable: any = db?.collection(tableName);
|
||||
nowtable?.where({ ...(keyValue ?? {}) }).get({
|
||||
nowtable?.where(keyValue).get({
|
||||
success: (res: any) => {
|
||||
okFun(res);
|
||||
},
|
||||
@@ -57,7 +58,7 @@ export const getTableid: any = ({
|
||||
env,
|
||||
tableName,
|
||||
id,
|
||||
keyValue,
|
||||
keyValue={},
|
||||
okFun,
|
||||
}: Typeint) => {
|
||||
// 数据库环境
|
||||
@@ -68,7 +69,7 @@ export const getTableid: any = ({
|
||||
let nowtable: any = db?.collection(tableName);
|
||||
nowtable
|
||||
?.doc(id)
|
||||
// .where({ ...(keyValue ?? {}) })
|
||||
.where(keyValue)
|
||||
.get({
|
||||
success: (res: any) => {
|
||||
okFun(res);
|
||||
|
||||
Reference in New Issue
Block a user