使用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


相关文章
|
23天前
|
JSON 自然语言处理 测试技术
2026 年 Qwen4-Max 预览版与 Qwen3.8 系列对比说明
Qwen4-Max预览版的价值在于"复杂任务一次做对",2折则是把这种能力临时拉到可承受的成本区间。正确用法是:用免费额度验证效果,用2折期完成压测与迁移,用资源包承接稳定期用量。同时记住预览版的三个变量——模型可能迭代、价格限时、折扣不叠加。把这些边界写进预算表,2折才是真的省。
371 0
uni-app监听页面滚动
uni-app监听页面滚动
1319 0
|
移动开发 Android开发 iOS开发
uniapp开发H5及app监听返回事件(以及监听不到的处理方法)
uniapp开发H5及app监听返回事件(以及监听不到的处理方法)
3755 0
|
Java
解决Java- 错误: 找不到或无法加载主类 HelloWorld.java
针对初学者使用javac,java等命令编译class文件时出现的经典问题,提供解决思路和方法。
11641 98
解决Java- 错误: 找不到或无法加载主类 HelloWorld.java
|
24天前
|
JSON 前端开发 API
阿里云最新Qwen4-Max大模型介绍:模型定位、特征、能力、适用场景解析
2026 年 11 月 11 日,阿里发布第四代旗舰模型Qwen4-Max预览版,首发千问 AI 平台 Token Plan,并同步接入千问办公、Qoder 等入口。该版本聚焦知识理解、世界感知、编程与 Agentic 四项升级,主打复杂编程、专业办公、前端设计与专业软件操作。预览期至 11 月 25 日 24:00,到期后模型标识下线;限时 2 折、新用户再享 5 折,最低 1 折可体验。
|
3月前
|
存储 人工智能 监控
预览下一代Qwen4架构,解析Qwen3.8‑Flash的Coding、Agent与成本优势
2026年,Qwen团队正式对外推出Qwen3.8‑Flash‑Next开源权重模型,对应的线上生产服务版本命名为Qwen3.8‑Flash。这套模型不只是一次常规版本迭代,更是下一代Qwen4整套架构思路的提前对外预览,在稀疏激活架构、超长上下文、代码工程能力、智能体工具调用以及推理成本层面都带来了非常关键的变化。总参数规模125B,采用稀疏MoE设计,每一个Token推理阶段仅激活约6B参数;开源版本原生支持262144 Token上下文窗口,借助YaRN技术可扩展至100万Token;线上云服务版本Qwen3.8‑Flash默认直接开启100万Token上下文能力,同时大幅强化代码处理、
2645 0
|
域名解析 网络协议 网络安全
SSL证书验证全攻略:DNS/HTTP/手动解析怎么选?
SSL证书在网络安全中至关重要,1Panel提供三种验证方式:DNS验证、HTTP验证和手动解析。DNS验证便捷,适合CDN网站;HTTP验证快速,需服务器在线;手动解析灵活,但操作复杂。根据需求选择合适确认方式,定期检查证书状态。
1938 2
|
前端开发 API UED
封装 uniapp 请求库的最佳实践
背景 在前端开发中,HTTP 请求是与服务器进行数据交互的核心手段。无论是获取数据还是提交数据,前端应用几乎都离不开 HTTP 请求。在 uniapp 中,uni.request 是官方提供的用于发起 HTTP 请求的基础 API。然而,直接使用 uni.request 存在一些问题和不足,比如: 1. 代码冗余:每次发起请求时都需要编写类似的配置代码,导致代码重复。 2. 缺乏统一管理:没有统一的地方管理请求参数、头信息、错误处理等,使得代码不易维护
798 7
|
域名解析 网络协议 安全
DNS服务器地址大全
DNS(域名系统)是互联网的“电话簿”,将域名解析为IP地址。选择优质DNS服务器可提升网络速度、降低延迟。以下是全球及中国各运营商的DNS服务器列表,包括公共DNS(如Google DNS、Cloudflare DNS)、中国电信、联通、移动等。根据地理位置、稳定性、安全性与隐私保护等因素选择适合的DNS服务器,优化上网体验。
58287 6