first commit

This commit is contained in:
zhouyanli
2026-10-27 13:54:39 +08:00
commit 5c9aca27e8
24 changed files with 1498 additions and 0 deletions

9
.editorconfig Normal file
View File

@@ -0,0 +1,9 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
unpackage/
.DS_Store
.hbuilderx/

67
App.vue Normal file
View File

@@ -0,0 +1,67 @@
<script setup>
import { onLaunch } from '@dcloudio/uni-app'
// 小程序只承载免押流程,启动时无需额外初始化
onLaunch(() => {})
</script>
<style>
/* 全局主题 */
page {
--brand-blue: #1e6bff;
--brand-blue-light: #4a90ff;
--text-primary: #1a1a1a;
--text-secondary: #666666;
--text-placeholder: #999999;
--border-color: #eeeeee;
background-color: #ffffff;
font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
}
view,
text {
box-sizing: border-box;
}
/* 底部固定操作区 */
.bottom-bar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
z-index: 10;
padding: 24rpx 48rpx;
padding-bottom: calc(24rpx + constant(safe-area-inset-bottom));
padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
background: #ffffff;
}
/* 主按钮 */
.btn-primary {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 92rpx;
margin: 0;
padding: 0;
border: none;
border-radius: 46rpx;
background: linear-gradient(90deg, #3f8bff 0%, #1e6bff 100%);
font-size: 32rpx;
font-weight: 500;
letter-spacing: 2rpx;
color: #ffffff;
line-height: 92rpx;
}
.btn-primary::after {
border: none;
}
.btn-primary[disabled] {
opacity: 0.6;
color: #ffffff;
background: linear-gradient(90deg, #3f8bff 0%, #1e6bff 100%);
}
</style>

52
README.md Normal file
View File

@@ -0,0 +1,52 @@
# 宠物智能项圈 · 芝麻免押小程序
支付宝小程序(uni-app + Vue3),只承载**芝麻信用免押**这一段流程;添加设备、查看宠物数据等其他操作都在宠物 App 内完成。
页面与组件统一用 Vue3 `<script setup>` 写法:状态用 `ref`,页面生命周期从 `@dcloudio/uni-app` 引入(`onLoad` / `onUnload` / `onLaunch`)。
## 流程与页面
参考 `static/企业微信截图_179300609524.png` 的五屏:
| 屏 | 归属 | 页面 |
| --- | --- | --- |
| 1 免押下单 | 小程序 | `pages/index/index` |
| 2 原生授权页 | 支付宝提供 | 不在本仓库,`utils/zhima.js` 拉起 |
| 3 芝麻分/减免弹窗 | 支付宝提供 | 不在本仓库 |
| 4 免押成功 | 小程序 | `pages/result/result`,按钮「前往添加设备」→ 交接宠物 App |
| 5 押金状态 | 小程序 | `pages/deposit/deposit` |
协议占位页:`pages/agreement/agreement`(上线前替换为正式文本)。
## 目录
```
config/index.js 品牌、物品、押金、接口地址、宠物 App 跳转配置
api/order.js 订单接口(mock / 真实请求切换)
api/mock.js 无服务端时的本地 mock(storage 持久化)
utils/request.js 请求封装
utils/zhima.js 拉起支付宝原生免押授权(唯一调用点)
utils/pet-app.js 交接到宠物 App(添加设备)
components/credit-header 蓝色头部 + 芝麻信用标识
components/rental-info 租赁物品 / 押金信息行
docs/api.md 给服务端的接口约定
```
## 本地运行
1. HBuilderX 打开本目录,`manifest.json` → 支付宝小程序 → 填 AppID。
2. 运行到「支付宝小程序」,用支付宝开发者工具打开 `unpackage/dist/dev/mp-alipay`。
3. 当前 `config/index.js` 为 `useMock: true`,不需要后端即可走完:继续 → 模拟授权 → 成功页 → 前往添加设备。
## 接入真实环境要改的地方
- `config/index.js`:`useMock: false`、`apiBaseUrl`、`petApp.openUrl` / `downloadUrl`、品牌名称与 logo、押金金额以服务端为准。
- `utils/zhima.js`:按开通后的芝麻信用文档替换 `my.zmCreditBorrow` 调用参数;非支付宝环境会直接报错提示。
- `pages.json`:支付宝端的自定义头部靠 `transparentTitle: "always"` + `titlePenetrate: "YES"` + 空标题实现,返回按钮用原生导航栏自带的那个(白色)。`navigationStyle: custom` 只对其他端生效。
- 真机上若原生返回按钮压到页面内容,把 `credit-header` 里 `#ifdef MP-ALIPAY` 那段改回自行绘制返回箭头,并在页面 `onShow` 调用 `my.hideBack()`。
## 待确认
- 「押金状态」页目前没有入口:截图里它是独立页,真实场景应通过支付宝订单消息 / 门店扫码头带 `orderId` 进入(页面已支持 `?orderId=`,不传则取最近一单)。
- 押金 69 元、租期等是否符合「信用借还」标准方案(押金 ≤1000 元、租期 ≤1 个月)需与芝麻能力申请结果对齐。
- 宠物 App 的唤起方式(universal link / 下载页)取决于开放平台报备结果,当前默认「提示 + 复制下载链接」。

89
api/mock.js Normal file
View File

@@ -0,0 +1,89 @@
/**
* 本地 mock 数据层
*
* 用来在没有服务端的情况下跑通前端流程,订单存在 storage 里,
* 方便重复进入小程序时还能看到押金状态。
* 接入真实服务端后由 api/order.js 切到 HTTP 请求,这里不再参与。
*/
const STORAGE_KEY = 'mock_credit_orders'
let seq = 0
function delay(ms = 300) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
function readOrders() {
const orders = uni.getStorageSync(STORAGE_KEY)
return Array.isArray(orders) ? orders : []
}
function writeOrders(orders) {
uni.setStorageSync(STORAGE_KEY, orders)
}
function findOrder(orderId) {
return readOrders().find((item) => item.orderId === orderId) || null
}
function updateOrder(orderId, patch) {
const orders = readOrders()
const index = orders.findIndex((item) => item.orderId === orderId)
if (index === -1) return null
orders[index] = { ...orders[index], ...patch }
writeOrders(orders)
return { ...orders[index] }
}
/** 创建免押订单(真实环境由服务端调芝麻接口创建信用借还订单后返回单号) */
export async function createCreditOrder(payload) {
await delay()
const now = Date.now()
const order = {
orderId: `CO${now}${++seq}`,
creditBorrowOrderId: `ZM${now}`,
itemName: payload.itemName,
depositAmount: payload.depositAmount,
// CREDIT=信用免押,PAID=现场付押金
depositMode: 'CREDIT',
// PENDING=授权中,ACTIVE=免押生效,RELEASED=已解除
status: 'PENDING',
createdAt: now
}
writeOrders([order, ...readOrders()])
return { ...order }
}
/**
* 模拟服务端收到支付宝异步通知后,把订单置为免押生效。
* 真实环境由服务端 notify 处理,小程序只做查询。
*/
export async function syncOrderStatus(orderId) {
await delay(200)
const order = findOrder(orderId)
if (!order) throw new Error('订单不存在')
if (order.status === 'PENDING') return updateOrder(orderId, { status: 'ACTIVE' })
return order
}
export async function getOrder(orderId) {
await delay(150)
const order = findOrder(orderId)
if (!order) throw new Error('订单不存在')
return order
}
export async function getLatestOrder() {
await delay(150)
const orders = readOrders()
return orders.length ? orders[0] : null
}
/** 解除信用授权 / 退还押金 */
export async function releaseCreditOrder(orderId) {
await delay(400)
const order = updateOrder(orderId, { status: 'RELEASED', releasedAt: Date.now() })
if (!order) throw new Error('订单不存在')
return order
}

41
api/order.js Normal file
View File

@@ -0,0 +1,41 @@
import config from '@/config'
import { request } from '@/utils/request'
import * as mock from './mock'
/**
* 免押订单接口
*
* 所有涉及芝麻信用的密钥、加签、异步 notify 都只在服务端处理,
* 小程序端只拿服务端返回的订单号去拉起原生授权页。
*/
/** 创建免押订单,返回 { orderId, creditBorrowOrderId } */
export function createCreditOrder(payload) {
if (config.useMock) return mock.createCreditOrder(payload)
return request({ url: '/api/credit/orders', method: 'POST', data: payload })
}
/**
* 查询订单(免押结果页轮询用)
* mock 下顺便模拟支付宝异步通知把订单置为生效。
*/
export function syncOrderStatus(orderId) {
if (config.useMock) return mock.syncOrderStatus(orderId)
return request({ url: `/api/credit/orders/${orderId}` })
}
export function getOrder(orderId) {
if (config.useMock) return mock.getOrder(orderId)
return request({ url: `/api/credit/orders/${orderId}` })
}
export function getLatestOrder() {
if (config.useMock) return mock.getLatestOrder()
return request({ url: '/api/credit/orders/latest' })
}
/** 解除信用授权 / 退还押金 */
export function releaseCreditOrder(orderId) {
if (config.useMock) return mock.releaseCreditOrder(orderId)
return request({ url: `/api/credit/orders/${orderId}/release`, method: 'POST' })
}

View File

@@ -0,0 +1,155 @@
<template>
<view class="credit-header" :class="{ 'is-curved': curved }">
<view :style="{ height: statusBarHeight + 'px' }"></view>
<view class="nav-bar">
<view v-if="showBack && canBack" class="back-btn" @tap="handleBack">
<view class="back-arrow"></view>
</view>
</view>
<view v-if="showBadge" class="zm-badge">
<view class="zm-logo"><text class="zm-logo-text">芝</text></view>
<text class="zm-text">芝麻信用</text>
</view>
<view class="hero-title">
<text class="hero-slash">///</text>
<text class="hero-text">{{ title }}</text>
<text class="hero-slash">///</text>
</view>
<slot></slot>
</view>
</template>
<script setup>
import { ref, onMounted } from 'vue'
defineProps({
title: {
type: String,
default: ''
},
// 是否显示「芝麻信用」标识(押金页不显示)
showBadge: {
type: Boolean,
default: false
},
showBack: {
type: Boolean,
default: true
},
// 底部是否做成弧形(下单页)
curved: {
type: Boolean,
default: false
}
})
const statusBarHeight = ref(0)
const canBack = ref(false)
onMounted(() => {
statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight || 0
// 支付宝端用透明原生导航栏自带的返回按钮(pages.json 里 navigationBarTextStyle 已设为白色),
// 这里不再画第二个箭头;其他端没有原生导航栏,自己画。
// #ifdef MP-ALIPAY
canBack.value = false
// #endif
// #ifndef MP-ALIPAY
canBack.value = getCurrentPages().length > 1
// #endif
})
function handleBack() {
if (getCurrentPages().length > 1) {
uni.navigateBack()
}
}
</script>
<style>
.credit-header {
position: relative;
padding-bottom: 72rpx;
background: linear-gradient(180deg, #4a90ff 0%, #1e6bff 100%);
color: #ffffff;
}
/* 下单页:底部弧形,并给悬浮的品牌卡片留出上半部分高度 */
.credit-header.is-curved {
padding-bottom: 140rpx;
border-radius: 0 0 50% 50% / 0 0 96rpx 96rpx;
}
.nav-bar {
display: flex;
align-items: center;
height: 88rpx;
padding: 0 24rpx;
}
.back-btn {
display: flex;
align-items: center;
justify-content: center;
width: 72rpx;
height: 72rpx;
}
.back-arrow {
width: 22rpx;
height: 22rpx;
margin-left: 8rpx;
border-left: 4rpx solid #ffffff;
border-bottom: 4rpx solid #ffffff;
transform: rotate(45deg);
}
.zm-badge {
display: flex;
align-items: center;
justify-content: center;
margin-top: 8rpx;
}
.zm-logo {
display: flex;
align-items: center;
justify-content: center;
width: 40rpx;
height: 40rpx;
border-radius: 50%;
background: #ffffff;
}
.zm-logo-text {
font-size: 22rpx;
font-weight: 600;
color: #1e6bff;
}
.zm-text {
margin-left: 12rpx;
font-size: 26rpx;
color: rgba(255, 255, 255, 0.95);
}
.hero-title {
display: flex;
align-items: center;
justify-content: center;
margin-top: 20rpx;
}
.hero-text {
font-size: 40rpx;
font-weight: 600;
letter-spacing: 4rpx;
}
.hero-slash {
margin: 0 20rpx;
font-size: 32rpx;
font-style: italic;
color: rgba(255, 255, 255, 0.55);
}
</style>

View File

@@ -0,0 +1,96 @@
<template>
<view class="rental-info">
<view class="info-row">
<text class="row-label">租赁物品</text>
<text class="row-value">{{ itemName }}</text>
</view>
<view class="info-row last">
<text class="row-label">押金</text>
<view class="row-value-wrap">
<text v-if="creditFree" class="free-tag">免押金</text>
<text class="amount" :class="{ 'is-free': creditFree }">{{ depositAmount }}</text>
<text class="amount-unit" :class="{ 'is-free': creditFree }">元</text>
</view>
</view>
</view>
</template>
<script setup>
defineProps({
itemName: {
type: String,
default: ''
},
depositAmount: {
type: [Number, String],
default: ''
},
// 信用免押时展示「免押金」标签,现场付押金时不展示
creditFree: {
type: Boolean,
default: true
}
})
</script>
<style>
.rental-info {
padding: 0 40rpx;
}
.info-row {
display: flex;
align-items: center;
justify-content: space-between;
height: 112rpx;
border-bottom: 1rpx solid #eeeeee;
}
.info-row.last {
border-bottom: none;
}
.row-label {
font-size: 28rpx;
color: #666666;
}
.row-value {
font-size: 28rpx;
font-weight: 600;
color: #1a1a1a;
}
.row-value-wrap {
display: flex;
align-items: center;
}
.free-tag {
margin-right: 12rpx;
padding: 2rpx 10rpx;
border: 1rpx solid rgba(30, 107, 255, 0.45);
border-radius: 8rpx;
font-size: 24rpx;
color: #1e6bff;
}
.amount {
font-size: 34rpx;
font-weight: 600;
color: #1a1a1a;
}
.amount-unit {
margin-left: 4rpx;
font-size: 26rpx;
font-weight: 600;
color: #1a1a1a;
}
/* 免押时把原押金划掉 */
.amount.is-free,
.amount-unit.is-free {
text-decoration: line-through;
}
</style>

36
config/index.js Normal file
View File

@@ -0,0 +1,36 @@
/**
* 全局业务配置
*
* 本小程序只负责「芝麻信用免押」这一段流程:
* 下单页 → 支付宝原生授权页(支付宝提供)→ 免押结果页 → 押金状态页
* 添加设备、查看宠物数据等其他操作都在宠物 App 内完成。
*/
const config = {
// 品牌信息
brandName: '宠物智能项圈',
brandLogo: '/static/logo.png',
// 租赁物品与押金,仅用于页面展示,真实金额以服务端下单结果为准
itemName: '宠物智能项圈',
depositAmount: 69,
// 服务端接口
apiBaseUrl: 'https://api.example.com',
// 服务端未就绪时用本地 mock 跑通前端流程,联调时改成 false
useMock: true,
// 宠物 App:添加设备等操作回去做
petApp: {
// 唤起 App 的地址,需在支付宝开放平台报备后才可用(如 universal link)
openUrl: '',
// 唤起失败时给用户复制的下载地址
downloadUrl: ''
},
// 协议页面(当前是本地占位页,正式文本请替换为芝麻信用官方协议地址)
agreements: {
credit: '/pages/agreement/agreement'
}
}
export default config

87
docs/api.md Normal file
View File

@@ -0,0 +1,87 @@
# 免押订单接口约定(给服务端)
小程序端只负责展示和拉起支付宝原生授权页,**所有芝麻信用相关调用、密钥、加签、异步通知都在服务端**。
前端目前走 `config/index.js` 的 `useMock: true` 本地 mock,服务端就绪后改 `false` 即可切到下面这套接口。
统一返回体:
```json
{ "code": 0, "message": "", "data": {} }
```
`code` 为 `0` 表示成功,非 0 时把 `message` 直接弹给用户。
## 1. 创建免押订单
```
POST /api/credit/orders
```
请求:
```json
{
"itemName": "宠物智能项圈",
"depositAmount": 69
}
```
服务端要做的事:调芝麻信用开放接口创建信用借还订单,把支付宝返回的信用借还单号一并下发。
响应:
```json
{
"orderId": "CO20261027120000",
"creditBorrowOrderId": "ZM20261027120000"
}
```
`creditBorrowOrderId` 是小程序拉起原生授权页时唯一要用的参数(见 `utils/zhima.js`)。
## 2. 查询订单
```
GET /api/credit/orders/{orderId}
```
响应(字段与 mock 对齐):
```json
{
"orderId": "CO20261027120000",
"itemName": "宠物智能项圈",
"depositAmount": 69,
"depositMode": "CREDIT",
"status": "ACTIVE",
"createdAt": 1761537600000
}
```
- `depositMode`:`CREDIT` 信用免押 / `PAID` 现场付押金
- `status`:`PENDING` 授权中 / `ACTIVE` 免押生效 / `RELEASED` 已解除 / `OVERDUE` 逾期未还
免押结果页会轮询这个接口(约 1.2 秒一次、最多 6 次)确认最终状态,**不要**用客户端回调直接判定成功。
## 3. 最近一单
```
GET /api/credit/orders/latest
```
无订单时返回 `null`(`data: null`)。
## 4. 解除信用授权 / 退还押金
```
POST /api/credit/orders/{orderId}/release
```
服务端调芝麻接口结束信用订单,并同步完成押金/履约处理;返回更新后的订单对象。
## 服务端必须兜住的几件事
1. **异步通知(notify)验签 + 幂等**:芝麻的授权结果、订单完结等以 notify 为准,重复通知只处理一次。
2. **信用闭环回传**:订单生成、逾期、归还完结都要真实回传支付宝,不能造数据。
3. **密钥不下发**:加签私钥、商户 ID 只留服务端,小程序只拿 `orderId` / `creditBorrowOrderId`。
4. **接口名以开通后的文档为准**:芝麻信用「信用借还」的具体开放接口名、参数随能力开通版本变化,本仓库没有硬编码,集中在 `utils/zhima.js` 与本文档两处待替换。

20
index.html Normal file
View File

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<script>
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
CSS.supports('top: constant(a)'))
document.write(
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
(coverSupport ? ', viewport-fit=cover' : '') + '" />')
</script>
<title></title>
<!--preload-links-->
<!--app-context-->
</head>
<body>
<div id="app"><!--app-html--></div>
<script type="module" src="/main.js"></script>
</body>
</html>

24
main.js Normal file
View File

@@ -0,0 +1,24 @@
import App from './App'
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
// #endif
// #ifdef VUE3
import {
createSSRApp
} from 'vue'
export function createApp() {
const app = createSSRApp(App)
return {
app
}
}
// #endif

71
manifest.json Normal file
View File

@@ -0,0 +1,71 @@
{
"name" : "chongdun-mianya",
"appid" : "__UNI__2A0D116",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
"transformPx" : false,
/* 5+App特有相关 */
"app-plus" : {
"usingComponents" : true,
"nvueStyleCompiler" : "uni-app",
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : true,
"waiting" : true,
"autoclose" : true,
"delay" : 0
},
/* 模块配置 */
"modules" : {},
/* 应用发布信息 */
"distribute" : {
/* android打包配置 */
"android" : {
"permissions" : [
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
]
},
/* ios打包配置 */
"ios" : {},
/* SDK配置 */
"sdkConfigs" : {}
}
},
/* 快应用特有相关 */
"quickapp" : {},
/* 小程序特有相关 */
"mp-weixin" : {
"appid" : "",
"setting" : {
"urlCheck" : false
},
"usingComponents" : true
},
"mp-alipay" : {
/* 在支付宝开放平台创建小程序后,把 appid 填到这里 */
"appid" : "",
"usingComponents" : true
},
"mp-baidu" : {
"usingComponents" : true
},
"mp-toutiao" : {
"usingComponents" : true
},
"vueVersion" : "3"
}

49
pages.json Normal file
View File

@@ -0,0 +1,49 @@
{
//pages数组中第一项表示应用启动页
"pages": [
{
"path": "pages/index/index",
"style": {
// 支付宝端靠 transparentTitle + titlePenetrate 实现自定义头部,
// navigationStyle: custom 只在微信/H5 生效
"navigationStyle": "custom",
"transparentTitle": "always",
"titlePenetrate": "YES",
"navigationBarTitleText": "",
"navigationBarTextStyle": "white"
}
},
{
"path": "pages/result/result",
"style": {
"navigationStyle": "custom",
"transparentTitle": "always",
"titlePenetrate": "YES",
"navigationBarTitleText": "",
"navigationBarTextStyle": "white"
}
},
{
"path": "pages/deposit/deposit",
"style": {
"navigationStyle": "custom",
"transparentTitle": "always",
"titlePenetrate": "YES",
"navigationBarTitleText": "",
"navigationBarTextStyle": "white"
}
},
{
"path": "pages/agreement/agreement",
"style": {
"navigationBarTitleText": "芝麻信用协议及授权条款"
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "宠物智能项圈免押",
"navigationBarBackgroundColor": "#FFFFFF",
"backgroundColor": "#FFFFFF"
}
}

View File

@@ -0,0 +1,78 @@
<template>
<view class="agreement-page">
<view class="title">芝麻信用协议及授权条款</view>
<view class="update">更新日期:2026-10-27</view>
<view class="section">
<view class="section-title">一、授权范围</view>
<view class="paragraph">
用户同意本小程序在办理宠物智能项圈租赁免押时,向芝麻信用查询用户的信用评估结果,
用于判断是否免除押金。用户可随时在支付宝「芝麻信用 - 我的 - 信用管理」中查看或解除授权。
</view>
</view>
<view class="section">
<view class="section-title">二、免押与履约</view>
<view class="paragraph">
免押租赁期间,用户应按约定时间归还设备并保证设备完好。逾期未归还或设备损坏的,
按门店租赁规则处理,并可能影响用户的芝麻信用记录。
</view>
</view>
<view class="section">
<view class="section-title">三、信息使用</view>
<view class="paragraph">
本小程序仅将信用评估结果用于本次免押判断,不会用于与租赁无关的用途,
相关信息的存储与保护遵循法律法规及芝麻信用平台规则。
</view>
</view>
<view class="placeholder">注:以上为占位文本,正式上线前需替换为经法务/芝麻信用确认的协议全文。</view>
</view>
</template>
<style>
.agreement-page {
padding: 40rpx;
background: #ffffff;
}
.title {
font-size: 36rpx;
font-weight: 600;
color: #1a1a1a;
}
.update {
margin-top: 12rpx;
font-size: 24rpx;
color: #999999;
}
.section {
margin-top: 40rpx;
}
.section-title {
margin-bottom: 16rpx;
font-size: 30rpx;
font-weight: 600;
color: #1a1a1a;
}
.paragraph {
font-size: 28rpx;
line-height: 1.8;
color: #555555;
}
.placeholder {
margin-top: 60rpx;
padding: 24rpx;
border-radius: 12rpx;
background: #f5f7fa;
font-size: 24rpx;
line-height: 1.6;
color: #999999;
}
</style>

93
pages/deposit/deposit.vue Normal file
View File

@@ -0,0 +1,93 @@
<template>
<view class="page">
<credit-header title="押金" :show-badge="false"></credit-header>
<view v-if="order" class="info-section">
<rental-info
:item-name="order.itemName"
:deposit-amount="order.depositAmount"
:credit-free="order.depositMode === 'CREDIT'"
></rental-info>
</view>
<view v-else class="empty">暂无押金订单</view>
<view class="bottom-bar">
<button class="btn-primary" :disabled="releasing || !order" @tap="handleRelease">
{{ releasing ? '处理中...' : '解除信用授权/退还押金' }}
</button>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { getOrder, getLatestOrder, releaseCreditOrder } from '@/api/order'
const orderId = ref('')
const order = ref(null)
const releasing = ref(false)
onLoad((query) => {
orderId.value = (query && query.orderId) || ''
loadOrder()
})
async function loadOrder() {
try {
order.value = orderId.value ? await getOrder(orderId.value) : await getLatestOrder()
} catch (error) {
order.value = null
}
}
function handleRelease() {
if (!order.value || releasing.value) return
uni.showModal({
title: '解除信用授权',
content: '解除后本次免押将不再有效,押金按门店规则处理,确认继续?',
confirmText: '确认解除',
confirmColor: '#1E6BFF',
success: (res) => {
if (res.confirm) doRelease()
}
})
}
async function doRelease() {
releasing.value = true
uni.showLoading({ title: '处理中', mask: true })
try {
await releaseCreditOrder(order.value.orderId)
uni.hideLoading()
uni.showToast({ title: '已解除信用授权', icon: 'success' })
setTimeout(() => {
uni.reLaunch({ url: '/pages/index/index' })
}, 1200)
} catch (error) {
uni.hideLoading()
uni.showToast({ title: error.message || '操作失败,请稍后重试', icon: 'none' })
} finally {
releasing.value = false
}
}
</script>
<style>
.page {
min-height: 100vh;
padding-bottom: 220rpx;
background: #ffffff;
}
.info-section {
margin-top: 24rpx;
}
.empty {
padding-top: 120rpx;
text-align: center;
font-size: 28rpx;
color: #999999;
}
</style>

181
pages/index/index.vue Normal file
View File

@@ -0,0 +1,181 @@
<template>
<view class="page">
<credit-header title="信用免押金" :show-badge="true" curved></credit-header>
<view class="brand-card">
<image class="brand-logo" :src="brandLogo" mode="aspectFit"></image>
</view>
<view class="brand-name">{{ brandName }}</view>
<view class="info-section">
<rental-info :item-name="itemName" :deposit-amount="depositAmount" credit-free></rental-info>
</view>
<view class="agreement" @tap="toggleAgree">
<view class="checkbox" :class="{ checked: agreed }">
<view v-if="agreed" class="checkbox-check"></view>
</view>
<view class="agreement-text">
我已阅读并同意
<text class="agreement-link" @tap.stop="openAgreement">《芝麻信用协议及授权条款》</text>
</view>
</view>
<view class="tip">注:请记得归还物品哦,以免对你的信用产生影响</view>
<view class="bottom-bar">
<button class="btn-primary" :disabled="submitting" @tap="handleContinue">
{{ submitting ? '处理中...' : '继续' }}
</button>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue'
import config from '@/config'
import { createCreditOrder, syncOrderStatus } from '@/api/order'
import { authorizeCreditBorrow } from '@/utils/zhima'
const brandName = config.brandName
const brandLogo = config.brandLogo
const itemName = config.itemName
const depositAmount = config.depositAmount
const agreed = ref(false)
const submitting = ref(false)
function toggleAgree() {
agreed.value = !agreed.value
}
function openAgreement() {
uni.navigateTo({ url: config.agreements.credit })
}
async function handleContinue() {
if (submitting.value) return
if (!agreed.value) {
uni.showToast({ title: '请先阅读并同意协议', icon: 'none' })
return
}
submitting.value = true
try {
// 1. 服务端创建免押订单,同时向芝麻创建信用借还订单
uni.showLoading({ title: '创建订单中', mask: true })
const order = await createCreditOrder({
itemName,
depositAmount
})
// 2. 拉起支付宝原生授权页
uni.hideLoading()
await authorizeCreditBorrow(order)
// 3. 以服务端订单状态为准:真实环境靠芝麻异步通知回写
uni.showLoading({ title: '确认免押中', mask: true })
await syncOrderStatus(order.orderId)
uni.hideLoading()
uni.redirectTo({ url: `/pages/result/result?orderId=${order.orderId}` })
} catch (error) {
uni.hideLoading()
uni.showToast({ title: error.message || '免押开通失败,请重试', icon: 'none' })
} finally {
submitting.value = false
}
}
</script>
<style>
.page {
min-height: 100vh;
padding-bottom: 220rpx;
background: #ffffff;
}
/* 卡片压在蓝色头部与白色内容交界处,对应截图里的悬浮效果 */
.brand-card {
position: relative;
z-index: 2;
display: flex;
align-items: center;
justify-content: center;
width: 200rpx;
height: 200rpx;
margin: -120rpx auto 0;
border-radius: 32rpx;
background: #ffffff;
box-shadow: 0 12rpx 40rpx rgba(0, 0, 0, 0.12);
}
.brand-logo {
width: 140rpx;
height: 140rpx;
}
.brand-name {
margin-top: 32rpx;
text-align: center;
font-size: 36rpx;
font-weight: 600;
color: #1a1a1a;
}
.info-section {
margin-top: 72rpx;
}
.agreement {
display: flex;
align-items: flex-start;
margin: 48rpx 40rpx 0;
}
.checkbox {
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
width: 32rpx;
height: 32rpx;
margin-top: 4rpx;
border: 2rpx solid #c9cdd4;
border-radius: 50%;
background: #ffffff;
}
.checkbox.checked {
border-color: #1e6bff;
background: #1e6bff;
}
.checkbox-check {
width: 12rpx;
height: 6rpx;
margin-top: -4rpx;
border-left: 2rpx solid #ffffff;
border-bottom: 2rpx solid #ffffff;
transform: rotate(-45deg);
}
.agreement-text {
margin-left: 14rpx;
font-size: 26rpx;
line-height: 1.5;
color: #333333;
}
.agreement-link {
color: #1e6bff;
}
.tip {
margin: 20rpx 40rpx 0 86rpx;
font-size: 24rpx;
line-height: 1.6;
color: #999999;
}
</style>

121
pages/result/result.vue Normal file
View File

@@ -0,0 +1,121 @@
<template>
<view class="page">
<credit-header title="信用免押金" :show-badge="true"></credit-header>
<view class="result">
<view class="success-icon">
<view class="success-check"></view>
</view>
<view class="result-title">成功</view>
<view class="result-desc">免押申请成功</view>
<view v-if="pollDone && !confirmed" class="result-hint">订单状态确认中,稍后可在支付宝订单中查看</view>
</view>
<view class="bottom-bar">
<button class="btn-primary" @tap="goAddDevice">前往添加设备</button>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue'
import { onLoad, onUnload } from '@dcloudio/uni-app'
import { getOrder } from '@/api/order'
import { openPetApp } from '@/utils/pet-app'
const orderId = ref('')
const confirmed = ref(false)
const pollDone = ref(false)
let pollTimes = 0
let pollTimer = null
onLoad((query) => {
orderId.value = (query && query.orderId) || ''
loadOrder()
})
onUnload(() => {
if (pollTimer) clearTimeout(pollTimer)
})
async function loadOrder() {
if (!orderId.value) return
try {
const order = await getOrder(orderId.value)
confirmed.value = !!order && order.status === 'ACTIVE'
} catch (error) {
// 查询失败不打断展示,状态可在支付宝订单详情中查看
}
if (confirmed.value) return
if (pollTimes < 6) {
pollTimes += 1
pollTimer = setTimeout(loadOrder, 1200)
} else {
pollDone.value = true
}
}
// 添加设备在宠物 App 内完成,小程序只做交接
function goAddDevice() {
openPetApp()
}
</script>
<style>
.page {
min-height: 100vh;
padding-bottom: 220rpx;
background: #ffffff;
}
.result {
display: flex;
flex-direction: column;
align-items: center;
padding-top: 120rpx;
}
.success-icon {
display: flex;
align-items: center;
justify-content: center;
width: 160rpx;
height: 160rpx;
border-radius: 50%;
background: linear-gradient(180deg, #4a90ff 0%, #1e6bff 100%);
box-shadow: 0 16rpx 40rpx rgba(30, 107, 255, 0.28);
}
.success-check {
width: 62rpx;
height: 34rpx;
margin-top: -10rpx;
border-left: 8rpx solid #ffffff;
border-bottom: 8rpx solid #ffffff;
transform: rotate(-45deg);
}
.result-title {
margin-top: 48rpx;
font-size: 40rpx;
font-weight: 600;
color: #1a1a1a;
}
.result-desc {
margin-top: 16rpx;
font-size: 28rpx;
color: #666666;
}
.result-hint {
margin-top: 24rpx;
padding: 0 64rpx;
text-align: center;
font-size: 24rpx;
line-height: 1.6;
color: #999999;
}
</style>

BIN
static/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

14
uni.promisify.adaptor.js Normal file
View File

@@ -0,0 +1,14 @@
uni.addInterceptor({
returnValue(res) {
if (!(!!res && (typeof res === "object" || typeof res === "function") && typeof res.then ===
"function")) {
return res;
}
return new Promise((resolve, reject) => {
res.then((res) => {
if (!res) return resolve(res)
return res[0] ? reject(res[0]) : resolve(res[1])
});
});
},
});

76
uni.scss Normal file
View File

@@ -0,0 +1,76 @@
/**
* 这里是uni-app内置的常用样式变量
*
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
*
*/
/**
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
*
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
*/
/* 颜色变量 */
/* 行为相关颜色 */
$uni-color-primary: #007aff;
$uni-color-success: #4cd964;
$uni-color-warning: #f0ad4e;
$uni-color-error: #dd524d;
/* 文字基本颜色 */
$uni-text-color:#333;//基本色
$uni-text-color-inverse:#fff;//反色
$uni-text-color-grey:#999;//辅助灰色,如加载更多的提示信息
$uni-text-color-placeholder: #808080;
$uni-text-color-disable:#c0c0c0;
/* 背景颜色 */
$uni-bg-color:#ffffff;
$uni-bg-color-grey:#f8f8f8;
$uni-bg-color-hover:#f1f1f1;//点击状态颜色
$uni-bg-color-mask:rgba(0, 0, 0, 0.4);//遮罩颜色
/* 边框颜色 */
$uni-border-color:#c8c7cc;
/* 尺寸变量 */
/* 文字尺寸 */
$uni-font-size-sm:12px;
$uni-font-size-base:14px;
$uni-font-size-lg:16px;
/* 图片尺寸 */
$uni-img-size-sm:20px;
$uni-img-size-base:26px;
$uni-img-size-lg:40px;
/* Border Radius */
$uni-border-radius-sm: 2px;
$uni-border-radius-base: 3px;
$uni-border-radius-lg: 6px;
$uni-border-radius-circle: 50%;
/* 水平间距 */
$uni-spacing-row-sm: 5px;
$uni-spacing-row-base: 10px;
$uni-spacing-row-lg: 15px;
/* 垂直间距 */
$uni-spacing-col-sm: 4px;
$uni-spacing-col-base: 8px;
$uni-spacing-col-lg: 12px;
/* 透明度 */
$uni-opacity-disabled: 0.3; // 组件禁用态的透明度
/* 文章场景相关 */
$uni-color-title: #2C405A; // 文章标题颜色
$uni-font-size-title:20px;
$uni-color-subtitle: #555555; // 二级标题颜色
$uni-font-size-subtitle:26px;
$uni-color-paragraph: #3F536E; // 文章段落颜色
$uni-font-size-paragraph:15px;

71
utils/pet-app.js Normal file
View File

@@ -0,0 +1,71 @@
import config from '@/config'
/**
* 小程序内不做添加设备,只负责把用户交回宠物 App。
* 支付宝小程序无法直接拉起任意第三方 App,openUrl 需要在开放平台报备后才能用,
* 所以默认走「提示 + 复制下载链接」的兜底。
*/
function copyText(text) {
uni.setClipboardData({
data: text,
success: () => uni.showToast({ title: '链接已复制', icon: 'none' })
})
}
function tryOpenUrl(url) {
if (!url) return false
try {
// #ifdef MP-ALIPAY
if (typeof my !== 'undefined' && my.ap && typeof my.ap.openURL === 'function') {
my.ap.openURL({ url, fail: () => {} })
return true
}
// #endif
// #ifdef H5
window.location.href = url
return true
// #endif
} catch (e) {
// 忽略,走兜底
}
return false
}
export function openPetApp() {
const { openUrl, downloadUrl } = config.petApp
const content = '添加设备、绑定项圈需要在宠物 App 内完成。'
if (openUrl && downloadUrl) {
uni.showModal({
title: '前往宠物 App 添加设备',
content,
confirmText: '打开 App',
cancelText: '复制链接',
success: (res) => {
if (res.confirm && tryOpenUrl(openUrl)) return
copyText(downloadUrl)
}
})
return
}
if (downloadUrl) {
uni.showModal({
title: '前往宠物 App 添加设备',
content: `${content}是否复制 App 下载链接?`,
confirmText: '复制链接',
success: (res) => {
if (res.confirm) copyText(downloadUrl)
}
})
return
}
uni.showModal({
title: '前往宠物 App 添加设备',
content,
showCancel: false,
confirmText: '我知道了'
})
}

33
utils/request.js Normal file
View File

@@ -0,0 +1,33 @@
import config from '@/config'
/**
* 服务端请求封装
*
* 约定返回体:{ code: 0, message: '', data: {...} }
* code 为 0 或未返回时视为成功,data 直接透出。
*/
export function request({ url, method = 'GET', data = {}, header = {} }) {
return new Promise((resolve, reject) => {
uni.request({
url: /^https?:\/\//.test(url) ? url : config.apiBaseUrl + url,
method,
data,
header: {
'Content-Type': 'application/json',
...header
},
success: (res) => {
const body = res.data || {}
const ok = res.statusCode >= 200 && res.statusCode < 300
if (ok && (body.code === undefined || body.code === 0)) {
resolve(body.data !== undefined ? body.data : body)
return
}
reject(new Error(body.message || `请求失败(${res.statusCode})`))
},
fail: (err) => {
reject(new Error(err.errMsg || '网络异常,请稍后重试'))
}
})
})
}

32
utils/zhima.js Normal file
View File

@@ -0,0 +1,32 @@
import config from '@/config'
/**
* 拉起支付宝原生「信用免押」授权页(截图第 2、3 屏,页面由支付宝提供)。
*
* 小程序端能做的只有把服务端创建好的信用借还单号交给支付宝,
* 具体调用方式以开通芝麻信用能力后的开放平台文档为准,统一收在这一个函数里替换,
* 避免接口名散落在页面中。
*/
export function authorizeCreditBorrow({ orderId, creditBorrowOrderId }) {
if (config.useMock) {
// mock:模拟用户在原生授权页点了「同意」
return new Promise((resolve) => setTimeout(() => resolve({ authorized: true }), 600))
}
const inAlipay = typeof my !== 'undefined'
const canBorrow = inAlipay && my.zmCreditBorrow && typeof my.zmCreditBorrow === 'function'
if (!canBorrow) {
return Promise.reject(new Error('当前环境不支持芝麻信用免押,请用支付宝扫码打开'))
}
return new Promise((resolve, reject) => {
my.zmCreditBorrow({
creditBorrowOrderId,
// 注意:授权成功回调只代表用户点了同意,免押是否真正生效
// 以服务端收到芝麻异步通知后的订单状态为准
success: () => resolve({ authorized: true }),
fail: (err) => reject(new Error((err && err.errorMessage) || '免押授权未完成'))
})
})
}