标签 uni-app 下的文章

两种截然不同的产品逻辑:前者是把社会外卖平台简单搬进校园,后者则是真正理解校园场景后构建的本地化服务生态。真正的校园外卖,绝非 “社会平台的简化版”,而是一套需要深度重构的 “懂校园、贴场景、有温度” 的服务体系。


一、走出“便宜至上”的误区:需求分层的金字塔模型

  1. 基础层(生存刚需):30分钟内稳定送达、10-20元主流价格带、食品安全底线保障。这是入场券,但不是决胜点。
  2. 场景层(节奏适配)

    • 时间适配:早课前8:00-8:05的“5分钟早餐包”、图书馆闭馆后的“深夜能量站”。
    • 空间适配:教室与宿舍区不同菜单、社团活动“拼单套餐”一键成团。
    • 社交适配:宿舍拼单免配送费、“分享考研加油餐得优惠”、可定制的“教授同款午餐”。
  3. 情感层(身份认同):这超越了功能本身,产品成为他们校园生活的“伙伴”而非工具。能否提供情绪价值、营造归属感的关键。

外卖端页面展示:

二、破解“高峰堰塞湖”:用“时空切割法”重构运力与体验

  • 空间切割

    • 教学饥荒区(教学楼群):主打“课间极速达”,供应可快速进食的简餐、咖啡。
    • 宿舍深水区(生活区):提供“夜间专属菜单”,如粥品、小吃,并延长服务时间。
    • 社交荒漠区(体育场、活动中心):预设“团建套餐”,满足班级、社团活动需求。
  • 时间预测:打通或模拟教务系统API,获取全校课表。在上午第四节下课、晚上选修课结束前,系统预判需求,提前向合作商户推送热销套餐备餐指令。
  • 运力革命:组建“校园配送联盟”,招募勤工俭学的学生作为配送员。优势显著:

    • 成本优化:学生兼职成本更低,且时间与订单高峰天然契合。
    • 信任穿透:校内同学身份,可直达宿舍楼内,解决“最后100米”难题。
    • 灵活调度:基于课程空闲时间派单,实现运力匹配。

商户端页面展示:

三、从“送餐”到“送一切”:构建校园生活服务中枢

单一的外卖功能有限。成功的小程序,早已演化成校园本地生活的超级入口。已验证的高频衍生场景包括:

  1. 外卖/快递代取:发布需求,由顺路的同学有偿接单送达。
  2. 资料/物品代送:忘带课本、急需文件,可发起校内闪送。
  3. 线上打印:上传文档,选择就近打印点,付费后直接送到寝室。
  4. 生活服务整合:二手交易、电脑维修、干洗服务、代买日用品等,均可接入平台。

骑手端页面展示:

四、技术为骨,运营为肉:让数据驱动“懂校园”的智慧

  • 技术选型:前端采用 Uni-app 实现一套代码多端发布(微信小程序、H5、App),后端使用 Tp6框架 开发管理后台,兼顾开发效率与系统稳定性。
  • 数据核心:不仅仅是处理订单,更重要的是数据分析。研判各区域、各时段、各人群的消费偏好,
  • 生态扩展:在基础平台上,可搭载 “校园圈子” 系统,形成信息互动社区。并可进一步插件化扩展,如:

    • 独立管理的社团专区
    • 1v1音视频通话(用于兼职面试、活动沟通)。
    • 求职招聘、兼职信息 频道。
    • 这些插件可根据学校特点进行私人化定制,让每个校园的生态都具有独特性。

后端管理系统看板:

uniappx服务端推送消息配置

一.前置条件

1.申请Dcloud 开发者账号(https://www.dcloud.io/
2.HBuilder安装
3.安装模拟器
4.uni-push 2.0 文档(https://uniapp.dcloud.net.cn/unipush-v2.html
5.创建一个uniappx项目
image.png

二.配置步骤

1.确认AppID

打开项目中 manifest.json 文件,确认AppId是否存在,若不存在则点击右侧 重新获取 按钮(此处可能需要登录Dcloud账号),会生成AppID
image.png

2.构建项目生成证书

点击 Hbuilder 菜单 运行 》 运行到手机或模拟器 》 制作自定义调试基座
image.png
点击打包,会出现打包校验提示,继续打包即可,随即会在控制台打印相关信息,此处等待时间可能较长,我们继续推进下一步,打包后台运行即可。
image.png

3.新建uniCloud

登录Dcloud 开发者中心,点击左侧uniCloud...
image.png
在新标签页中点击右上角新建服务空间,按提示完成即可,例子中建立一个叫uniapp-hello 的服务空间(取名仅作区分,无其他含义,视自己习惯命名即可);
image.png

4.创建应用信息推送

回到Dcloud开发者管理页面,点击左侧uni-push > 2.0(支持全段推送) > 应用信息
image.png
点击当前应用下拉框,选择我们需要推送的应用
image.png

选择平台视业务而定,此处示例仅勾选Android
image.png
点击选择Android包名,若包名不存在,则需等待上一步打包结束后刷新当前页面重新选择,
再添加云服务空间,选中上一步创建的空间即可,最后点击开通应用
image.png

5.创建云函数

在项目目录下的uniCloud 》coudfunctions 目录右键,选择新建云函数/云对象(若没有uniCloud目录可在项目根目录上右键,选择 创建uniCloud云开发环境 )
image.png
填写函数名点击创建即可
image.png
随后替换新建函数下的index.js 和 package.json 内容
image.png

index.js新内容如下(需替换第二行中自己的appId):


'use strict';
const uniPush = uniCloud.getPushManager({appId:"__UNI__XXXXX"}) 
exports.main = async (event, context) => {
    const body = JSON.parse(event.body);
    return await uniPush.sendMessage({
        "push_clientid": body.cid,     
        "title": body.title,    
        "content": body.content,
        "payload": body.data
    })
};
 

package.json新内容如下:

{
    "name": "photo_push",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "extensions": {
        "uni-cloud-push": {} 
    },
    "author": ""
}

6.增加uni-push 能力

在Hbuilder中打开manifest.json,勾选uni-push(消息推送)
image.png
在新建立的photo-push 目录上右键,选择 管理公共模块或扩展库依赖
image.png
选中统一推送服务,点击确定
image.png

7.增加扩展库依赖表

在database目录下增加以下依赖表文件(文件内容见结尾附件)
image.png
在 opendb-device.index.json 右键 》 初始化云数据库索引
剩余其他三个文件 右键 》 上传DB schema

8.上传部署云函数

随后在photo-push 目录点击 右键 》 上传部署,等待上传完成即可
image.png

9.云函数URL化

回到第三步创建发unicloud服务空间,点击 服务空间 名称进入详情页
在左侧 云函数/对象列表找到创建的云函数
image.png
点击函数名进入详情页,页面底部 云函数URL化编辑配置函数名 /sendMessage
注:每个服务空间内函数名不可重复,且URL路径不可出现重复部分
image.png

10.项目增加消息监听

在项目App.uvue中 onLaunch()生命函数中增加监听代码
image.png

uni.onPushMessage(res => {
                console.log("监听消息:", res)                
                if (res.type == "click") {
                    console.log("点击消息:" + res)
                }
                if (res.type == "receive") {
                    console.log("收到APP消息" + res.data);
                    // 创建本地通知栏消息
                    uni.createPushMessage({
                        title: res.data.title as string,
                        content: res.data.content as string,
                        payload: res.data.payload
                    })
                }
            }) 

11.启动项目

启动模拟器,此处以 网易Mumu模拟器 演示
Hbuilder 菜单点击 运行 》 运行到手机或模拟器 》 运行到Android App 基座
选择设备后运行,等待控制台编译完成
image.png
控制台选择 连接云端云函数
image.png

12.发起调用

使用云函数URL发起调用
image.png

效果如图
image.png
请求参数说明:

{
    "cid": ["02e3c939927d45df1028b274e493488c"], // 设备ID,长度不超过500
    "title": "绿12",
    "content": "收到消息12",
    "data": {    // data 为自定义业务参数,该字段可不传
        "type": "messageList"
    }
}

附件

●opendb-device.index.json

[
    {
        "IndexName": "index_device_id",
        "MgoKeySchema": {
            "MgoIndexKeys": [
                {
                    "Name": "device_id",
                    "Direction": "1"
                }
            ],
            "MgoIsUnique": true
        }
    }
]

●opendb-device.schema.json

{
    "bsonType": "object",
    "required": [],
    "permission": {
        "read": false,
        "create": true,
        "update": false,
        "delete": false
    },
    "properties": {
        "_id": {
            "description": "ID,系统自动生成"
        },
        "appid": {
            "bsonType": "string",
            "description": "DCloud appid"
        },
        "device_id": {
            "bsonType": "string",
            "description": "设备唯一标识"
        },
        "vendor": {
            "bsonType": "string",
            "description": "设备厂商"
        },
        "push_clientid": {
            "bsonType": "string",
            "description": "推送设备客户端标识"
        },
        "imei": {
            "bsonType": "string",
            "description": "国际移动设备识别码IMEI(International Mobile Equipment Identity)"
        },
        "oaid": {
            "bsonType": "string",
            "description": "移动智能设备标识公共服务平台提供的匿名设备标识符(OAID)"
        },
        "idfa": {
            "bsonType": "string",
            "description": "iOS平台配置应用使用广告标识(IDFA)"
        },
        "imsi": {
            "bsonType": "string",
            "description": "国际移动用户识别码(International Mobile Subscriber Identification Number)"
        },
        "model": {
            "bsonType": "string",
            "description": "设备型号"
        },
        "platform": {
            "bsonType": "string",
            "description": "平台类型"
        },
        "uni_platform": {
            "bsonType": "string",
            "description": "uni-app 运行平台,与条件编译平台相同。"
        },
        "os_name": {
            "bsonType": "string",
            "description": "ios|android|windows|mac|linux "
        },
        "os_version": {
            "bsonType": "string",
            "description": "操作系统版本号 "
        },
        "os_language": {
            "bsonType": "string",
            "description": "操作系统语言 "
        },
        "os_theme": {
            "bsonType": "string",
            "description": "操作系统主题 light|dark"
        },
        "pixel_ratio": {
            "bsonType": "string",
            "description": "设备像素比 "
        },
        "network_model": {
            "bsonType": "string",
            "description": "设备网络型号wifi\/3G\/4G\/"
        },
        "window_width": {
            "bsonType": "string",
            "description": "设备窗口宽度 "
        },
        "window_height": {
            "bsonType": "string",
            "description": "设备窗口高度"
        },
        "screen_width": {
            "bsonType": "string",
            "description": "设备屏幕宽度"
        },
        "screen_height": {
            "bsonType": "string",
            "description": "设备屏幕高度"
        },
        "rom_name": {
            "bsonType": "string",
            "description": "rom 名称"
        },
        "rom_version": {
            "bsonType": "string",
            "description": "rom 版本"
        },
        "location_latitude": {
            "bsonType": "double",
            "description": "纬度"
        },
        "location_longitude": {
            "bsonType": "double",
            "description": "经度"
        },
        "location_country": {
            "bsonType": "string",
            "description": "国家"
        },
        "location_province": {
            "bsonType": "string",
            "description": "省份"
        },
        "location_city": {
            "bsonType": "string",
            "description": "城市"
        },
        "create_date": {
            "bsonType": "timestamp",
            "description": "创建时间",
            "forceDefaultValue": {
                "$env": "now"
            }
        },
        "last_update_date": {
            "bsonType": "timestamp",
            "description": "最后一次修改时间",
            "forceDefaultValue": {
                "$env": "now"
            }
        }
    },
    "version": "0.0.1"
}

●opendb-tempdata.schema.json

{
    "bsonType": "object",
    "required": ["value", "expired"],
    "permission": {
        "read": false,
        "create": false,
        "update": false,
        "delete": false
    },
    "properties": {
        "_id": {
            "description": "ID,系统自动生成"
        },
        "value": {
            "description": "值"
        },
        "expired": {
            "description": "过期时间",
            "bsonType": "timestamp"
        }
    }
}

●uni-id-device.schema.json

{
    "bsonType": "object",
    "required": [
        "user_id"
    ],
    "properties": {
        "_id": {
            "description": "ID,系统自动生成"
        },
        "user_id": {
            "bsonType": "string",
            "description": "用户id,参考uni-id-users表"
        },
        "ua": {
            "bsonType": "string",
            "description": "userAgent"
        },
        "uuid": {
            "bsonType": "string",
            "description": "设备唯一标识(需要加密存储)"
        },
        "os_name": {
            "bsonType": "string",
            "description": "ios|android|windows|mac|linux "
        },
        "os_version": {
            "bsonType": "string",
            "description": "操作系统版本号 "
        },
        "os_language": {
            "bsonType": "string",
            "description": "操作系统语言 "
        },
        "os_theme": {
            "bsonType": "string",
            "description": "操作系统主题 light|dark"
        },
        "vendor": {
            "bsonType": "string",
            "description": "设备厂商"
        },
        "push_clientid": {
            "bsonType": "string",
            "description": "推送设备客户端标识"
        },
        "imei": {
            "bsonType": "string",
            "description": "国际移动设备识别码IMEI(International Mobile Equipment Identity)"
        },
        "oaid": {
            "bsonType": "string",
            "description": "移动智能设备标识公共服务平台提供的匿名设备标识符(OAID)"
        },
        "idfa": {
            "bsonType": "string",
            "description": "iOS平台配置应用使用广告标识(IDFA)"
        },
        "model": {
            "bsonType": "string",
            "description": "设备型号"
        },
        "platform": {
            "bsonType": "string",
            "description": "平台类型"
        },
        "create_date": {
            "bsonType": "timestamp",
            "description": "创建时间",
            "forceDefaultValue": {
                "$env": "now"
            }
        },
        "last_active_date": {
            "bsonType": "timestamp",
            "description": "最后登录时间"
        },
        "last_active_ip": {
            "bsonType": "string",
            "description": "最后登录IP"
        }
    },
    "version": "0.0.1"
}