使用goEasy实现多对多实时点餐程序

简介: 使用goEasy实现多对多实时点餐程序

使用goEasy实现多对多实时点餐程序

  1. 新建一个uniapp项目,引入goEasy插件
npm install goeasy@2.6.2 --save
  1. 在main.js引入goeasy并注册
import App from './App'
import GoEasy from 'goeasy'
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
    ...App
})
app.$mount()
// #endif
Vue.prototype.GoEasy = GoEasy
let goeasy = GoEasy.getInstance({
    host:"hangzhou.goeasy.io",  //若是新加坡区域:singapore.goeasy.io
    appkey:"BC-e1f69be1cd6e409f944f3e1285c257c7",
    modules:['pubsub']//根据需要,传入‘pubsub’或'im’,或数组方式同时传入
});
Vue.prototype.goEasy = goeasy
//建立连接
goeasy.connect({
  id:"test_channel", //pubsub选填,im必填,最大长度60字符
  // id:uni.getSystemInfoSync().deviceId, //pubsub选填,im必填,最大长度60字符
  data:{"avatar":"/www/xxx.png","nickname":"Neo"}, //必须是一个对象,pubsub选填,im必填,最大长度300字符,用于上下线提醒和查询在线用户列表时,扩展更多的属性
  onSuccess: function () {  //连接成功
    console.log("GoEasy connect successfully.") //连接成功
  },
  onFailed: function (error) { //连接失败
    console.log("Failed to connect GoEasy, code:"+error.code+ ",error:"+error.content);
  },
  onProgress:function(attempts) { //连接或自动重连中
    console.log("GoEasy is connecting", attempts);
  }
});
  1. 编写模板页面
<template>
  <view class="content">
    <!--  <u-modal v-model="isModel" title="请输入用户名">
        <view>
          <input style="padding: 20rpx;border: 1rpx solid #eee;margin: 30rpx;" v-model="userId" />
        </view>
      </u-modal> -->
      <!-- 顶部 -->
      <view class="top-view">
        <view>{{number_people}}人就餐</view>
        <view class="top-view-flex">
          <image src="/static/tab/fenxiang.svg" mode="widthFix" class="top-search"></image>
          <image src="/static/tab/dingdan.svg" mode="widthFix" @click="my_order()"></image>
        </view>
      </view>
      <view class="order-view">
        <view class="commodity"> 
          <!-- 左 --> 
          <view class="order-left">
            <scroll-view scroll-y="true" class="scroll-Hei" :scroll-with-animation="true" :enhanced="true"
              :show-scrollbar="false">
              <block v-for="(item,index) in itemize" :key="index">
                <view class="itemize-text" :class="{active: index == trigger}"
                  @click="itemIze(index,item.cid)">
                  <text>{{item.value}}</text>
                  <text v-if="item.sele_quantity > 0">{{item.sele_quantity}}</text>
                </view>
              </block>
            </scroll-view>
          </view>
          <!-- 右 -->
          <view class="order-right">
            <scroll-view scroll-y="true" class="scroll-Hei" :scroll-with-animation="true" :enhanced="true"
              :show-scrollbar="false" :scroll-into-view="scroll_into" @scroll="scroLl">
              <block v-for="(item,index) in goods" :key="index">
                <view :id="item.cid" class="rig-height">
                  <view class="classif">{{item.category}}</view>
                  <view class="classif-goods" v-for="(itemgood,good_index) in item.good_query"
                    :key="good_index" @click="popup_item(true,index,good_index,item.cid,itemgood)">
                    <view class="goods-image">
                      <image :src="itemgood.image[0].url" mode="aspectFill"></image>
                    </view>
                    <view class="goods-Price">
                      <view class="goods-name">
                        <text class="Bold">{{itemgood.name}}</text>
                        <text class="Thinning">已售 {{itemgood.monthlysale}}</text>
                      </view>
                      <view class="unit-price">
                        <text class="Symbol">¥</text>
                        <text class="Bold">{{itemgood.unitprice}}</text>
                        <text class="Thinning">/{{itemgood.unit}}</text>
                      </view>
                    </view>
                    <!-- 无规格 -->
                    <view class="quantity" v-if="!itemgood.att_hide">
                      <view>
                        <image v-if="itemgood.quantity > 0" src="/static/tab/jianhao.png"
                          mode="widthFix"
                          @click.stop="channel('reduce',[index,good_index,item.cid,itemgood])"></image>
                      </view>
                      <view><text v-if="itemgood.quantity > 0">{{itemgood.quantity}}</text></view>
                      <view>
                        <image src="/static/tab/jia.png" mode="widthFix"
                          @click.stop="channel('plus',[index,good_index,item.cid,itemgood])"></image>
                      </view>
                    </view>
                    <!-- 有规格 -->
                    <view class="quantity specs-view" v-if="itemgood.att_hide">
                      <text>选规格</text>
                      <text v-if="itemgood.quantity > 0">{{itemgood.quantity}}</text>
                    </view>
                  </view>
                </view>
              </block>
              <view style="height: 400rpx;"></view>
            </scroll-view>
          </view>
        </view>
        <!-- 底部 -->
        <view class="order-bottom" @click="pop_Shopping()" :style="{'padding-bottom': Modelmes ? '68rpx' : ''}">
          <view class="Shopping" style="width: 115rpx;">
            <view class="Shopping-left">
              <image src="/static/tab/gouwuche.png" mode="widthFix"></image>
            </view>
            <view class="Shopping-number" v-if="total_quantity > 0">{{total_quantity}}</view>
          </view>
          <view class="Shopping-title" v-if="total_quantity > 0">已点{{total_quantity}}份菜品</view>
          <view class="place-order" @click.stop="total_quantity == 0 ? false : true && placean_order()">
            <button plain="true" open-type="getUserInfo">选好了</button>
          </view>
        </view>
      </view>
      <!-- 购物车 -->
      <Cart @empty_data="channel" @shopping_Cart_add_sub="channel" @close="pop_Shopping" v-if="card" :otherList="otherList" :shopping_card="shopping_card"></Cart>
      <!-- 引入单个商品弹出 -->
      <Details @reduce="channel" @plus="channel" @popup_item="popup_item" v-if="popupitem" :pro_details="pro_details"></Details>
      <!-- 骨架屏 -->
      <Home v-if="exist"></Home>
  <!--  <input v-model="value" placeholder="请输入您的id" />
    <input v-model="valueB" placeholder="请输入您发送的id" /> -->
    <!-- <button @click="onload()">确定</button> -->
    <!-- <button @click="returnClick">发送</button> -->
  </view>
</template>
  1. 订阅消息
//订阅消息
  goEasy.pubsub.subscribe({
    channel: "test_channel",//替换为您自己的channel
    onMessage: (message) => { //收到消息
      let obj = JSON.parse(message.content)
      // obj.data[3].uid = obj.uid
      this[obj.fun](...obj.data)
      // if(this.userId !== obj.uid) {
      //  this.otherList = obj.shopList
      //  if(this.otherList.length <= 0) {
      //    this.otherList = [obj.data[3]]
      //  }
      // } else {
      // }
      console.log("Channel:" + message.channel + " content:" + message.content);
    },
    onSuccess: function () {
      console.log("Channel订阅成功。");
    },
    onFailed: function (error) {
      console.log("Channel订阅失败, 错误编码:" + error.code + " 错误信息:" + error.content)
    }
  });
  1. 发送消息
//发送
channel(fun,data) {
  console.log('uni.getSystemInfoSync()-------',uni.getSystemInfoSync())
  //发送
  goEasy.pubsub.publish({
    channel: "test_channel",//替换为您自己的channel
    message: JSON.stringify({
      fun:fun,
      uid:this.userId,
      shopList:this.shopping_card,
      data:data
    }),//替换为您想要发送的消息内容
    onSuccess:res => {
      console.log("消息发布成功。");
    },
    onFailed: function (error) {
      console.log("消息发送失败,错误编码:"+error.code+" 错误信息:"+error.content);
    }
  })
}

项目预览

git:https://gitcode.net/qq_27161847/goEasy.git


相关文章
|
开发框架 移动开发 前端开发
Uni-App常用事件
Uni-App常用事件
532 2
|
JavaScript
vue3-在自定义hooks使用useRouter 报错问题
vue3-在自定义hooks使用useRouter 报错问题
2275 0
|
关系型数据库 MySQL
【Mysql】服务没有响应控制功能。 请键入 NET HELPMSG 2186 以获得更多的帮助。
解决方法: 1. 下载dll文件 https://www.aliyundrive.com/s/oV6GgghtPkN 2.将文件放置在mysql bin文件夹下 3. 重新启动Mysql,发现启动成功了!🚀
1578 1
|
监控 文件存储 Docker
实现NAS远程下载,Docker部署qBittorrent、Transmission、贝锐花生壳
与电脑不同,NAS通常7x24小时运行,便于下载资源,解决BT/PT下载需长时间在线的问题。因此,qBittorrent、Transmission等下载管理工具成为NAS用户的必备应用。通过Docker,用户可在多种NAS设备上快速安装这些工具,并通过局域网IP地址+端口访问。然而,缺乏公网IPv4地址导致远程访问困难,贝锐花生壳提供了解决方案,允许无公网IP情况下通过固定域名远程访问NAS中的下载工具,简化了部署过程,使用户能随时随地控制家中的下载任务。
935 33
实现NAS远程下载,Docker部署qBittorrent、Transmission、贝锐花生壳
|
11月前
|
SQL Oracle 关系型数据库
Navicat还原DMP文件步骤
Navicat还原DMP文件步骤
496 13
|
前端开发
Vue3 element-ui el-upload(上传组件) 上传图片后,隐藏上传按钮
Vue3 element-ui el-upload(上传组件) 上传图片后,隐藏上传按钮
955 0
|
11月前
|
XML JSON JavaScript
HttpGet 请求的响应处理:获取和解析数据
HttpGet 请求的响应处理:获取和解析数据
|
Java 关系型数据库 MySQL
create connection error, url: jdbc:mysql://localhost:3306/ssm, errorCode 1045, state 28000 java.sql.
create connection error, url: jdbc:mysql://localhost:3306/ssm, errorCode 1045, state 28000 java.sql.
391 0
|
Java 关系型数据库 MySQL
JavaWeb基础第一章(MySQL数据库与JDBC)
JavaWeb基础第一章(MySQL数据库与JDBC)
下一篇
开通oss服务