feat: 封装增删查改函数
This commit is contained in:
17
src/app.ts
17
src/app.ts
@@ -1,11 +1,22 @@
|
||||
import Taro from "@tarojs/taro";
|
||||
import { Component } from "react";
|
||||
import "./app.scss";
|
||||
class App extends Component<any> {
|
||||
componentDidMount() {}
|
||||
componentDidMount() {
|
||||
Taro.cloud.init({
|
||||
env: 'cloud1-5g5xrgza12a0dd6d',
|
||||
traceUser:true
|
||||
})
|
||||
|
||||
componentDidShow () {}
|
||||
const a = new Taro.cloud.Cloud({
|
||||
resourceEnv: 'cloud1-5g5xrgza12a0dd6d',
|
||||
})
|
||||
a.init()
|
||||
}
|
||||
|
||||
componentDidHide () {}
|
||||
componentDidShow() {}
|
||||
|
||||
componentDidHide() {}
|
||||
|
||||
// this.props.children 是将要会渲染的页面
|
||||
render() {
|
||||
|
||||
@@ -9,13 +9,14 @@ import {
|
||||
Tag,
|
||||
} from "@antmjs/vantui";
|
||||
import { View } from "@tarojs/components";
|
||||
import React, { useCallback } from "react";
|
||||
import React, { useCallback, useEffect } from "react";
|
||||
import { Swiper, SwiperItem, Image } from "@antmjs/vantui";
|
||||
import react from "react";
|
||||
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";
|
||||
|
||||
const Home = () => {
|
||||
// const { images } = COMMON
|
||||
@@ -27,6 +28,18 @@ const Home = () => {
|
||||
"cloud://cloud1-5g5xrgza12a0dd6d.636c-cloud1-5g5xrgza12a0dd6d-1253665791/images.jpg",
|
||||
];
|
||||
|
||||
useEffect(() => {
|
||||
let objParams={
|
||||
tableName: "test",
|
||||
id: "80516fb66370bcf300b8f43c5f4dd52b",
|
||||
okFun: (res) => {
|
||||
console.log("res", res);
|
||||
},
|
||||
}
|
||||
getTable(objParams)
|
||||
getTableid(objParams);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<View>
|
||||
{/* 通知条 */}
|
||||
@@ -126,7 +139,7 @@ const Home = () => {
|
||||
<TabbarItem icon="setting-o">我的</TabbarItem>
|
||||
</Tabbar> */}
|
||||
|
||||
<TabbarCom active={0}/>
|
||||
<TabbarCom active={0} />
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
5
src/pages/mountainPeak/index.scss
Normal file
5
src/pages/mountainPeak/index.scss
Normal file
@@ -0,0 +1,5 @@
|
||||
.peakContent{
|
||||
background-color: yellow;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
@@ -1,23 +1,49 @@
|
||||
import { View } from "@tarojs/components";
|
||||
import { RichText, View } from "@tarojs/components";
|
||||
import react from "react";
|
||||
import { Sidebar, SidebarItem } from "@antmjs/vantui";
|
||||
import "./index.scss";
|
||||
import {test} from '../../utils/index'
|
||||
|
||||
|
||||
const mountainPeak = () => {
|
||||
const state: any = {
|
||||
nodes: [
|
||||
{
|
||||
name: "div",
|
||||
attrs: {
|
||||
class: "div_class",
|
||||
style: "line-height: 60px; color: red;",
|
||||
},
|
||||
children: [
|
||||
{
|
||||
type: "text",
|
||||
text: "Hello World!",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
return (
|
||||
<View>
|
||||
<View className={`peakContent`}>
|
||||
{" "}
|
||||
<Sidebar activeKey={0}>
|
||||
<SidebarItem title="梧桐山" />
|
||||
<SidebarItem title="梧桐山" />
|
||||
<SidebarItem title="梧桐山" />
|
||||
<SidebarItem title="梧桐山" />
|
||||
<SidebarItem title="梧桐山" />
|
||||
<SidebarItem title="梧桐山" />
|
||||
<SidebarItem title="梧桐山" />
|
||||
<SidebarItem title="梧桐山" />
|
||||
<SidebarItem title="梧桐山" />
|
||||
<SidebarItem title="梧桐山" />
|
||||
<SidebarItem title="梧桐山" />
|
||||
<SidebarItem title="标签名" />
|
||||
<SidebarItem title="标签名" />
|
||||
</Sidebar>
|
||||
<View onClick={()=>{
|
||||
test()
|
||||
}}>
|
||||
{" "}
|
||||
<RichText nodes={state.nodes} />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
63
src/utils/index.ts
Normal file
63
src/utils/index.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import Taro from "@tarojs/taro";
|
||||
|
||||
// 数据库环境
|
||||
// const db: any = Taro.cloud.database({
|
||||
// env: "cloud1-5g5xrgza12a0dd6d",
|
||||
// });
|
||||
|
||||
interface Typeint {
|
||||
env?: any;
|
||||
id?:any
|
||||
tableName: any;
|
||||
objData?: any;
|
||||
okFun: any;
|
||||
}
|
||||
|
||||
// 添加数据
|
||||
export const addTable: any = ({ env,tableName, objData, okFun }: Typeint) => {
|
||||
// 数据库环境
|
||||
const db: any = Taro.cloud.database({
|
||||
env: env,
|
||||
});
|
||||
|
||||
let nowtable: any = db?.collection(tableName);
|
||||
nowtable?.add({
|
||||
// data 字段表示需新增的 JSON 数据
|
||||
data: objData,
|
||||
success: (res: any) => {
|
||||
okFun(res);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// 获取指定集合数据
|
||||
export const getTable: any = ({ env,tableName, okFun }: Typeint) => {
|
||||
// 数据库环境
|
||||
const db: any = Taro.cloud.database({
|
||||
env: env,
|
||||
});
|
||||
|
||||
let nowtable: any = db?.collection(tableName);
|
||||
nowtable?.get({
|
||||
success: (res: any) => {
|
||||
okFun(res);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 获取指定id数据数据
|
||||
export const getTableid: any = ({ env,tableName, id, okFun }: Typeint) => {
|
||||
// 数据库环境
|
||||
const db: any = Taro.cloud.database({
|
||||
env: env,
|
||||
});
|
||||
|
||||
let nowtable: any = db?.collection(tableName);
|
||||
nowtable?.doc(id).get({
|
||||
success: (res: any) => {
|
||||
okFun(res);
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user