From 841b480f01e4d6cc011372225429acabdeca9cda Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 21 Nov 2022 18:13:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=99=BB=E5=BD=95=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/common.js | 2 +- .../activityList/components/details/index.js | 2 +- .../components/details/index.js.LICENSE.txt | 8 ++ dist/pages/my/index.js | 2 +- .../activityList/components/details/index.tsx | 85 +++++------- src/pages/my/index.tsx | 16 ++- src/utils/index.ts | 124 ++++++++++-------- 7 files changed, 125 insertions(+), 114 deletions(-) diff --git a/dist/common.js b/dist/common.js index c89e382..f3a002a 100644 --- a/dist/common.js +++ b/dist/common.js @@ -1,2 +1,2 @@ /*! For license information please see common.js.LICENSE.txt */ -"use strict";(wx.webpackJsonp=wx.webpackJsonp||[]).push([["common"],{"./src/pages/components/ActiveCard/index.tsx":function(e,n,t){var a=t("./node_modules/@antmjs/vantui/es/button/index.js"),s=t("./node_modules/@antmjs/vantui/es/image/index.js"),i=t("./node_modules/@antmjs/vantui/es/tag/index.js"),l=t("./node_modules/@babel/runtime/helpers/esm/slicedToArray.js"),o=t("./node_modules/@tarojs/plugin-platform-weapp/dist/components-react.js"),r=t("webpack/container/remote/react"),c=t("webpack/container/remote/moment"),d=t.n(c),u=t("webpack/container/remote/react/jsx-runtime");n.default=function ActiveCard(e){var n=(0,r.useState)({}),t=(0,l.default)(n,2),c=(t[0],t[1],null==e?void 0:e.dataSource),m=c.title,x=c.address,j=c.date,p=c.tagName,v=(c.tagCode,c.Status,c.images);c.isDelete;return(0,u.jsxs)(o.View,{className:"activeCard",children:[(0,u.jsxs)(o.View,{className:"left",children:[!1,(0,u.jsx)(o.View,{className:"leftImage",children:(0,u.jsx)(s.default,{width:"100%",height:"100px",fit:"cover",src:null==v?void 0:v[0]})})]}),(0,u.jsxs)(o.View,{className:"middle",children:[(0,u.jsxs)(o.View,{className:"title",children:[(0,u.jsx)(i.default,{round:!0,type:"warning",style:{marginRight:"5px"},children:p}),(0,u.jsx)(o.Text,{children:m})]}),(0,u.jsxs)(o.View,{className:"down",children:[(0,u.jsxs)(o.View,{className:"date",children:[(0,u.jsx)(o.View,{className:"",children:x}),(0,u.jsx)(o.View,{className:"",children:d()(j).format("YYYY-MM-DD")})]}),(0,u.jsx)(o.View,{className:"btn",children:(0,u.jsx)(a.default,{plain:!0,hairline:!0,type:"primary",children:"立即报名"})})]})]})]})}},"./src/pages/components/TabbarCom/index.tsx":function(e,n,t){var a=t("./node_modules/@antmjs/vantui/es/tabbar/index.js"),s=t("./node_modules/@antmjs/vantui/es/tabbar-item/index.js"),i=t("./node_modules/@babel/runtime/helpers/esm/slicedToArray.js"),l=t("./node_modules/@tarojs/plugin-platform-weapp/dist/components-react.js"),o=t("webpack/container/remote/@tarojs/taro"),r=t.n(o),c=t("webpack/container/remote/react"),d=t.n(c),u=t("webpack/container/remote/react/jsx-runtime");n.default=function TabbarCom(e){var n,t=d().useState(null!==(n=null==e?void 0:e.active)&&void 0!==n?n:0),o=(0,i.default)(t,2),c=o[0],m=o[1];return(0,u.jsx)(l.View,{style:{marginTop:"40px"},children:(0,u.jsxs)(a.default,{active:c,onChange:function onChange(e){console.log("e",e),m(null==e?void 0:e.detail),0===(null==e?void 0:e.detail)&&r().redirectTo({url:"/pages/home/index"}),1===(null==e?void 0:e.detail)&&r().redirectTo({url:"/pages/activityList/index"}),2===(null==e?void 0:e.detail)&&r().redirectTo({url:"/pages/my/index"})},safeAreaInsetBottom:!0,children:[(0,u.jsx)(s.default,{icon:"home-o",children:"首页"}),(0,u.jsx)(s.default,{icon:"friends-o",children:"活动"}),(0,u.jsx)(s.default,{icon:"setting-o",children:"我的"})]})})}},"./src/utils/index.ts":function(e,n,t){t.d(n,{getTable:function(){return i},getTableid:function(){return l}});var a=t("webpack/container/remote/@tarojs/taro"),s=t.n(a),i=function getTable(e){var n=e.env,t=e.tableName,a=e.okFun,i=s().cloud.database({env:n}),l=null==i?void 0:i.collection(t);null==l||l.get({success:function success(e){a(e)}})},l=function getTableid(e){var n=e.env,t=e.tableName,a=e.id,i=e.okFun,l=s().cloud.database({env:n}),o=null==l?void 0:l.collection(t);null==o||o.doc(a).get({success:function success(e){i(e)}})}}}]); \ No newline at end of file +"use strict";(wx.webpackJsonp=wx.webpackJsonp||[]).push([["common"],{"./src/pages/components/ActiveCard/index.tsx":function(e,n,t){var a=t("./node_modules/@antmjs/vantui/es/button/index.js"),s=t("./node_modules/@antmjs/vantui/es/image/index.js"),i=t("./node_modules/@antmjs/vantui/es/tag/index.js"),o=t("./node_modules/@babel/runtime/helpers/esm/slicedToArray.js"),l=t("./node_modules/@tarojs/plugin-platform-weapp/dist/components-react.js"),c=t("webpack/container/remote/react"),r=t("webpack/container/remote/moment"),d=t.n(r),u=t("webpack/container/remote/react/jsx-runtime");n.default=function ActiveCard(e){var n=(0,c.useState)({}),t=(0,o.default)(n,2),r=(t[0],t[1],null==e?void 0:e.dataSource),m=r.title,p=r.address,f=r.date,j=r.tagName,x=(r.tagCode,r.Status,r.images);r.isDelete;return(0,u.jsxs)(l.View,{className:"activeCard",children:[(0,u.jsxs)(l.View,{className:"left",children:[!1,(0,u.jsx)(l.View,{className:"leftImage",children:(0,u.jsx)(s.default,{width:"100%",height:"100px",fit:"cover",src:null==x?void 0:x[0]})})]}),(0,u.jsxs)(l.View,{className:"middle",children:[(0,u.jsxs)(l.View,{className:"title",children:[(0,u.jsx)(i.default,{round:!0,type:"warning",style:{marginRight:"5px"},children:j}),(0,u.jsx)(l.Text,{children:m})]}),(0,u.jsxs)(l.View,{className:"down",children:[(0,u.jsxs)(l.View,{className:"date",children:[(0,u.jsx)(l.View,{className:"",children:p}),(0,u.jsx)(l.View,{className:"",children:d()(f).format("YYYY-MM-DD")})]}),(0,u.jsx)(l.View,{className:"btn",children:(0,u.jsx)(a.default,{plain:!0,hairline:!0,type:"primary",children:"立即报名"})})]})]})]})}},"./src/pages/components/TabbarCom/index.tsx":function(e,n,t){var a=t("./node_modules/@antmjs/vantui/es/tabbar/index.js"),s=t("./node_modules/@antmjs/vantui/es/tabbar-item/index.js"),i=t("./node_modules/@babel/runtime/helpers/esm/slicedToArray.js"),o=t("./node_modules/@tarojs/plugin-platform-weapp/dist/components-react.js"),l=t("webpack/container/remote/@tarojs/taro"),c=t.n(l),r=t("webpack/container/remote/react"),d=t.n(r),u=t("webpack/container/remote/react/jsx-runtime");n.default=function TabbarCom(e){var n,t=d().useState(null!==(n=null==e?void 0:e.active)&&void 0!==n?n:0),l=(0,i.default)(t,2),r=l[0],m=l[1];return(0,u.jsx)(o.View,{style:{marginTop:"40px"},children:(0,u.jsxs)(a.default,{active:r,onChange:function onChange(e){console.log("e",e),m(null==e?void 0:e.detail),0===(null==e?void 0:e.detail)&&c().redirectTo({url:"/pages/home/index"}),1===(null==e?void 0:e.detail)&&c().redirectTo({url:"/pages/activityList/index"}),2===(null==e?void 0:e.detail)&&c().redirectTo({url:"/pages/my/index"})},safeAreaInsetBottom:!0,children:[(0,u.jsx)(s.default,{icon:"home-o",children:"首页"}),(0,u.jsx)(s.default,{icon:"friends-o",children:"活动"}),(0,u.jsx)(s.default,{icon:"setting-o",children:"我的"})]})})}},"./src/utils/index.ts":function(e,n,t){t.d(n,{getTable:function(){return i},getTableid:function(){return o},updateTableid:function(){return l},isLogin:function(){return c}});var a=t("webpack/container/remote/@tarojs/taro"),s=t.n(a),i=function getTable(e){var n=e.env,t=e.tableName,a=e.okFun,i=s().cloud.database({env:n}),o=null==i?void 0:i.collection(t);null==o||o.get({success:function success(e){a(e)}})},o=function getTableid(e){var n=e.env,t=e.tableName,a=e.id,i=e.okFun,o=s().cloud.database({env:n}),l=null==o?void 0:o.collection(t);null==l||l.doc(a).get({success:function success(e){i(e)}})},l=function updateTableid(e){var n=e.env,t=e.tableName,a=e.objData,i=e.id,o=e.okFun,l=s().cloud.database({env:n});(null==l?void 0:l.collection(t)).doc(i).update({data:a,success:function success(e){o(e)}})},c=function isLogin(){s().checkSession({success:function success(e){return console.log("res",e),!0},fail:function fail(e){return console.log("err",e),!1}})}}}]); \ No newline at end of file diff --git a/dist/pages/activityList/components/details/index.js b/dist/pages/activityList/components/details/index.js index 7ca7527..cba8723 100644 --- a/dist/pages/activityList/components/details/index.js +++ b/dist/pages/activityList/components/details/index.js @@ -1,2 +1,2 @@ /*! For license information please see index.js.LICENSE.txt */ -"use strict";(wx.webpackJsonp=wx.webpackJsonp||[]).push([["pages/activityList/components/details/index"],{"./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??ruleSet[1].rules[9].use[1]!./src/pages/activityList/components/details/index.tsx":function(e,t,n){var l=n("./node_modules/@antmjs/vantui/es/button/index.js"),i=n("./node_modules/@antmjs/vantui/es/toast/index.js"),s=n("./node_modules/@antmjs/vantui/es/cell/index.js"),o=n("./node_modules/@antmjs/vantui/es/image/index.js"),a=n("./node_modules/@babel/runtime/helpers/esm/slicedToArray.js"),d=n("./node_modules/@tarojs/plugin-platform-weapp/dist/components-react.js"),c=n("webpack/container/remote/@tarojs/taro"),u=n.n(c),r=n("webpack/container/remote/react"),v=n("./src/utils/index.ts"),m=n("webpack/container/remote/react/jsx-runtime");t.default=function details(){var e,t,n,x,f,p,j=(0,r.useState)([]),b=(0,a.default)(j,2),g=b[0],h=b[1],k=(0,r.useState)(0),w=(0,a.default)(k,2),y=w[0],T=w[1],_=(0,c.getCurrentInstance)(),C=(null!==(e=null==_||null===(t=_.router)||void 0===t?void 0:t.params)&&void 0!==e?e:{}).id;(0,r.useEffect)((function(){}),[]),(0,r.useEffect)((function(){var e,t=u().getSystemInfoSync(),n=t.screenHeight,l=t.safeArea,i=void 0===l?{}:l,s=null!==(e=n-(null==i?void 0:i.bottom))&&void 0!==e?e:0;T(s);var o={tableName:"details",id:C,okFun:function okFun(e){var t;console.log("res",e),h(null!==(t=null==e?void 0:e.data)&&void 0!==t?t:[])}};(0,v.getTableid)(o)}),[]);return(0,m.jsxs)(d.View,{className:"detailContent",children:[(0,m.jsxs)(d.View,{children:[(0,m.jsx)(d.View,{children:null==g?void 0:g.title}),(0,m.jsx)(o.default,{width:"100%",height:"180px",fit:"cover",src:null==g||null===(n=g.images)||void 0===n||null===(x=n[0])||void 0===x?void 0:x.url}),(0,m.jsxs)(d.View,{children:[(0,m.jsx)(s.default,{icon:"clock",title:"开始时间 ".concat(null==g?void 0:g.startTime)}),(0,m.jsx)(s.default,{icon:"clock",title:"结束时间 ".concat(null==g?void 0:g.endTime)}),(0,m.jsx)(s.default,{isLink:!0,icon:"location",title:"".concat(null==g?void 0:g.address),linkType:"navigateTo",url:"/pages/dashboard/index"}),(0,m.jsx)(s.default,{icon:"friends",title:"已报名人数 ".concat(null!==(f=null==g||null===(p=g.useridArr)||void 0===p?void 0:p.length)&&void 0!==f?f:0)})]})]}),(0,m.jsx)(d.View,{onClick:function onClick(){},className:"RichText",children:(0,m.jsx)(d.RichText,{nodes:null==g?void 0:g.richText})}),(0,m.jsxs)(d.View,{className:"detailBtn",style:{bottom:"".concat(null!=y?y:0,"px")},onClick:function onClick(){u().checkSession({success:function success(e){console.log("res",e)},fail:function fail(e){console.log("err",e),i.default.fail({message:"请先登录",selector:"#vanToast-demo2",duration:2e3,onClose:function onClose(){u().navigateTo({url:"/pages/my/index"})}})}})},children:[(0,m.jsx)(l.default,{type:"primary",block:!0,disabled:!["1"].includes(null==g?void 0:g.Status),children:[{label:"活动待开放",value:"0"},{label:"立即报名",value:"1"},{label:"活动已取消",value:"2"},{label:"活动进行中",value:"3"},{label:"活动已结束",value:"4"},{label:"活动已关闭",value:"5"}].map((function(e){var t=null==g?void 0:g.Status;if((null==e?void 0:e.value)===t)return null==e?void 0:e.label}))}),(0,m.jsx)(i.default,{id:"vanToast-demo2"})]})]})}},"./src/pages/activityList/components/details/index.tsx":function(e,t,n){var l=n("webpack/container/remote/@tarojs/runtime"),i=n("./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??ruleSet[1].rules[9].use[1]!./src/pages/activityList/components/details/index.tsx");Page((0,l.createPageConfig)(i.default,"pages/activityList/components/details/index",{root:{cn:[]}},{navigationBarTitleText:"活动详情"}||{}))}},function(e){e.O(0,["taro","vendors","common"],(function(){return t="./src/pages/activityList/components/details/index.tsx",e(e.s=t);var t}));e.O()}]); \ No newline at end of file +"use strict";(wx.webpackJsonp=wx.webpackJsonp||[]).push([["pages/activityList/components/details/index"],{"./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??ruleSet[1].rules[9].use[1]!./src/pages/activityList/components/details/index.tsx":function(e,t,n){var o=n("./node_modules/@antmjs/vantui/es/button/index.js"),l=n("./node_modules/@babel/runtime/helpers/esm/objectSpread2.js"),i=n("./node_modules/@antmjs/vantui/es/toast/index.js"),s=n("./node_modules/@antmjs/vantui/es/cell/index.js"),a=n("./node_modules/@antmjs/vantui/es/image/index.js"),r=n("./node_modules/@babel/runtime/helpers/esm/slicedToArray.js"),d=n("./node_modules/@tarojs/plugin-platform-weapp/dist/components-react.js"),c=n("webpack/container/remote/@tarojs/taro"),u=n.n(c),m=n("webpack/container/remote/react"),p=n("./src/utils/index.ts"),v=n("webpack/container/remote/react/jsx-runtime");t.default=function details(){var e,t,n,b,f,j,x=(0,m.useState)([]),g=(0,r.default)(x,2),y=g[0],h=g[1],w=(0,m.useState)(0),k=(0,r.default)(w,2),O=k[0],T=k[1],_=(0,c.getCurrentInstance)(),S=(null!==(e=null==_||null===(t=_.router)||void 0===t?void 0:t.params)&&void 0!==e?e:{}).id;(0,m.useEffect)((function(){}),[]),(0,m.useEffect)((function(){var e,t=u().getSystemInfoSync(),n=t.screenHeight,o=t.safeArea,l=void 0===o?{}:o,i=null!==(e=n-(null==l?void 0:l.bottom))&&void 0!==e?e:0;T(i);var s={tableName:"details",id:S,okFun:function okFun(e){var t;console.log("res",e),h(null!==(t=null==e?void 0:e.data)&&void 0!==t?t:[])}};(0,p.getTableid)(s)}),[]);return(0,v.jsxs)(d.View,{className:"detailContent",children:[(0,v.jsxs)(d.View,{children:[(0,v.jsx)(d.View,{children:null==y?void 0:y.title}),(0,v.jsx)(a.default,{width:"100%",height:"180px",fit:"cover",src:null==y||null===(n=y.images)||void 0===n||null===(b=n[0])||void 0===b?void 0:b.url}),(0,v.jsxs)(d.View,{children:[(0,v.jsx)(s.default,{icon:"clock",title:"开始时间 ".concat(null==y?void 0:y.startTime)}),(0,v.jsx)(s.default,{icon:"clock",title:"结束时间 ".concat(null==y?void 0:y.endTime)}),(0,v.jsx)(s.default,{isLink:!0,icon:"location",title:"".concat(null==y?void 0:y.address),linkType:"navigateTo",url:"/pages/dashboard/index"}),(0,v.jsx)(s.default,{icon:"friends",title:"已报名人数 ".concat(null!==(f=null==y||null===(j=y.useridArr)||void 0===j?void 0:j.length)&&void 0!==f?f:0)})]})]}),(0,v.jsx)(d.View,{onClick:function onClick(){},className:"RichText",children:(0,v.jsx)(d.RichText,{nodes:null==y?void 0:y.richText})}),(0,v.jsxs)(d.View,{className:"detailBtn",style:{bottom:"".concat(null!=O?O:0,"px")},onClick:function onClick(){if((0,p.isLogin)()){console.log("id",S);var e={id:S,tableName:"details",objData:{useridArr:["openid"]},okFun:function okFun(e){console.log("res",e)}};console.log("postData",e),(0,p.updateTableid)((0,l.default)({},e))}else i.default.fail({message:"请先登录",selector:"#vanToast-demo2",duration:2e3,onClose:function onClose(){u().navigateTo({url:"/pages/my/index"})}})},children:[(0,v.jsx)(o.default,{type:"primary",block:!0,disabled:!["1"].includes(null==y?void 0:y.Status),children:[{label:"活动待开放",value:"0"},{label:"立即报名",value:"1"},{label:"活动已取消",value:"2"},{label:"活动进行中",value:"3"},{label:"活动已结束",value:"4"},{label:"活动已关闭",value:"5"}].map((function(e){var t=null==y?void 0:y.Status;if((null==e?void 0:e.value)===t)return null==e?void 0:e.label}))}),(0,v.jsx)(i.default,{id:"vanToast-demo2"})]})]})}},"./src/pages/activityList/components/details/index.tsx":function(e,t,n){var o=n("webpack/container/remote/@tarojs/runtime"),l=n("./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??ruleSet[1].rules[9].use[1]!./src/pages/activityList/components/details/index.tsx");Page((0,o.createPageConfig)(l.default,"pages/activityList/components/details/index",{root:{cn:[]}},{navigationBarTitleText:"活动详情"}||{}))},"./node_modules/@babel/runtime/helpers/esm/objectSpread2.js":function(e,t,n){n.d(t,{default:function(){return _objectSpread2}});var o=n("./node_modules/@babel/runtime/helpers/esm/defineProperty.js");function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function _objectSpread2(e){for(var t=1;t { 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", - }); - }, - }) - + let isin: any = isLogin(); + if (!isin) { + //重新登录- 跳转到我的页面 + Toast.fail({ + message: "请先登录", + selector: "#vanToast-demo2", + duration: 2000, + onClose: () => { + // 跳转到目的页面,打开新页面 + Taro.navigateTo({ + url: "/pages/my/index", + }); + }, + }); + } else { + console.log("id", id); + // 立即报名 + let postData = { + // env: "any", + id: id, + tableName: "details", + objData: { + // ..._.cloneDeep(dataSource), + useridArr: ["openid"], + }, + okFun: (res: any) => { + console.log("res", res); + }, + }; - // 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}) + console.log("postData", postData); + updateTableid({ ...postData }); + } }} > {/* style={{width:'375px'}} */} diff --git a/src/pages/my/index.tsx b/src/pages/my/index.tsx index c513153..34d8d71 100644 --- a/src/pages/my/index.tsx +++ b/src/pages/my/index.tsx @@ -16,7 +16,7 @@ import "./index.module.scss"; import { Tab, Tabs } from "@antmjs/vantui"; import Taro from "@tarojs/taro"; import ActiveCard from "../components/ActiveCard"; -import { getTable } from "../../utils/index"; +import { getTable, isLogin } from "../../utils/index"; const my = (props: any) => { // const [active, setActive] = react.useState(props?.active ?? 0); @@ -24,6 +24,12 @@ const my = (props: any) => { const [userInfo, setuserInfo] = useState({}); //用户信息 const [detailsData, setdetailsData] = useState([]); //活动详情 const [currentIndex, setcurrentIndex] = useState(0); + const [isin,setisin]=useState(false) + + useEffect(()=>{ + let isin: any = isLogin(); + setisin(isin) + },[]) // 云函数,-获取手机号 const getLogin = (e: any) => { @@ -37,9 +43,7 @@ const my = (props: any) => { .then((res: any) => { console.log("res11"); console.log("res", res); - // this.setState({ - // context: res.result, - // }); + setisin(true) }); }; @@ -118,7 +122,7 @@ const my = (props: any) => { src="cloud://cloud1-5g5xrgza12a0dd6d.636c-cloud1-5g5xrgza12a0dd6d-1253665791/images/images-2.jpg" /> - + {!isin&& - + } {/* diff --git a/src/utils/index.ts b/src/utils/index.ts index 4f6b31b..f759d4d 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,7 +1,7 @@ +import { Toast } from "@antmjs/vantui"; import Taro from "@tarojs/taro"; import { getCurrentInstance } from "@tarojs/taro"; - // 数据库环境 // const db: any = Taro.cloud.database({ // env: "cloud1-5g5xrgza12a0dd6d", @@ -9,18 +9,18 @@ import { getCurrentInstance } from "@tarojs/taro"; interface Typeint { env?: any; - id?:any + id?: any; tableName: any; objData?: any; okFun: any; } -const params=()=>{ +const params = () => { let $instance: any = getCurrentInstance(); return $instance.router.params; -} +}; // 添加数据 -export const addTable: any = ({ env,tableName, objData, okFun }: Typeint) => { +export const addTable: any = ({ env, tableName, objData, okFun }: Typeint) => { // 数据库环境 const db: any = Taro.cloud.database({ env: env, @@ -36,24 +36,23 @@ export const addTable: any = ({ env,tableName, objData, okFun }: Typeint) => { }); }; - // 获取指定集合数据表 -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); - }, - }); - }; +export const getTable: any = ({ env, tableName, okFun }: Typeint) => { + // 数据库环境 + const db: any = Taro.cloud.database({ + env: env, + }); - // 获取指定id数据数据 -export const getTableid: any = ({ env,tableName, id, okFun }: Typeint) => { + 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, @@ -67,39 +66,58 @@ export const getTableid: any = ({ env,tableName, id, okFun }: Typeint) => { }); }; - - - - // 更新数据 -export const updateTableid: any = ({ env,tableName,objData, id, okFun }: Typeint) => { - // 数据库环境 - const db: any = Taro.cloud.database({ - env: env, - }); - let nowtable: any = db?.collection(tableName); - nowtable.doc(id).update({ +// 更新数据 +export const updateTableid: any = ({ + env, + tableName, + objData, + id, + okFun, +}: Typeint) => { + // 数据库环境 + const db: any = Taro.cloud.database({ + env: env, + }); + let nowtable: any = db?.collection(tableName); + nowtable.doc(id).update({ // nowtable.doc(id).set({ - // data 传入需要局部更新的数据 - data: objData, - success: (res: any) => { - okFun(res); - }, - }) - }; + // data 传入需要局部更新的数据 + data: objData, + success: (res: any) => { + okFun(res); + }, + }); +}; - // 删除数据 -export const deleteTableid: any = ({ env,tableName, id, okFun }: Typeint) => { - // 数据库环境 - const db: any = Taro.cloud.database({ - env: env, - }); - let nowtable: any = db?.collection(tableName); - nowtable.doc(id).remove({ - success: (res: any) => { - okFun(res); - }, - }) - }; +// 删除数据 +export const deleteTableid: any = ({ env, tableName, id, okFun }: Typeint) => { + // 数据库环境 + const db: any = Taro.cloud.database({ + env: env, + }); + let nowtable: any = db?.collection(tableName); + nowtable.doc(id).remove({ + success: (res: any) => { + okFun(res); + }, + }); +}; - +export const isLogin = () => { + // 检查登录态,获取openid + Taro.checkSession({ + success: function (res: any) { + //session_key 未过期,并且在本生命周期一直有效 + console.log("res", res); + return true; + // 获取用户openid + }, + fail: function (err: any) { + console.log("err", err); + // session_key 已经失效,需要重新执行登录流程 + return false; + + }, + }); +};