Browse Source

初始化

HW 4 years ago
parent
commit
b1acaf879c

+ 6 - 0
cloudbase/public/config.json

@@ -0,0 +1,6 @@
+{
+  "permissions": {
+    "openapi": [
+    ]
+  }
+}

+ 30 - 0
cloudbase/public/index.js

@@ -0,0 +1,30 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+
+cloud.init()
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  const wxContext = cloud.getWXContext()
+
+  switch (event.action) {
+    case 'getUrlScheme': {
+      return getUrlScheme()
+    }
+  }
+
+  return 'action not found'
+}
+
+async function getUrlScheme() {
+  return cloud.openapi.urlscheme.generate({
+    jumpWxa: {
+      path: '/pages/index/index', // <!-- replace -->
+      query: '',
+    },
+    // 如果想不过期则置为 false,并可以存到数据库
+    isExpire: false,
+    // 一分钟有效期
+    expireTime: parseInt(Date.now() / 1000 + 60),
+  })
+}

+ 14 - 0
cloudbase/public/package.json

@@ -0,0 +1,14 @@
+{
+  "name": "public",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "wx-server-sdk": "~2.3.2"
+  }
+}

+ 2 - 1
project.config.json

@@ -40,5 +40,6 @@
     "minifyWXSS": true
   },
   "compileType": "miniprogram",
-  "condition": {}
+  "condition": {},
+  "cloudbaseRoot": "cloudbase/"
 }

+ 6 - 3
src/app.config.js

@@ -3,7 +3,8 @@ export default {
   pages: [
     'pages/index/index',
     'pages/user/index',
-    'pages/details/index'
+    'pages/details/index',
+    // 'pages/webDetails/index'
   ],
   window: {
     backgroundTextStyle: 'light',
@@ -24,6 +25,8 @@ export default {
       badge: '444'
     }]
   },
-  // debug:true,
-  // networkTimeout:1000
+  debug:true,
+  networkTimeout:{
+    request:1000
+  }
 }

+ 1 - 1
src/components/NavBar/index.js

@@ -2,7 +2,7 @@ import _isFunction from 'lodash/isFunction';
 import { Component } from 'react';
 import Taro from '@tarojs/taro';
 import { View } from '@tarojs/components';
-import './index.scss';
+import './index.less';
 
 function getSystemInfo() {
   if (Taro.globalSystemInfo && !Taro.globalSystemInfo.ios) {

src/components/NavBar/index.scss → src/components/NavBar/index.less


+ 1 - 1
src/custom-tab-bar/index.jsx

@@ -61,7 +61,7 @@ class CustomTabBar extends Component{
 
   render() {
     return(
-      <View className='tab-bar'>
+      <View className='custom-tab-bar'>
           {/*<View  className='tab-bar-border'/>*/}
           {
             this.state.list.map((v,key)=>(

+ 1 - 1
src/custom-tab-bar/index.less

@@ -1,4 +1,4 @@
-.tab-bar {
+.custom-tab-bar {
   position: fixed;
   bottom: 0;
   left: 0;

+ 3 - 0
src/pages/details/index.jsx

@@ -192,6 +192,9 @@ class Details extends Component {
                     autoplay={false}
                     poster={resourceAddress + projectInfor.thumbnailUrl}
                     initialTime='0'
+                    direction={-90}
+                    enableAutoRotation
+                    showBackgroundPlaybackButton
                     id='video'
                     loop={false}
                     muted={false}

+ 0 - 3
src/pages/index/index.config.js

@@ -6,7 +6,4 @@ export default {
   navigationBarTextStyle:'white',
   backgroundColor: '#7ac7ff',
   onReachBottomDistance: 50,
-  usingComponents: {
-    "mp-html": "../../components/common/mp-weixin/index",
-  }
 }

+ 1 - 1
src/pages/index/index.jsx

@@ -9,7 +9,7 @@ import {resourceAddress} from '../../utils/config';
 import NavBar from '../../components/NavBar';
 import ListBottomStart  from '../../components/common/listBottomStart';
 
-import './index.less'
+import './index.less';
 
 import background from '../../assets/images/background.png';
 

+ 7 - 0
src/pages/index/index.less

@@ -48,6 +48,13 @@
           color: #2F3742;
           font-weight: bolder;
           line-height: 39px;
+          height: 78px;
+          text-overflow: -o-ellipsis-lastline;
+          overflow: hidden;
+          text-overflow: ellipsis;
+          display: -webkit-box;
+          -webkit-line-clamp: 2;
+          -webkit-box-orient: vertical;
         }
         .createTimes{
           display: inline-block;

+ 7 - 3
src/pages/user/index.jsx

@@ -5,14 +5,14 @@ import { View, Image } from '@tarojs/components'
 
 import {set} from '../../actions/counter'
 import { login,getUserOrderList } from '../../utils/servers/servers'
+
+import NavBar from "../../components/NavBar";
 import ListBottomStart from "../../components/common/listBottomStart";
 
 import './index.less'
 
-import background from "../../assets/images/background.png";
-import NavBar from "../../components/NavBar";
-
 import userIcon from '../../custom-tab-bar/image/user.png';
+import background from "../../assets/images/background.png";
 
 @connect(({ counter }) => ({
   counter
@@ -57,6 +57,9 @@ class Index extends Component {
   }
 
   async login(nickname){
+    Taro.showLoading({
+      title:'登录中...',
+    })
     let token = Taro.getStorageSync('token');
     if(!token){
       let loginMsg = await Taro.login();
@@ -81,6 +84,7 @@ class Index extends Component {
         console.log('登录失败!' + loginMsg.errMsg)
       }
     }
+    Taro.hideLoading();
   }
 
   async getUserOrderList (pageNo = 1){

+ 10 - 0
src/pages/webDetails/index.config.js

@@ -0,0 +1,10 @@
+export default {
+  navigationBarTitleText: '产品详情',
+  enablePullDownRefresh: true,
+  backgroundColor: '#7ac7ff',
+  navigationBarBackgroundColor:'#7ac7ff',
+  navigationBarTextStyle:'white',
+  usingComponents: {
+    "mp-html": "../../components/common/mp-weixin/index",
+  }
+}

+ 263 - 0
src/pages/webDetails/index.jsx

@@ -0,0 +1,263 @@
+import { Component } from 'react';
+import Taro from '@tarojs/taro';
+import {View, Image, Video} from '@tarojs/components'
+import AudioPlayer from '../../components/audio';
+
+import API from '../../utils/API';
+import { pay,payClose,getSelectProject,wxQuery,login } from '../../utils/servers/servers';
+import {resourceAddress} from '../../utils/config';
+
+import './index.less'
+import 'taro-ui/dist/style/components/tag.scss';
+import "taro-ui/dist/style/components/progress.scss";
+import "taro-ui/dist/style/components/icon.scss";
+import "taro-ui/dist/style/components/slider.scss";
+
+import background from '../../assets/images/background.png';
+
+class Details extends Component {
+
+  inst = Taro.getCurrentInstance()
+
+  constructor(props) {
+    super(props);
+    this.state={
+      projectInfor: {},
+    }
+    this.pay= this.pay.bind(this);
+    this.payClose= this.payClose.bind(this);
+    this.wxQuery= this.wxQuery.bind(this);
+    this.login= this.login.bind(this);
+  }
+
+  componentDidMount() {
+    this.getSelectProject();
+  }
+
+  onPullDownRefresh(){
+    this.getSelectProject();
+  }
+
+  //H5跳转到微信小程序
+  jumpWeapp(){
+    window.location.href='https://cloud1-2gpyny9bdfc8c33a-1305545304.tcloudbaseapp.com/jump-mp.html?sign=639f843ec9b22075c5ce44e301060206&t=1618818701&id=27';
+  }
+
+  pay(){
+    let token = Taro.getStorageSync('token');
+    if(!token){
+      Taro.getUserProfile({
+        desc: '用于用户登录',
+        success: async (res)=> {
+          let userInfo = res.userInfo
+          let nickName = userInfo.nickName
+          Taro.setStorageSync('userInfor', userInfo);
+          await this.login(nickName);
+          await this.getSelectProject();
+        },
+        fail: ()=>{
+          Taro.showToast({title:'请同意授权获取用户信息',icon:'none'});
+        }
+      })
+      return ;
+    }
+    Taro.showLoading({title:'加载中'})
+    pay({
+      id:this.inst.router.params.id,
+    }).then(v => {
+      Taro.hideLoading();
+      if(v.error.length === 0){
+        if(v.data.amount === "0"){
+          Taro.showToast({title:'购买成功'});
+          this.getSelectProject();
+          return ;
+        }
+        API.requestPayment({
+          timeStamp: v.data.timeStamp,
+          nonceStr: v.data.nonceStr,
+          package: v.data.package,
+          signType: 'MD5',
+          paySign: v.data.paySign,
+          success: (_)=> {
+            Taro.showToast({title:'支付成功'});
+            this.wxQuery(v.data.out_trade_no);
+            this.getSelectProject();
+          },
+          fail: (err)=> {
+            console.log(err,'fail');
+            this.payClose(v.data.out_trade_no);
+          },
+        })
+      }else{
+        Taro.showToast({title:v.error[0].message,icon:'none'})
+      }
+    }).catch(err => {
+      Taro.hideLoading();
+      Taro.showToast({title:'系统错误,请稍后重试',icon:'none'});
+      console.log(err)
+    })
+  }
+
+  async login(nickname){
+    let token = Taro.getStorageSync('token');
+    if(!token){
+      let loginMsg = await Taro.login();
+      if (loginMsg.code) {
+        try{
+          let msg = await login({
+            code:loginMsg.code,
+            nickname
+          });
+          if(msg.error.length === 0){
+            Taro.setStorageSync('token', msg.token)
+          }else{
+            Taro.showToast({title:msg.error[0].message,icon:'none'})
+          }
+        }catch (err) {
+          Taro.showToast({title:'系统错误,请稍后重试',icon:'none'});
+          console.log(err)
+        }
+      } else {
+        Taro.showToast({title:loginMsg.errMsg,icon:'none'})
+        console.log('登录失败!' + loginMsg.errMsg)
+      }
+    }
+  }
+
+  payClose(orderNo){
+    payClose({
+      orderNo,
+    }).then(v => {
+      if(v.error.length === 0){
+        Taro.showToast({title:'已取消支付',icon:'none'});
+      }else{
+        Taro.showToast({title:v.error[0].message,icon:'none'})
+      }
+    }).catch(err => {
+      Taro.showToast({title:'系统错误,请稍后重试',icon:'none'});
+      console.log(err)
+    })
+  }
+
+  wxQuery(orderNo){
+    wxQuery({
+      orderNo:orderNo,
+    }).then(v => {
+      if(v.error.length === 0){
+        this.getSelectProject();
+      }else{
+        Taro.showToast({title:v.error[0].message,icon:'none'})
+      }
+    }).catch(err => {
+      Taro.showToast({title:'系统错误,请稍后重试',icon:'none'});
+      console.log(err)
+    })
+  }
+
+  getSelectProject(){
+    getSelectProject({
+      id:this.inst.router.params.id,
+    }).then(v => {
+      if(v.error.length === 0){
+        this.setState({
+          projectInfor: v.data
+        })
+      }else{
+        Taro.showToast({title:v.error[0].message,icon:'none'})
+      }
+    }).catch(err => {
+      Taro.showToast({title:'系统错误,请稍后重试',icon:'none'});
+      console.log(err)
+    })
+    Taro.stopPullDownRefresh();
+  }
+
+  render () {
+    const { projectInfor } = this.state;
+    return (
+      <View className='detailsPage'>
+        <Image src={background} className='background'/>
+        <View className='introduce'>
+          <View className='imgContent'>
+            {
+              projectInfor.buy === 0 ?
+                <Image onClick={()=>{
+                  Taro.previewMedia({
+                    sources: [
+                      {
+                        url: resourceAddress + projectInfor.thumbnailUrl + ''
+                      }
+                    ]
+                  });
+                }} objectFit='contain' src={resourceAddress + projectInfor.thumbnailUrl} className='img'/> :
+                projectInfor.commodityType === 1 ?
+                  <Video
+                    src={resourceAddress + projectInfor.commodityUrl}
+                    controls
+                    autoplay={false}
+                    poster={resourceAddress + projectInfor.thumbnailUrl}
+                    initialTime='0'
+                    direction={-90}
+                    enableAutoRotation
+                    showBackgroundPlaybackButton
+                    id='video'
+                    loop={false}
+                    muted={false}
+                  /> : projectInfor.commodityType === 2 ?
+                  <View className='audio'>
+                    <Image objectFit='contain' src={resourceAddress + projectInfor.thumbnailUrl} className='audioImg'/>
+                    <View className='operation'>
+                      <AudioPlayer audioFile={resourceAddress + projectInfor.commodityUrl}/>
+                    </View>
+                  </View> : <Image objectFit='contain' src={resourceAddress + projectInfor.commodityUrl} className='img'/>
+            }
+          </View>
+          <View className='infor'>
+            <View className='title'>{projectInfor.name}</View>
+            <View className='introduceItem'>
+              <View className='introduceContent'>
+                {
+                  projectInfor.summary
+                }
+              </View>
+              <View className='user'>
+                <View className='typeName'>
+                  {projectInfor.typeName}
+                </View>
+              </View>
+            </View>
+          </View>
+        </View>
+        <View className='detailsContent'>
+          <View className='details'>产品详情</View>
+          {
+            Taro.getEnv() === 'WEAPP' ?
+              <mp-html content={projectInfor.buy === 0 ? projectInfor.content : projectInfor.commodityContent} />:
+              <View dangerouslySetInnerHTML={{__html:projectInfor.buy === 0 ? projectInfor.content+'' : projectInfor.commodityContent+''}}/>
+          }
+        </View>
+        <View className='shop'>
+          <View className='singlePurchase' onClick={()=>{
+            if(Taro.getEnv() === 'WEB'){
+              this.jumpWeapp();
+            }else{
+              this.pay();
+            }
+          }}>购买: ¥{projectInfor.amount}</View>
+        </View>
+        {/*{projectInfor.buy === 0 ? <View className='shop' style={{bottom:Taro.getEnv() === 'WEB' ? '50px' : '0'}}>*/}
+        {/*  <View className='singlePurchase' onClick={()=>{*/}
+        {/*    if(Taro.getEnv() === 'WEB'){*/}
+        {/*      this.jumpWeapp();*/}
+        {/*    }else{*/}
+        {/*      this.pay();*/}
+        {/*    }*/}
+        {/*  }}>购买: ¥{projectInfor.amount}</View>*/}
+        {/*</View> : null}*/}
+      </View>
+    )
+  }
+}
+
+export default Details
+

+ 113 - 0
src/pages/webDetails/index.less

@@ -0,0 +1,113 @@
+.detailsPage{
+  position: relative;
+  min-height: 100vh;
+  background: #F5F5F5;
+  z-index: 1;
+  //padding-bottom: 65px;
+  .background{
+    position: absolute;
+    top: -18px;
+    z-index: -1;
+    width: 100%;
+    height: 318px;
+  }
+  .introduce{
+    margin: 18px 26px 42px 0;
+    background: #FFFFFF;
+    border-top-right-radius: 33px;
+    border-bottom-right-radius: 33px;
+    overflow: hidden;
+    box-shadow: -10px 11px 25px #393483;
+    .imgContent{
+      width: 100%;
+      .img{
+        width: 100%;
+        display: block;
+      }
+      #video{
+        width: 100%;
+        display: block;
+      }
+      .audio{
+        position: relative;
+        .audioImg{
+          width: 100%;
+          display: block;
+        }
+        .operation{
+          position: absolute;
+          z-index: 1;
+          top: 0;
+          left: 0;
+          right: 0;
+          bottom: 0;
+          background: #00000085;
+          display: flex;
+          flex-flow: column nowrap;
+          align-items: center;
+          justify-content: center;
+        }
+      }
+    }
+    .infor{
+      padding: 24px;
+      background: #393484;
+      .title{
+        color: #FFFFFF;
+        font-size: 28px;
+      }
+      .introduceItem{
+        display: flex;
+        flex-flow: row nowrap;
+        justify-content: space-between;
+        align-items: center;
+        padding-top: 19px;
+        .introduceContent{
+          color: #999999;
+          font-size: 22px;
+        }
+        .user{
+          display: flex;
+          flex-flow: row nowrap;
+          padding-left: 10px;
+          .typeName{
+            white-space: nowrap;
+            display: inline-block;
+            background: #EFF3FF;
+            border-radius: 2px;
+            font-size: 16px;
+            padding: 5px 7px;
+            color: #4564DC;
+            border: 1px #A7B6F1 solid;
+          }
+        }
+      }
+    }
+  }
+  .detailsContent{
+    padding-left: 19px;
+    padding-right: 19px;
+    .details{
+      font-size: 32px;
+      font-weight: bolder;
+      color: #303030;
+      padding-bottom: 22px;
+    }
+  }
+  .shop{
+    display: flex;
+    position: fixed;
+    bottom: 0;
+    left: 0;
+    right: 0;
+    color: #FFFFFF;
+    font-size: 27px;
+    .singlePurchase{
+      margin-left: auto;
+      padding: 19px 44px;
+      text-align: center;
+      background: #CE9F1E;
+      width: 220px;
+    }
+  }
+}