骑手端app代码仓库创建
This commit is contained in:
30
.env
Normal file
30
.env
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# 版本号
|
||||||
|
SHOPRO_VERSION=v2.3.0
|
||||||
|
|
||||||
|
# 后端接口 - 正式环境(通过 process.env.NODE_ENV 非 development)
|
||||||
|
SHOPRO_BASE_URL = http://api.jnmall.zq-hightech.com
|
||||||
|
|
||||||
|
# 后端接口 - 测试环境(通过 process.env.NODE_ENV = development)
|
||||||
|
SHOPRO_DEV_BASE_URL = https://icepacker.52cfzy.com
|
||||||
|
|
||||||
|
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持 S3 服务
|
||||||
|
SHOPRO_UPLOAD_TYPE=server
|
||||||
|
|
||||||
|
# 后端接口前缀(一般不建议调整)
|
||||||
|
SHOPRO_API_PATH=/app-api
|
||||||
|
|
||||||
|
# 后端 websocket 接口前缀
|
||||||
|
SHOPRO_WEBSOCKET_PATH=/infra/ws
|
||||||
|
|
||||||
|
# 开发环境运行端口
|
||||||
|
SHOPRO_DEV_PORT=3000
|
||||||
|
|
||||||
|
# 客户端静态资源地址 空=默认使用服务端指定的CDN资源地址前缀 | local=本地 | http(s)://xxx.xxx=自定义静态资源地址前缀
|
||||||
|
SHOPRO_STATIC_URL=http://api.jnmall.zq-hightech.com/miniapp
|
||||||
|
### SHOPRO_STATIC_URL = https://file.sheepjs.com
|
||||||
|
|
||||||
|
# 是否开启直播 1 开启直播 | 0 关闭直播 (小程序官方后台未审核开通直播权限时请勿开启)
|
||||||
|
SHOPRO_MPLIVE_ON=0
|
||||||
|
|
||||||
|
# 租户ID 默认 1
|
||||||
|
SHOPRO_TENANT_ID=1
|
||||||
13
.gitignore
vendored
Normal file
13
.gitignore
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
unpackage/*
|
||||||
|
node_modules/*
|
||||||
|
.idea/*
|
||||||
|
deploy.sh
|
||||||
|
.hbuilderx/
|
||||||
|
.vscode/
|
||||||
|
**/.DS_Store
|
||||||
|
yarn.lock
|
||||||
|
package-lock.json
|
||||||
|
*.keystore
|
||||||
|
pnpm-lock.yaml
|
||||||
|
/unpackage
|
||||||
|
/node_modules
|
||||||
6
.prettierignore
Normal file
6
.prettierignore
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
/unpackage/*
|
||||||
|
/node_modules/**
|
||||||
|
/uni_modules/**
|
||||||
|
/public/*
|
||||||
|
**/*.svg
|
||||||
|
**/*.sh
|
||||||
10
.prettierrc
Normal file
10
.prettierrc
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 100,
|
||||||
|
"semi": true,
|
||||||
|
"vueIndentScriptAndStyle": true,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "all",
|
||||||
|
"proseWrap": "never",
|
||||||
|
"htmlWhitespaceSensitivity": "strict",
|
||||||
|
"endOfLine": "auto"
|
||||||
|
}
|
||||||
39
App.vue
Normal file
39
App.vue
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<script setup>
|
||||||
|
import { onLaunch, onShow, onError } from '@dcloudio/uni-app';
|
||||||
|
import { ShoproInit } from './sheep';
|
||||||
|
|
||||||
|
onLaunch(() => {
|
||||||
|
// 隐藏原生导航栏 使用自定义底部导航
|
||||||
|
// uni.hideTabBar();
|
||||||
|
|
||||||
|
// 加载Shopro底层依赖
|
||||||
|
ShoproInit();
|
||||||
|
});
|
||||||
|
|
||||||
|
onError((err) => {
|
||||||
|
console.log('AppOnError:', err);
|
||||||
|
});
|
||||||
|
|
||||||
|
onShow((options) => {
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
// 获取urlSchemes参数
|
||||||
|
const args = plus.runtime.arguments;
|
||||||
|
if (args) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取剪贴板
|
||||||
|
uni.getClipboardData({
|
||||||
|
success: (res) => { },
|
||||||
|
});
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
// 确认收货回调结果
|
||||||
|
console.log(options,'options');
|
||||||
|
// #endif
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
@import '@/sheep/scss/index.scss';
|
||||||
|
</style>
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2022 lidongtony
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
56
README.md
Normal file
56
README.md
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
**严肃声明:现在、未来都不会有商业版本,所有代码全部开源!!**
|
||||||
|
|
||||||
|
**「我喜欢写代码,乐此不疲」**
|
||||||
|
**「我喜欢做开源,以此为乐」**
|
||||||
|
|
||||||
|
我 🐶 在上海艰苦奋斗,早中晚在 top3 大厂认真搬砖,夜里为开源做贡献。
|
||||||
|
|
||||||
|
如果这个项目让你有所收获,记得 Star 关注哦,这对我是非常不错的鼓励与支持。
|
||||||
|
|
||||||
|
## 🐶 新手必读
|
||||||
|
|
||||||
|
* 演示地址:<https://doc.iocoder.cn/mall-preview/>
|
||||||
|
* 启动文档:<https://doc.iocoder.cn/quick-start/>
|
||||||
|
* 视频教程:<https://doc.iocoder.cn/video/>
|
||||||
|
|
||||||
|
## 🐯 商城简介
|
||||||
|
|
||||||
|
**芋道商城**,基于 [芋道开发平台](https://github.com/YunaiV/ruoyi-vue-pro) 构建,以开发者为中心,打造中国第一流的 Java 开源商城系统,全部开源,个人与企业可 100% 免费使用。
|
||||||
|
|
||||||
|
> 有任何问题,或者想要的功能,可以在 Issues 中提给艿艿。
|
||||||
|
>
|
||||||
|
> 😜 给项目点点 Star 吧,这对我们真的很重要!
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
* 基于 uni-app + Vue3 开发,支持微信小程序、微信公众号、H5 移动端,未来会支持支付宝小程序、抖音小程序等
|
||||||
|
* 支持 SaaS 多租户,可满足商品、订单、支付、会员、优惠券、秒杀、拼团、砍价、分销、积分等多种经营需求
|
||||||
|
|
||||||
|
## 🔥 后端架构
|
||||||
|
|
||||||
|
支持 Spring Boot、Spring Cloud 两种架构:
|
||||||
|
|
||||||
|
① Spring Boot 单体架构:<https://doc.iocoder.cn>
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
② Spring Cloud 微服务架构:<https://cloud.iocoder.cn>
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 🐱 移动端预览
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 🐶 管理端预览
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
3
androidPrivacy.json
Normal file
3
androidPrivacy.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"prompt" : "template"
|
||||||
|
}
|
||||||
17
index.html
Normal file
17
index.html
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta
|
||||||
|
name="viewport"
|
||||||
|
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
|
||||||
|
/>
|
||||||
|
<title></title>
|
||||||
|
<!--preload-links-->
|
||||||
|
<!--app-context-->
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"><!--app-html--></div>
|
||||||
|
<script type="module" src="/main.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
9
jsconfig.json
Normal file
9
jsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"jsx": "preserve",
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["./*"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
main.js
Normal file
15
main.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import App from './App';
|
||||||
|
import { createSSRApp } from 'vue';
|
||||||
|
import { setupPinia } from './sheep/store';
|
||||||
|
|
||||||
|
|
||||||
|
export function createApp() {
|
||||||
|
|
||||||
|
const app = createSSRApp(App);
|
||||||
|
|
||||||
|
setupPinia(app);
|
||||||
|
|
||||||
|
return {
|
||||||
|
app,
|
||||||
|
};
|
||||||
|
}
|
||||||
240
manifest.json
Normal file
240
manifest.json
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
{
|
||||||
|
"name": "云南江楠商城",
|
||||||
|
"appid": "__UNI__4E984D1",
|
||||||
|
"description": "基于 uni-app + Vue3 技术驱动的在线商城系统,内含诸多功能与丰富的活动,期待您的使用和反馈。",
|
||||||
|
"versionName": "2.1.0",
|
||||||
|
"versionCode": "183",
|
||||||
|
"transformPx": false,
|
||||||
|
"app-plus": {
|
||||||
|
"usingComponents": true,
|
||||||
|
"nvueCompiler": "uni-app",
|
||||||
|
"nvueStyleCompiler": "uni-app",
|
||||||
|
"compilerVersion": 3,
|
||||||
|
"nvueLaunchMode": "fast",
|
||||||
|
"splashscreen": {
|
||||||
|
"alwaysShowBeforeRender": true,
|
||||||
|
"waiting": true,
|
||||||
|
"autoclose": true,
|
||||||
|
"delay": 0
|
||||||
|
},
|
||||||
|
"safearea": {
|
||||||
|
"bottom": {
|
||||||
|
"offset": "none"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"modules": {
|
||||||
|
"Payment": {},
|
||||||
|
"Share": {},
|
||||||
|
"VideoPlayer": {},
|
||||||
|
"OAuth": {}
|
||||||
|
},
|
||||||
|
"distribute": {
|
||||||
|
"android": {
|
||||||
|
"permissions": [
|
||||||
|
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
||||||
|
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.ACCESS_MOCK_LOCATION\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.CALL_PHONE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.GET_TASKS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.INTERNET\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.READ_CONTACTS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.READ_SMS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.RECEIVE_BOOT_COMPLETED\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.SEND_SMS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.SYSTEM_ALERT_WINDOW\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.WRITE_CONTACTS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.WRITE_SMS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.RECEIVE_USER_PRESENT\"/>"
|
||||||
|
],
|
||||||
|
"minSdkVersion": 21,
|
||||||
|
"schemes": "shopro"
|
||||||
|
},
|
||||||
|
"ios": {
|
||||||
|
"urlschemewhitelist": [
|
||||||
|
"baidumap",
|
||||||
|
"iosamap"
|
||||||
|
],
|
||||||
|
"dSYMs": false,
|
||||||
|
"privacyDescription": {
|
||||||
|
"NSPhotoLibraryUsageDescription": "需要同意访问您的相册选取图片才能完善该条目",
|
||||||
|
"NSPhotoLibraryAddUsageDescription": "需要同意访问您的相册才能保存该图片",
|
||||||
|
"NSCameraUsageDescription": "需要同意访问您的摄像头拍摄照片才能完善该条目",
|
||||||
|
"NSUserTrackingUsageDescription": "开启追踪并不会获取您在其它站点的隐私信息,该行为仅用于标识设备,保障服务安全和提升浏览体验"
|
||||||
|
},
|
||||||
|
"urltypes": "shopro",
|
||||||
|
"capabilities": {
|
||||||
|
"entitlements": {
|
||||||
|
"com.apple.developer.associated-domains": [
|
||||||
|
"applinks:shopro.sheepjs.com"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"idfa": true
|
||||||
|
},
|
||||||
|
"sdkConfigs": {
|
||||||
|
"speech": {
|
||||||
|
"ifly": {}
|
||||||
|
},
|
||||||
|
"ad": {},
|
||||||
|
"oauth": {
|
||||||
|
"apple": {},
|
||||||
|
"weixin": {
|
||||||
|
"appid": "wxae7a0c156da9383b",
|
||||||
|
"UniversalLinks": "https://shopro.sheepjs.com/uni-universallinks/__UNI__082C0BA/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"payment": {
|
||||||
|
"weixin": {
|
||||||
|
"__platform__": [
|
||||||
|
"ios",
|
||||||
|
"android"
|
||||||
|
],
|
||||||
|
"appid": "wxae7a0c156da9383b",
|
||||||
|
"UniversalLinks": "https://shopro.sheepjs.com/uni-universallinks/__UNI__082C0BA/"
|
||||||
|
},
|
||||||
|
"alipay": {
|
||||||
|
"__platform__": [
|
||||||
|
"ios",
|
||||||
|
"android"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"share": {
|
||||||
|
"weixin": {
|
||||||
|
"appid": "wxae7a0c156da9383b",
|
||||||
|
"UniversalLinks": "https://shopro.sheepjs.com/uni-universallinks/__UNI__082C0BA/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"orientation": [
|
||||||
|
"portrait-primary"
|
||||||
|
],
|
||||||
|
"splashscreen": {
|
||||||
|
"androidStyle": "common",
|
||||||
|
"iosStyle": "common",
|
||||||
|
"useOriginalMsgbox": true
|
||||||
|
},
|
||||||
|
"icons": {
|
||||||
|
"android": {
|
||||||
|
"hdpi": "unpackage/res/icons/72x72.png",
|
||||||
|
"xhdpi": "unpackage/res/icons/96x96.png",
|
||||||
|
"xxhdpi": "unpackage/res/icons/144x144.png",
|
||||||
|
"xxxhdpi": "unpackage/res/icons/192x192.png"
|
||||||
|
},
|
||||||
|
"ios": {
|
||||||
|
"appstore": "unpackage/res/icons/1024x1024.png",
|
||||||
|
"ipad": {
|
||||||
|
"app": "unpackage/res/icons/76x76.png",
|
||||||
|
"app@2x": "unpackage/res/icons/152x152.png",
|
||||||
|
"notification": "unpackage/res/icons/20x20.png",
|
||||||
|
"notification@2x": "unpackage/res/icons/40x40.png",
|
||||||
|
"proapp@2x": "unpackage/res/icons/167x167.png",
|
||||||
|
"settings": "unpackage/res/icons/29x29.png",
|
||||||
|
"settings@2x": "unpackage/res/icons/58x58.png",
|
||||||
|
"spotlight": "unpackage/res/icons/40x40.png",
|
||||||
|
"spotlight@2x": "unpackage/res/icons/80x80.png"
|
||||||
|
},
|
||||||
|
"iphone": {
|
||||||
|
"app@2x": "unpackage/res/icons/120x120.png",
|
||||||
|
"app@3x": "unpackage/res/icons/180x180.png",
|
||||||
|
"notification@2x": "unpackage/res/icons/40x40.png",
|
||||||
|
"notification@3x": "unpackage/res/icons/60x60.png",
|
||||||
|
"settings@2x": "unpackage/res/icons/58x58.png",
|
||||||
|
"settings@3x": "unpackage/res/icons/87x87.png",
|
||||||
|
"spotlight@2x": "unpackage/res/icons/80x80.png",
|
||||||
|
"spotlight@3x": "unpackage/res/icons/120x120.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"quickapp": {},
|
||||||
|
"quickapp-native": {
|
||||||
|
"icon": "/static/logo.png",
|
||||||
|
"package": "com.example.demo",
|
||||||
|
"features": [
|
||||||
|
{
|
||||||
|
"name": "system.clipboard"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"quickapp-webview": {
|
||||||
|
"icon": "/static/logo.png",
|
||||||
|
"package": "com.example.demo",
|
||||||
|
"minPlatformVersion": 1070,
|
||||||
|
"versionName": "1.0.0",
|
||||||
|
"versionCode": 100
|
||||||
|
},
|
||||||
|
"mp-weixin": {
|
||||||
|
"appid": "wxfcfcbdebfb0d99ad",
|
||||||
|
"setting": {
|
||||||
|
"urlCheck": false,
|
||||||
|
"minified": true,
|
||||||
|
"postcss": false,
|
||||||
|
"es6": false
|
||||||
|
},
|
||||||
|
"optimization": {
|
||||||
|
"subPackages": true
|
||||||
|
},
|
||||||
|
"plugins": {},
|
||||||
|
"lazyCodeLoading": "requiredComponents",
|
||||||
|
"usingComponents": {},
|
||||||
|
"permission": {},
|
||||||
|
"requiredPrivateInfos": [
|
||||||
|
"chooseAddress"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"mp-alipay": {
|
||||||
|
"usingComponents": true
|
||||||
|
},
|
||||||
|
"mp-baidu": {
|
||||||
|
"usingComponents": true
|
||||||
|
},
|
||||||
|
"mp-toutiao": {
|
||||||
|
"usingComponents": true
|
||||||
|
},
|
||||||
|
"mp-jd": {
|
||||||
|
"usingComponents": true
|
||||||
|
},
|
||||||
|
"h5": {
|
||||||
|
"template": "index.html",
|
||||||
|
"router": {
|
||||||
|
"mode": "history",
|
||||||
|
"base": "/"
|
||||||
|
},
|
||||||
|
"sdkConfigs": {
|
||||||
|
"maps": {}
|
||||||
|
},
|
||||||
|
"async": {
|
||||||
|
"timeout": 20000
|
||||||
|
},
|
||||||
|
"title": "云南江楠商城",
|
||||||
|
"optimization": {
|
||||||
|
"treeShaking": {
|
||||||
|
"enable": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"vueVersion": "3",
|
||||||
|
"_spaceID": "192b4892-5452-4e1d-9f09-eee1ece40639",
|
||||||
|
"locale": "zh-Hans",
|
||||||
|
"fallbackLocale": "zh-Hans"
|
||||||
|
}
|
||||||
103
package.json
Normal file
103
package.json
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
{
|
||||||
|
"id": "shopro",
|
||||||
|
"name": "shopro",
|
||||||
|
"displayName": "芋道商城",
|
||||||
|
"version": "2.3.0",
|
||||||
|
"description": "芋道商城,一套代码,同时发行到iOS、Android、H5、微信小程序多个平台,请使用手机扫码快速体验强大功能",
|
||||||
|
"scripts": {
|
||||||
|
"prettier": "prettier --write \"{pages,sheep}/**/*.{js,json,tsx,css,less,scss,vue,html,md}\""
|
||||||
|
},
|
||||||
|
"repository": "https://github.com/sheepjs/shop.git",
|
||||||
|
"keywords": [
|
||||||
|
"商城",
|
||||||
|
"B2C",
|
||||||
|
"商城模板"
|
||||||
|
],
|
||||||
|
"author": "",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/sheepjs/shop/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/dcloudio/hello-uniapp#readme",
|
||||||
|
"dcloudext": {
|
||||||
|
"category": [
|
||||||
|
"前端页面模板",
|
||||||
|
"uni-app前端项目模板"
|
||||||
|
],
|
||||||
|
"sale": {
|
||||||
|
"regular": {
|
||||||
|
"price": "0.00"
|
||||||
|
},
|
||||||
|
"sourcecode": {
|
||||||
|
"price": "0.00"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"contact": {
|
||||||
|
"qq": ""
|
||||||
|
},
|
||||||
|
"declaration": {
|
||||||
|
"ads": "无",
|
||||||
|
"data": "无",
|
||||||
|
"permissions": "无"
|
||||||
|
},
|
||||||
|
"npmurl": ""
|
||||||
|
},
|
||||||
|
"uni_modules": {
|
||||||
|
"dependencies": [],
|
||||||
|
"encrypt": [],
|
||||||
|
"platforms": {
|
||||||
|
"cloud": {
|
||||||
|
"tcb": "u",
|
||||||
|
"aliyun": "u"
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"App": {
|
||||||
|
"app-vue": "y",
|
||||||
|
"app-nvue": "u"
|
||||||
|
},
|
||||||
|
"H5-mobile": {
|
||||||
|
"Safari": "y",
|
||||||
|
"Android Browser": "y",
|
||||||
|
"微信浏览器(Android)": "y",
|
||||||
|
"QQ浏览器(Android)": "y"
|
||||||
|
},
|
||||||
|
"H5-pc": {
|
||||||
|
"Chrome": "y",
|
||||||
|
"IE": "y",
|
||||||
|
"Edge": "y",
|
||||||
|
"Firefox": "y",
|
||||||
|
"Safari": "y"
|
||||||
|
},
|
||||||
|
"小程序": {
|
||||||
|
"微信": "y",
|
||||||
|
"阿里": "u",
|
||||||
|
"百度": "u",
|
||||||
|
"字节跳动": "u",
|
||||||
|
"QQ": "u",
|
||||||
|
"京东": "u"
|
||||||
|
},
|
||||||
|
"快应用": {
|
||||||
|
"华为": "u",
|
||||||
|
"联盟": "u"
|
||||||
|
},
|
||||||
|
"Vue": {
|
||||||
|
"vue2": "u",
|
||||||
|
"vue3": "y"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"dayjs": "^1.11.7",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
|
"lodash-es": "^4.17.21",
|
||||||
|
"luch-request": "^3.0.8",
|
||||||
|
"pinia": "^2.0.33",
|
||||||
|
"pinia-plugin-persist-uni": "^1.2.0",
|
||||||
|
"weixin-js-sdk": "^1.6.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"prettier": "^2.8.7",
|
||||||
|
"vconsole": "^3.15.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
134
pages.json
Normal file
134
pages.json
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
{
|
||||||
|
"easycom": {
|
||||||
|
"autoscan": true,
|
||||||
|
"custom": {
|
||||||
|
"^s-(.*)": "@/sheep/components/s-$1/s-$1.vue",
|
||||||
|
"^su-(.*)": "@/sheep/ui/su-$1/su-$1.vue"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pages": [{
|
||||||
|
"path": "pages/index/index",
|
||||||
|
"aliasPath": "/",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "首页",
|
||||||
|
"enablePullDownRefresh": true
|
||||||
|
},
|
||||||
|
"meta": {
|
||||||
|
"auth": false,
|
||||||
|
"sync": true,
|
||||||
|
"title": "首页",
|
||||||
|
"group": "商城"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/index/user",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "个人中心",
|
||||||
|
"enablePullDownRefresh": true
|
||||||
|
},
|
||||||
|
"meta": {
|
||||||
|
"sync": true,
|
||||||
|
"title": "个人中心",
|
||||||
|
"group": "商城"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/index/login",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "登录"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"subPackages": [
|
||||||
|
{
|
||||||
|
"root": "pages/user",
|
||||||
|
"pages": [
|
||||||
|
{
|
||||||
|
"path": "info",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "我的信息"
|
||||||
|
},
|
||||||
|
"meta": {
|
||||||
|
"auth": true,
|
||||||
|
"sync": true,
|
||||||
|
"title": "用户信息",
|
||||||
|
"group": "用户中心"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root": "pages/public",
|
||||||
|
"pages": [
|
||||||
|
{
|
||||||
|
"path": "setting",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "系统设置"
|
||||||
|
},
|
||||||
|
"meta": {
|
||||||
|
"sync": true,
|
||||||
|
"title": "系统设置",
|
||||||
|
"group": "通用"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "richtext",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "富文本"
|
||||||
|
},
|
||||||
|
"meta": {
|
||||||
|
"sync": true,
|
||||||
|
"title": "富文本",
|
||||||
|
"group": "通用"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "faq",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "常见问题"
|
||||||
|
},
|
||||||
|
"meta": {
|
||||||
|
"sync": true,
|
||||||
|
"title": "常见问题",
|
||||||
|
"group": "通用"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "error",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "错误页面"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "webview",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"globalStyle": {
|
||||||
|
"navigationBarTextStyle": "black",
|
||||||
|
"navigationBarTitleText": "惠吃宝骑手端",
|
||||||
|
"navigationBarBackgroundColor": "#FFFFFF",
|
||||||
|
"backgroundColor": "#FFFFFF",
|
||||||
|
"navigationStyle": "custom"
|
||||||
|
},
|
||||||
|
"tabBar": {
|
||||||
|
"list": [
|
||||||
|
{
|
||||||
|
"pagePath": "pages/index/index",
|
||||||
|
"iconPath": "static/img/home.png",
|
||||||
|
"selectedIconPath": "static/img/home.png",
|
||||||
|
"text": "首页"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pagePath": "pages/index/user",
|
||||||
|
"iconPath": "static/img/edit.png",
|
||||||
|
"selectedIconPath": "static/img/edit.png",
|
||||||
|
"text": "个人中心"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
26
pages/index/components/first-one.vue
Normal file
26
pages/index/components/first-one.vue
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<!-- 分类展示:first-one 风格 -->
|
||||||
|
<template>
|
||||||
|
<view class="ss-flex-col">
|
||||||
|
<view class="goods-box" v-for="item in pagination.list" :key="item.id">
|
||||||
|
<s-goods-column
|
||||||
|
size="sl"
|
||||||
|
:data="item"
|
||||||
|
@click="sheep.$router.go('/pages/goods/index', { id: item.id })"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
pagination: Object,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.goods-box {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
66
pages/index/components/first-two.vue
Normal file
66
pages/index/components/first-two.vue
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<!-- 分类展示:first-two 风格 -->
|
||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<view class="ss-flex flex-wrap">
|
||||||
|
<view class="goods-box" v-for="item in pagination?.list" :key="item.id">
|
||||||
|
<view @click="sheep.$router.go('/pages/goods/index', { id: item.id })">
|
||||||
|
<view class="goods-img">
|
||||||
|
<image class="goods-img" :src="item.picUrl" mode="aspectFit" />
|
||||||
|
</view>
|
||||||
|
<view class="goods-content">
|
||||||
|
<view class="goods-title ss-line-1 ss-m-b-28">{{ item.name }}</view>
|
||||||
|
<view class="goods-price">¥{{ fen2yuan(item.price) }}</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import { fen2yuan } from '@/sheep/hooks/useGoods';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
pagination: Object,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.goods-box {
|
||||||
|
width: calc((100% - 20rpx) / 2);
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
|
||||||
|
.goods-img {
|
||||||
|
width: 100%;
|
||||||
|
height: 246rpx;
|
||||||
|
border-radius: 10rpx 10rpx 0px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-content {
|
||||||
|
width: 100%;
|
||||||
|
background: #ffffff;
|
||||||
|
box-shadow: 0px 0px 20rpx 4rpx rgba(199, 199, 199, 0.22);
|
||||||
|
padding: 20rpx 0 32rpx 16rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border-radius: 0 0 10rpx 10rpx;
|
||||||
|
|
||||||
|
.goods-title {
|
||||||
|
font-size: 26rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #333333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-price {
|
||||||
|
font-size: 24rpx;
|
||||||
|
font-family: OPPOSANS;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #e1212b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:nth-child(2n + 1) {
|
||||||
|
margin-right: 20rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
97
pages/index/components/second-one.vue
Normal file
97
pages/index/components/second-one.vue
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
<!-- 分类展示:second-one 风格 -->
|
||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<!-- 一级分类的名字 -->
|
||||||
|
<!-- <view class="title-box ss-flex ss-col-center ss-row-center ss-p-b-30">
|
||||||
|
<view class="title-line-left" />
|
||||||
|
<view class="title-text ss-p-x-20">{{ props.data[activeMenu].name }}</view>
|
||||||
|
<view class="title-line-right" />
|
||||||
|
</view> -->
|
||||||
|
<view class="title-box ss-flex ss-p-b-30">
|
||||||
|
<view class="theme-line"></view>
|
||||||
|
<view class="title-text">{{ props.data[activeMenu].name }}</view>
|
||||||
|
</view>
|
||||||
|
<!-- 二级分类的名字 -->
|
||||||
|
<view class="goods-item-box ss-flex ss-flex-wrap ss-p-b-20">
|
||||||
|
<view
|
||||||
|
class="goods-item"
|
||||||
|
v-for="item in props.data[activeMenu].children"
|
||||||
|
:key="item.id"
|
||||||
|
@tap="
|
||||||
|
sheep.$router.go('/pages/goods/list', {
|
||||||
|
categoryId: item.id,
|
||||||
|
})
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<image class="goods-img" :src="item.picUrl" mode="aspectFill" />
|
||||||
|
<view class="ss-p-10">
|
||||||
|
<view class="goods-title ss-line-1">{{ item.name }}</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
data: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({}),
|
||||||
|
},
|
||||||
|
activeMenu: [Number, String],
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.title-box {
|
||||||
|
font-weight: 800;
|
||||||
|
font-size: 32rpx;
|
||||||
|
color: #333333;
|
||||||
|
|
||||||
|
.title-line-left,
|
||||||
|
.title-line-right {
|
||||||
|
width: 15px;
|
||||||
|
height: 1px;
|
||||||
|
background: #d2d2d2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-item {
|
||||||
|
width: calc((100% - 20px) / 3);
|
||||||
|
margin-right: 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
|
||||||
|
&:nth-of-type(3n) {
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-img {
|
||||||
|
width: calc((100vw - 140px) / 3);
|
||||||
|
height: calc((100vw - 140px) / 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-title {
|
||||||
|
font-size: 26rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #333333;
|
||||||
|
line-height: 40rpx;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-price {
|
||||||
|
color: $red;
|
||||||
|
line-height: 40rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-line {
|
||||||
|
margin-right: 15rpx;
|
||||||
|
width: 8rpx;
|
||||||
|
height: 28rpx;
|
||||||
|
background: var(--ui-BG-Main);
|
||||||
|
border-radius: 8rpx 8rpx 8rpx 8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
480
pages/index/index.vue
Normal file
480
pages/index/index.vue
Normal file
@@ -0,0 +1,480 @@
|
|||||||
|
<!-- 接单页:将原首页替换为接单页面(含订单卡片、顶部 tab、底部批量操作栏) -->
|
||||||
|
<template>
|
||||||
|
<view class="receive-page">
|
||||||
|
<!-- 顶部区域:状态 + tabs -->
|
||||||
|
<view class="top-area" :style="headerStyle">
|
||||||
|
<view class="top-bg"></view>
|
||||||
|
<view class="top-inner">
|
||||||
|
<view class="user-info">
|
||||||
|
<image class="user-avatar" :src="driverInfo.avatar || defaultAvatar" mode="cover" />
|
||||||
|
<view class="user-meta">
|
||||||
|
<!-- <text class="user-name">{{ driverInfo.nickName || '骑手姓名' }}</text> -->
|
||||||
|
<text class="user-status" @click="toggleOnline">{{ driverInfo.isOnline ? '在线中' : '离线' }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="tabs">
|
||||||
|
<view :class="['tab', activeTab === 'pickup' ? 'active' : '']" @click="switchTab('pickup')">
|
||||||
|
<text>待取货</text>
|
||||||
|
<text class="count">({{ pickupCount }})</text>
|
||||||
|
</view>
|
||||||
|
<view :class="['tab', activeTab === 'delivering' ? 'active' : '']" @click="switchTab('delivering')">
|
||||||
|
<text>配送中</text>
|
||||||
|
<text class="count">({{ deliveringCount }})</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 订单列表 -->
|
||||||
|
<scroll-view class="order-list" scroll-y="true" :style="{ height: listHeight + 'px' }">
|
||||||
|
<view v-for="order in filteredOrders" :key="order.id" class="order-card">
|
||||||
|
<!-- 头部编号 -->
|
||||||
|
<view class="order-header">
|
||||||
|
<view class="order-badge">{{ order.type === 'pickup' ? '取' : '送' }}</view>
|
||||||
|
<view class="order-title">
|
||||||
|
<text class="shop-name">{{ order.shopName }}</text>
|
||||||
|
<text class="order-id">#{{ order.id }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="order-status">{{ order.statusText }}</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 地址信息 -->
|
||||||
|
<view class="order-info">
|
||||||
|
<view class="address-row">
|
||||||
|
<view class="icon pickup">取</view>
|
||||||
|
<view class="address-content">
|
||||||
|
<text class="address-title">{{ order.pickupAddress }}</text>
|
||||||
|
<text class="address-sub">商家已出餐 · {{ order.pickupNote || '' }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="nav-icon" @click="openMap(order.pickupLat, order.pickupLng, order.pickupAddress)">导航</view>
|
||||||
|
</view>
|
||||||
|
<view class="address-row">
|
||||||
|
<view class="icon deliver">送</view>
|
||||||
|
<view class="address-content">
|
||||||
|
<text class="address-title">{{ order.deliveryAddress }}</text>
|
||||||
|
<text class="address-sub">收货人:{{ order.receiverName }} {{ order.receiverPhone ? ('尾号' + (order.receiverPhone + '').slice(-4)) : ''}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="nav-icon" @click="openMap(order.deliveryLat, order.deliveryLng, order.deliveryAddress)">导航</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 备注 -->
|
||||||
|
<view class="order-note" v-if="order.note">
|
||||||
|
<text>顾客:{{ order.note }}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 操作区 -->
|
||||||
|
<view class="order-actions">
|
||||||
|
<view class="contact" @click="callPhone(order.receiverPhone)">
|
||||||
|
<text>联系</text>
|
||||||
|
</view>
|
||||||
|
<view class="confirm" @click="confirmArrive(order.id)">
|
||||||
|
<text>确认到店</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
|
||||||
|
<!-- 底部批量操作栏 -->
|
||||||
|
<view class="bottom-bar">
|
||||||
|
<view class="batch-item" @click="scanQr">扫一扫取单</view>
|
||||||
|
<view class="batch-item" @click="openManualInput">输入用户单编码</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, computed, onMounted } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
|
||||||
|
// 驿站/骑手信息(从 store 获取或 mock)
|
||||||
|
const driverInfo = ref({
|
||||||
|
isOnline: true,
|
||||||
|
nickName: '骑手张三',
|
||||||
|
avatar: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const defaultAvatar = 'https://huichibao.oss-cn-guangzhou.aliyuncs.com/1/material/348b8223-8d03-46aa-8836-6757e8beebd2.png';
|
||||||
|
|
||||||
|
// 页面状态
|
||||||
|
const activeTab = ref('pickup'); // 'pickup' | 'delivering'
|
||||||
|
const listHeight = ref(600);
|
||||||
|
|
||||||
|
// Mock 订单数据(真实项目应从后端接口拉取 / store)
|
||||||
|
const orders = ref([
|
||||||
|
{
|
||||||
|
id: 1001,
|
||||||
|
type: 'pickup',
|
||||||
|
statusText: '待取货',
|
||||||
|
shopName: '取货点店铺名称',
|
||||||
|
pickupAddress: '广东省广州市天河区学院站荷光路118-121号',
|
||||||
|
pickupLat: 23.1,
|
||||||
|
pickupLng: 113.3,
|
||||||
|
pickupNote: '商家已出餐',
|
||||||
|
deliveryAddress: '广东省广州市天河区华景新城软件园区',
|
||||||
|
deliveryLat: 23.12,
|
||||||
|
deliveryLng: 113.31,
|
||||||
|
receiverName: '张先生',
|
||||||
|
receiverPhone: '13900001234',
|
||||||
|
note: '根据餐量提供餐具'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1002,
|
||||||
|
type: 'pickup',
|
||||||
|
statusText: '待取货',
|
||||||
|
shopName: '乐易购(学院店)',
|
||||||
|
pickupAddress: '广东省广州市天河区学院站荷光路118--121号',
|
||||||
|
pickupLat: 23.11,
|
||||||
|
pickupLng: 113.32,
|
||||||
|
pickupNote: '',
|
||||||
|
deliveryAddress: '广东省广州市天河区某小区',
|
||||||
|
deliveryLat: 23.13,
|
||||||
|
deliveryLng: 113.33,
|
||||||
|
receiverName: '李女士',
|
||||||
|
receiverPhone: '13900005678',
|
||||||
|
note: ''
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 计算各 tab 数量与过滤列表
|
||||||
|
const pickupCount = computed(() => orders.value.filter(o => o.type === 'pickup').length);
|
||||||
|
const deliveringCount = computed(() => orders.value.filter(o => o.type === 'delivering').length);
|
||||||
|
const filteredOrders = computed(() => {
|
||||||
|
if (activeTab.value === 'pickup') {
|
||||||
|
return orders.value.filter(o => o.type === 'pickup');
|
||||||
|
}
|
||||||
|
return orders.value.filter(o => o.type === 'delivering');
|
||||||
|
});
|
||||||
|
|
||||||
|
// 切换 tab
|
||||||
|
function switchTab(tab) {
|
||||||
|
activeTab.value = tab;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 切换上线/下线(简单 UI 切换,建议接入后端)
|
||||||
|
function toggleOnline() {
|
||||||
|
driverInfo.value.isOnline = !driverInfo.value.isOnline;
|
||||||
|
sheep.$helper && sheep.$helper.toast && sheep.$helper.toast(driverInfo.value.isOnline ? '已上线' : '已下线');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确认到店(演示:改变订单状态)
|
||||||
|
function confirmArrive(orderId) {
|
||||||
|
const order = orders.value.find(o => o.id === orderId);
|
||||||
|
if (!order) return;
|
||||||
|
// 示例逻辑:到店后将类型改为 delivering
|
||||||
|
if (order.type === 'pickup') {
|
||||||
|
order.type = 'delivering';
|
||||||
|
order.statusText = '配送中';
|
||||||
|
sheep.$helper && sheep.$helper.toast && sheep.$helper.toast('已确认到店,开始配送');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拨打电话
|
||||||
|
function callPhone(phone) {
|
||||||
|
if (!phone) {
|
||||||
|
sheep.$helper && sheep.$helper.toast && sheep.$helper.toast('未找到联系电话');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uni.makePhoneCall({
|
||||||
|
phoneNumber: phone
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打开地图导航(使用 openLocation 打开经纬度或直接跳转小程序地图)
|
||||||
|
function openMap(lat, lng, name) {
|
||||||
|
if (!lat || !lng) {
|
||||||
|
sheep.$helper && sheep.$helper.toast && sheep.$helper.toast('无法获取坐标');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uni.openLocation({
|
||||||
|
latitude: Number(lat),
|
||||||
|
longitude: Number(lng),
|
||||||
|
name: name || '',
|
||||||
|
scale: 18
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 底部操作(扫码、手动输入)
|
||||||
|
function scanQr() {
|
||||||
|
uni.scanCode({
|
||||||
|
onlyFromCamera: false,
|
||||||
|
success(res) {
|
||||||
|
const code = res.result || res.path || '';
|
||||||
|
sheep.$helper && sheep.$helper.toast && sheep.$helper.toast('已识别:' + code);
|
||||||
|
},
|
||||||
|
fail() {
|
||||||
|
sheep.$helper && sheep.$helper.toast && sheep.$helper.toast('扫码失败');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function openManualInput() {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pages/index/user' // 示例跳转,按需替换为真实手动输入页面
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 入口:计算列表高度适配底部栏
|
||||||
|
onMounted(() => {
|
||||||
|
try {
|
||||||
|
const sys = uni.getSystemInfoSync();
|
||||||
|
const windowHeight = sys.windowHeight || 667;
|
||||||
|
// 留出顶部和底部空间
|
||||||
|
listHeight.value = windowHeight - 200;
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 顶部安全区处理:参考 pages/index/user.vue 的实现
|
||||||
|
import { onShow } from '@dcloudio/uni-app';
|
||||||
|
|
||||||
|
const headerStyle = ref({});
|
||||||
|
|
||||||
|
function setHeaderSafeArea() {
|
||||||
|
try {
|
||||||
|
const sys = uni.getSystemInfoSync();
|
||||||
|
const statusBarHeightPx = sys?.statusBarHeight || 0;
|
||||||
|
const windowWidth = sys?.windowWidth || 375;
|
||||||
|
// 将 px 转为 rpx: rpx = px / windowWidth * 750
|
||||||
|
const statusBarHeightRpx = Math.round((statusBarHeightPx / windowWidth) * 750);
|
||||||
|
headerStyle.value = {
|
||||||
|
paddingTop: statusBarHeightPx + 'px',
|
||||||
|
'--statusbar': statusBarHeightRpx + 'rpx'
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
setHeaderSafeArea();
|
||||||
|
// 计算列表高度适配底部栏
|
||||||
|
try {
|
||||||
|
const sys = uni.getSystemInfoSync();
|
||||||
|
const windowHeight = sys.windowHeight || 667;
|
||||||
|
// 留出顶部和底部空间
|
||||||
|
listHeight.value = windowHeight - 200;
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
onShow(() => {
|
||||||
|
// 每次页面显示时重新计算(兼容热更或状态变化)
|
||||||
|
setHeaderSafeArea();
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.receive-page {
|
||||||
|
background: #fff;
|
||||||
|
min-height: 100vh;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-area {
|
||||||
|
position: relative;
|
||||||
|
/* 兼容刘海屏安全区处理 */
|
||||||
|
padding-top: constant(safe-area-inset-top);
|
||||||
|
padding-top: env(safe-area-inset-top);
|
||||||
|
height: 220rpx;
|
||||||
|
}
|
||||||
|
.top-bg {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
/* 背景高度需要包含安全区高度 */
|
||||||
|
height: 270rpx;
|
||||||
|
height: calc(270rpx + constant(safe-area-inset-top));
|
||||||
|
height: calc(270rpx + env(safe-area-inset-top));
|
||||||
|
height: calc(270rpx + var(--statusbar, 0rpx));
|
||||||
|
background: #c292ee;
|
||||||
|
border-bottom-left-radius: 12rpx;
|
||||||
|
border-bottom-right-radius: 12rpx;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
.top-inner {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
top: calc(var(--statusbar, 0rpx) + 30rpx);
|
||||||
|
z-index: 1;
|
||||||
|
padding: 0 30rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.user-info {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.user-avatar {
|
||||||
|
width: 110rpx;
|
||||||
|
height: 110rpx;
|
||||||
|
border-radius: 55rpx;
|
||||||
|
border: 4rpx solid rgba(255,255,255,0.6);
|
||||||
|
}
|
||||||
|
.user-meta {
|
||||||
|
margin-left: 20rpx;
|
||||||
|
}
|
||||||
|
.user-name {
|
||||||
|
font-size: 32rpx;
|
||||||
|
color: #fff;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
.user-status {
|
||||||
|
margin-top: 8rpx;
|
||||||
|
color: rgba(255,255,255,0.9);
|
||||||
|
font-size: 26rpx;
|
||||||
|
}
|
||||||
|
.tabs {
|
||||||
|
margin-top: 18rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
gap: 20rpx;
|
||||||
|
}
|
||||||
|
.tab {
|
||||||
|
padding: 10rpx 20rpx;
|
||||||
|
background: rgba(255,255,255,0.12);
|
||||||
|
border-radius: 40rpx;
|
||||||
|
color: #fff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.tab.active {
|
||||||
|
background: #fff;
|
||||||
|
color: #6b3aa6;
|
||||||
|
}
|
||||||
|
.tab .count {
|
||||||
|
margin-left: 8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-list {
|
||||||
|
padding: 20rpx;
|
||||||
|
padding-right: 20rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
background: #f7f7f7;
|
||||||
|
}
|
||||||
|
.order-card {
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 12rpx;
|
||||||
|
padding: 20rpx;
|
||||||
|
margin-bottom: 18rpx;
|
||||||
|
box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
|
||||||
|
overflow: hidden;
|
||||||
|
box-sizing: border-box;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
.order-header {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 12rpx;
|
||||||
|
}
|
||||||
|
.order-badge {
|
||||||
|
width: 54rpx;
|
||||||
|
height: 54rpx;
|
||||||
|
border-radius: 27rpx;
|
||||||
|
background: #e6f7ff;
|
||||||
|
color: #1890ff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
.order-title {
|
||||||
|
flex: 1;
|
||||||
|
margin-left: 12rpx;
|
||||||
|
}
|
||||||
|
.shop-name {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
.order-id {
|
||||||
|
color: #999;
|
||||||
|
margin-left: 8rpx;
|
||||||
|
}
|
||||||
|
.order-status {
|
||||||
|
color: #ff7a45;
|
||||||
|
}
|
||||||
|
.order-info {
|
||||||
|
margin-top: 8rpx;
|
||||||
|
}
|
||||||
|
.address-row {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
margin-top: 10rpx;
|
||||||
|
}
|
||||||
|
.icon {
|
||||||
|
width: 38rpx;
|
||||||
|
height: 38rpx;
|
||||||
|
border-radius: 19rpx;
|
||||||
|
background: #f2f2f2;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
margin-right: 10rpx;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
.icon.pickup { background: #87d6ff; color: #fff; }
|
||||||
|
.icon.deliver { background: #ffd591; color: #fff; }
|
||||||
|
.address-content { flex: 1; min-width: 0; }
|
||||||
|
.address-title {
|
||||||
|
display: block;
|
||||||
|
font-size: 26rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
/* 支持长地址换行,防止撑开布局 */
|
||||||
|
white-space: normal;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
.address-sub { display: block; font-size: 22rpx; color: #888; margin-top: 6rpx; }
|
||||||
|
.nav-icon { color: #1e9fff; padding: 6rpx 10rpx; }
|
||||||
|
.order-note { background: #f6f6f6; padding: 12rpx; border-radius: 8rpx; margin-top: 12rpx; color: #666; }
|
||||||
|
.order-actions {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
margin-top: 12rpx;
|
||||||
|
gap: 12rpx;
|
||||||
|
}
|
||||||
|
.contact {
|
||||||
|
flex: 1;
|
||||||
|
background: #fff;
|
||||||
|
border: 1rpx solid #ddd;
|
||||||
|
padding: 14rpx;
|
||||||
|
text-align: center;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
.confirm {
|
||||||
|
flex: 2;
|
||||||
|
background: #1e9fff;
|
||||||
|
padding: 14rpx;
|
||||||
|
text-align: center;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.bottom-bar {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 110rpx;
|
||||||
|
background: rgba(255,255,255,0.98);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-around;
|
||||||
|
align-items: center;
|
||||||
|
border-top: 1rpx solid #eee;
|
||||||
|
}
|
||||||
|
.batch-item {
|
||||||
|
background: #fff;
|
||||||
|
padding: 14rpx 20rpx;
|
||||||
|
border-radius: 40rpx;
|
||||||
|
border: 1rpx solid #ddd;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
39
pages/index/login.vue
Normal file
39
pages/index/login.vue
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<!-- 微信公众号的登录回调页 -->
|
||||||
|
<template>
|
||||||
|
<!-- 空登陆页 -->
|
||||||
|
<view />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import { onLoad } from '@dcloudio/uni-app';
|
||||||
|
|
||||||
|
onLoad(async (options) => {
|
||||||
|
// #ifdef H5
|
||||||
|
// 将 search 参数赋值到 options 中,方便下面解析
|
||||||
|
new URLSearchParams(location.search).forEach((value, key) => {
|
||||||
|
options[key] = value;
|
||||||
|
});
|
||||||
|
// 执行登录 or 绑定,注意需要 await 绑定
|
||||||
|
const event = options.event;
|
||||||
|
const code = options.code;
|
||||||
|
const state = options.state;
|
||||||
|
if (event === 'login') { // 场景一:登录
|
||||||
|
await sheep.$platform.useProvider().login(code, state);
|
||||||
|
} else if (event === 'bind') { // 场景二:绑定
|
||||||
|
await sheep.$platform.useProvider().bind(code, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测 H5 登录回调
|
||||||
|
let returnUrl = uni.getStorageSync('returnUrl');
|
||||||
|
if (returnUrl) {
|
||||||
|
uni.removeStorage({key:'returnUrl'});
|
||||||
|
location.replace(returnUrl);
|
||||||
|
} else {
|
||||||
|
uni.switchTab({
|
||||||
|
url: '/',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
});
|
||||||
|
</script>
|
||||||
463
pages/index/user.vue
Normal file
463
pages/index/user.vue
Normal file
@@ -0,0 +1,463 @@
|
|||||||
|
<template>
|
||||||
|
<view class="page">
|
||||||
|
<!-- header -->
|
||||||
|
<view class="header-wrap" :style="headerStyle">
|
||||||
|
<view class="header-bg"></view>
|
||||||
|
<view class="header-inner">
|
||||||
|
<image class="avatar" :src="user.avatar || defautAvatar"></image>
|
||||||
|
<view class="user-meta">
|
||||||
|
<view class="user-name">{{ user.nickName || '姓名(账号)' }}</view>
|
||||||
|
<view class="user-status" @click="handleStatusToggle">
|
||||||
|
{{ user.isOnline ? '在线' : '离线' }}<uni-icons style="margin-left:10rpx;" type="right" size="13" color="#fff"></uni-icons>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- stats card -->
|
||||||
|
<view class="stats-card">
|
||||||
|
<view class="stats-row">
|
||||||
|
<view class="stats-item">
|
||||||
|
<text class="stats-title">今日预计收入(元)</text>
|
||||||
|
<text class="stats-value"> {{ formatMoney(todayIncome) }} </text>
|
||||||
|
<view class="stats-link" @click="openAccount">
|
||||||
|
我的账户 <uni-icons type="right" size="13"></uni-icons>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="stats-item">
|
||||||
|
<text class="stats-title">今日完成单量(单)</text>
|
||||||
|
<text class="stats-value"> {{ todayOrders }} </text>
|
||||||
|
<view class="stats-link" @click="openOrders">
|
||||||
|
订单统计 <uni-icons type="right" size="13"></uni-icons>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- shortcuts -->
|
||||||
|
<view class="shortcuts">
|
||||||
|
<view class="shortcut" @click="openAttendance">
|
||||||
|
<image class="shortcut-icon" src="/static/img/order1.png" mode="aspectFit" />
|
||||||
|
<text class="shortcut-text">考勤排班</text>
|
||||||
|
</view>
|
||||||
|
<view class="shortcut" @click="openSalary">
|
||||||
|
<image class="shortcut-icon" src="/static/img/order2.png" mode="aspectFit" />
|
||||||
|
<text class="shortcut-text">薪资助手</text>
|
||||||
|
</view>
|
||||||
|
<view class="shortcut" @click="openSetting">
|
||||||
|
<!-- <image class="shortcut-icon" src="/static/img/edit.png" mode="aspectFit" /> -->
|
||||||
|
<view class="shortcut-icon">
|
||||||
|
<uni-icons type="gear" size="43"></uni-icons>
|
||||||
|
</view>
|
||||||
|
<text class="shortcut-text">设置</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<s-auth-modal />
|
||||||
|
|
||||||
|
<su-popup type="center" :show="showStatusPopup" round="14" :showClose="false">
|
||||||
|
<view class="modal-box">
|
||||||
|
<view class="modal-body">
|
||||||
|
<text class="modal-title">{{ modalTitle }}</text>
|
||||||
|
<text v-if="modalMsg" class="modal-msg">{{ modalMsg }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="modal-footer">
|
||||||
|
<view class="modal-btn cancel" @click="cancelConfirm">取消</view>
|
||||||
|
<view class="modal-btn confirm" @click="confirmAction">确认</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</su-popup>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import {
|
||||||
|
computed,
|
||||||
|
ref
|
||||||
|
} from 'vue';
|
||||||
|
import {
|
||||||
|
onShow,
|
||||||
|
onPageScroll,
|
||||||
|
onPullDownRefresh
|
||||||
|
} from '@dcloudio/uni-app';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
|
||||||
|
// 现有 store / 模板数据
|
||||||
|
const template = computed(() => sheep.$store('app').template.user);
|
||||||
|
const isLogin = computed(() => sheep.$store('user').isLogin);
|
||||||
|
|
||||||
|
const user = ref({});
|
||||||
|
const todayIncome = ref(0);
|
||||||
|
const todayOrders = ref(0);
|
||||||
|
const showBind = ref(false);
|
||||||
|
// 动态 header 内联样式,用于兼容不同平台的状态栏高度
|
||||||
|
const headerStyle = ref({});
|
||||||
|
const defautAvatar =
|
||||||
|
'https://huichibao.oss-cn-guangzhou.aliyuncs.com/1/material/348b8223-8d03-46aa-8836-6757e8beebd2.png';
|
||||||
|
|
||||||
|
// 格式化金额显示
|
||||||
|
function formatMoney(val) {
|
||||||
|
if (val == null) return '0';
|
||||||
|
return (Number(val) || 0).toFixed(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 微信小程序的“手机号快速验证”
|
||||||
|
const getPhoneNumber = async (e) => {
|
||||||
|
if (e.detail.errMsg !== 'getPhoneNumber:ok') {
|
||||||
|
sheep.$helper.toast('快捷登录失败');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let result = await sheep.$platform.useProvider().mobileLogin(e.detail);
|
||||||
|
if (result) {
|
||||||
|
showBind.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 页面显示时拉取用户信息并填充统计数据(从 store 获取或使用占位)
|
||||||
|
onShow(async () => {
|
||||||
|
const data = await sheep.$store('user').getInfo();
|
||||||
|
if (data) {
|
||||||
|
user.value = data;
|
||||||
|
// 兼容后端字段名,优先使用 data.todayIncome / data.income / placeholder
|
||||||
|
todayIncome.value = data.todayIncome ?? data.income ?? 137.9;
|
||||||
|
todayOrders.value = data.todayOrders ?? data.orders ?? 39;
|
||||||
|
if (data?.status == 1) {
|
||||||
|
console.log("清空缓存");
|
||||||
|
uni.clearStorageSync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 兼容处理:读取原生状态栏高度并设置 header 的 padding-top(px)与 CSS 变量 --statusbar(rpx)
|
||||||
|
try {
|
||||||
|
const sys = uni.getSystemInfoSync();
|
||||||
|
const statusBarHeightPx = sys?.statusBarHeight || 0;
|
||||||
|
const windowWidth = sys?.windowWidth || 375;
|
||||||
|
// 将 px 转为 rpx: rpx = px / windowWidth * 750
|
||||||
|
const statusBarHeightRpx = Math.round((statusBarHeightPx / windowWidth) * 750);
|
||||||
|
headerStyle.value = {
|
||||||
|
paddingTop: statusBarHeightPx + 'px',
|
||||||
|
'--statusbar': statusBarHeightRpx + 'rpx'
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 确认弹框状态(上线/下线/禁止)
|
||||||
|
const showStatusPopup = ref(false);
|
||||||
|
const confirmType = ref(''); // 'online' | 'offline' | 'forbidden'
|
||||||
|
const modalTitle = ref('');
|
||||||
|
const modalMsg = ref('');
|
||||||
|
|
||||||
|
// 判断用户是否被禁止接单(兼容多种字段)
|
||||||
|
function isUserForbidden() {
|
||||||
|
const u = user.value || {};
|
||||||
|
return !!(u.forbidden || u.isForbidden || u.forbid || u.forbidReceive || u.disableReceive || u.receive === false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 点击状态:根据当前状态弹不同的确认框
|
||||||
|
function handleStatusToggle() {
|
||||||
|
if (user.value.isOnline) {
|
||||||
|
confirmType.value = 'offline';
|
||||||
|
modalTitle.value = '确认下线?';
|
||||||
|
modalMsg.value = '下线需平台进行核准\n此时正常接单请留意核准信息';
|
||||||
|
showStatusPopup.value = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 如果被禁止接单
|
||||||
|
if (isUserForbidden()) {
|
||||||
|
confirmType.value = 'forbidden';
|
||||||
|
modalTitle.value = '您处于禁止接单状态';
|
||||||
|
modalMsg.value = '暂无法上线上线';
|
||||||
|
showStatusPopup.value = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 普通从离线 -> 上线
|
||||||
|
confirmType.value = 'online';
|
||||||
|
modalTitle.value = '确认上线?';
|
||||||
|
modalMsg.value = '';
|
||||||
|
showStatusPopup.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelConfirm() {
|
||||||
|
showStatusPopup.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function confirmAction() {
|
||||||
|
const type = confirmType.value;
|
||||||
|
showStatusPopup.value = false;
|
||||||
|
if (type === 'online') {
|
||||||
|
// TODO: 调用后端接口变更上线状态
|
||||||
|
user.value.isOnline = true;
|
||||||
|
sheep.$helper && sheep.$helper.toast && sheep.$helper.toast('已上线');
|
||||||
|
} else if (type === 'offline') {
|
||||||
|
user.value.isOnline = false;
|
||||||
|
sheep.$helper && sheep.$helper.toast && sheep.$helper.toast('已下线');
|
||||||
|
} else if (type === 'forbidden') {
|
||||||
|
// 仅展示信息,无操作
|
||||||
|
sheep.$helper && sheep.$helper.toast && sheep.$helper.toast('无法上线(禁止接单)');
|
||||||
|
}
|
||||||
|
// 可在此处调用 store 或 API 同步服务端状态,例如:
|
||||||
|
// await sheep.$store('user').setOnline(user.value.isOnline);
|
||||||
|
}
|
||||||
|
|
||||||
|
onPullDownRefresh(() => {
|
||||||
|
sheep.$store('user').updateUserData();
|
||||||
|
setTimeout(function() {
|
||||||
|
uni.stopPullDownRefresh();
|
||||||
|
}, 800);
|
||||||
|
});
|
||||||
|
|
||||||
|
onPageScroll(() => {});
|
||||||
|
|
||||||
|
// 跳转/交互方法(保留路由调用位置,用户可按需实现)
|
||||||
|
function goBack() {
|
||||||
|
uni.navigateBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
function openAccount() {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pages/public/webview?type=account'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function openOrders() {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pages/index/order-list'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function openAttendance() {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pages/public/faq'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function openSalary() {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pages/public/richtext'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function openSetting() {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pages/public/setting'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.page {
|
||||||
|
background: #ffffff;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* header */
|
||||||
|
.header-wrap {
|
||||||
|
position: relative;
|
||||||
|
/* 适配刘海屏安全区:优先使用 constant/env,兼容小程序与 iOS/Android 安全区 */
|
||||||
|
padding-top: constant(safe-area-inset-top);
|
||||||
|
padding-top: env(safe-area-inset-top);
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-bg {
|
||||||
|
/* 背景放置为绝对定位以覆盖安全区(兼容 env/constant 回退与 JS 动态 --statusbar) */
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
/* 背景高度需要包含安全区高度,优先使用 env/constant;最后一行为回退值 */
|
||||||
|
height: 250rpx;
|
||||||
|
height: calc(250rpx + constant(safe-area-inset-top));
|
||||||
|
height: calc(250rpx + env(safe-area-inset-top));
|
||||||
|
/* JS 动态变量回退(当 env/constant 不可用时,使用 --statusbar,单位 rpx) */
|
||||||
|
height: calc(250rpx + var(--statusbar, 0rpx));
|
||||||
|
background: #9ad6f0;
|
||||||
|
/* 浅蓝 */
|
||||||
|
border-bottom-left-radius: 24rpx;
|
||||||
|
border-bottom-right-radius: 24rpx;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-inner {
|
||||||
|
position: absolute;
|
||||||
|
left: 32rpx;
|
||||||
|
/* 使用 CSS 变量保证当我们通过 JS 设置 --statusbar 时,内容会相对下移(单位 rpx) */
|
||||||
|
top: calc(var(--statusbar, 0rpx) + 40rpx);
|
||||||
|
z-index: 1;
|
||||||
|
flex-direction: row;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar {
|
||||||
|
width: 120rpx;
|
||||||
|
height: 120rpx;
|
||||||
|
border-radius: 60rpx;
|
||||||
|
border: 4rpx solid rgba(255, 255, 255, 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-meta {
|
||||||
|
margin-left: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-name {
|
||||||
|
font-size: 30rpx;
|
||||||
|
color: #fff;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-status {
|
||||||
|
margin-top: 8rpx;
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: rgba(255, 255, 255, 0.9);
|
||||||
|
}
|
||||||
|
|
||||||
|
.back {
|
||||||
|
position: absolute;
|
||||||
|
left: 18rpx;
|
||||||
|
top: calc(var(--statusbar, 0rpx) + 12rpx);
|
||||||
|
z-index: 2;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 36rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* stats card */
|
||||||
|
.stats-card {
|
||||||
|
padding: 0 24rpx;
|
||||||
|
margin-top: 190rpx;
|
||||||
|
position: relative;
|
||||||
|
z-index: 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-row {
|
||||||
|
background: #f6c98b;
|
||||||
|
/* 浅橙色 */
|
||||||
|
border-radius: 20rpx;
|
||||||
|
padding: 30rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-item {
|
||||||
|
width: 48%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-title {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #5b4a32;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-value {
|
||||||
|
display: block;
|
||||||
|
margin-top: 12rpx;
|
||||||
|
font-size: 42rpx;
|
||||||
|
color: #222;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-link {
|
||||||
|
display: block;
|
||||||
|
margin-top: 12rpx;
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #7a5a3a;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* shortcuts */
|
||||||
|
.shortcuts {
|
||||||
|
margin-top: 30rpx;
|
||||||
|
padding: 30rpx 40rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
position: relative;
|
||||||
|
z-index: 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shortcut {
|
||||||
|
flex: 1;
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shortcut-icon {
|
||||||
|
width: 80rpx;
|
||||||
|
height: 80rpx;
|
||||||
|
margin-bottom: 12rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shortcut-text {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* popup 原有样式 */
|
||||||
|
.popup {
|
||||||
|
padding: 80rpx 0 50rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tip-text {
|
||||||
|
margin-bottom: 30rpx;
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #999999;
|
||||||
|
line-height: 44rpx;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bind-btn {
|
||||||
|
width: 630rpx;
|
||||||
|
height: 96rpx;
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #FFFFFF;
|
||||||
|
line-height: 96rpx;
|
||||||
|
text-align: center;
|
||||||
|
font-style: normal;
|
||||||
|
background: #00B85B;
|
||||||
|
border-radius: 64rpx 64rpx 64rpx 64rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 确认弹框样式(su-popup 内部内容) */
|
||||||
|
.modal-box {
|
||||||
|
width: 640rpx;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 14rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.modal-body {
|
||||||
|
padding: 40rpx 30rpx;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.modal-title {
|
||||||
|
display: block;
|
||||||
|
font-size: 30rpx;
|
||||||
|
color: #333;
|
||||||
|
margin-bottom: 10rpx;
|
||||||
|
}
|
||||||
|
.modal-msg {
|
||||||
|
display: block;
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #999;
|
||||||
|
line-height: 34rpx;
|
||||||
|
white-space: pre-line;
|
||||||
|
}
|
||||||
|
.modal-footer {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
border-top: 1rpx solid #eee;
|
||||||
|
}
|
||||||
|
.modal-btn {
|
||||||
|
flex: 1;
|
||||||
|
padding: 26rpx 0;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 28rpx;
|
||||||
|
}
|
||||||
|
.modal-btn.cancel {
|
||||||
|
color: #666;
|
||||||
|
border-right: 1rpx solid #eee;
|
||||||
|
}
|
||||||
|
.modal-btn.confirm {
|
||||||
|
color: #1e9fff;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
60
pages/public/error.vue
Normal file
60
pages/public/error.vue
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<!-- 错误界面 -->
|
||||||
|
<template>
|
||||||
|
<view class="error-page">
|
||||||
|
<s-empty
|
||||||
|
v-if="errCode === 'NetworkError'"
|
||||||
|
icon="/static/internet-empty.png"
|
||||||
|
text="网络连接失败"
|
||||||
|
showAction
|
||||||
|
actionText="重新连接"
|
||||||
|
@clickAction="onReconnect"
|
||||||
|
buttonColor="#ff3000"
|
||||||
|
/>
|
||||||
|
<s-empty
|
||||||
|
v-else-if="errCode === 'TemplateError'"
|
||||||
|
icon="/static/internet-empty.png"
|
||||||
|
text="未找到模板"
|
||||||
|
showAction
|
||||||
|
actionText="重新加载"
|
||||||
|
@clickAction="onReconnect"
|
||||||
|
buttonColor="#ff3000"
|
||||||
|
/>
|
||||||
|
<s-empty
|
||||||
|
v-else-if="errCode !== ''"
|
||||||
|
icon="/static/internet-empty.png"
|
||||||
|
:text="errMsg"
|
||||||
|
showAction
|
||||||
|
actionText="重新加载"
|
||||||
|
@clickAction="onReconnect"
|
||||||
|
buttonColor="#ff3000"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { onLoad } from '@dcloudio/uni-app';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { ShoproInit } from '@/sheep';
|
||||||
|
|
||||||
|
const errCode = ref('');
|
||||||
|
const errMsg = ref('');
|
||||||
|
|
||||||
|
onLoad((options) => {
|
||||||
|
errCode.value = options.errCode;
|
||||||
|
errMsg.value = options.errMsg;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 重新连接
|
||||||
|
async function onReconnect() {
|
||||||
|
uni.reLaunch({
|
||||||
|
url: '/pages/index/index',
|
||||||
|
});
|
||||||
|
await ShoproInit();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.error-page {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
118
pages/public/faq.vue
Normal file
118
pages/public/faq.vue
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<!-- FAQ 常见问题 -->
|
||||||
|
<template>
|
||||||
|
<s-layout class="set-wrap" title="常见问题" :bgStyle="{ color: '#FFF' }">
|
||||||
|
<uni-collapse>
|
||||||
|
<uni-collapse-item v-for="(item, index) in state.list" :key="item">
|
||||||
|
<template v-slot:title>
|
||||||
|
<view class="ss-flex ss-col-center header">
|
||||||
|
<view class="ss-m-l-20 ss-m-r-20 icon">
|
||||||
|
<view class="rectangle">
|
||||||
|
<view class="num ss-flex ss-row-center ss-col-center">
|
||||||
|
{{ index + 1 < 10 ? '0' + (index + 1) : index + 1 }}
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="triangle"> </view>
|
||||||
|
</view>
|
||||||
|
<view class="title ss-m-t-36 ss-m-b-36">
|
||||||
|
{{ item.title }}
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
<view class="content ss-p-l-78 ss-p-r-40 ss-p-b-50 ss-p-t-20">
|
||||||
|
<text class="text">{{ item.content }}</text>
|
||||||
|
</view>
|
||||||
|
</uni-collapse-item>
|
||||||
|
</uni-collapse>
|
||||||
|
<s-empty
|
||||||
|
v-if="state.list.length === 0 && !state.loading"
|
||||||
|
text="暂无常见问题"
|
||||||
|
icon="/static/collect-empty.png"
|
||||||
|
/>
|
||||||
|
</s-layout>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { onLoad } from '@dcloudio/uni-app';
|
||||||
|
import { reactive } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
|
||||||
|
const state = reactive({
|
||||||
|
list: [],
|
||||||
|
loading: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
async function getFaqList() {
|
||||||
|
const { error, data } = await sheep.$api.data.faq();
|
||||||
|
if (error === 0) {
|
||||||
|
state.list = data;
|
||||||
|
state.loading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onLoad(() => {
|
||||||
|
// TODO 芋艿:【文章】目前简单做,使用营销文章,作为 faq
|
||||||
|
if (true) {
|
||||||
|
sheep.$router.go('/pages/public/richtext', {
|
||||||
|
title: '常见问题',
|
||||||
|
})
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
getFaqList();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.header {
|
||||||
|
.title {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #333333;
|
||||||
|
line-height: 30rpx;
|
||||||
|
max-width: 688rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
position: relative;
|
||||||
|
width: 40rpx;
|
||||||
|
height: 40rpx;
|
||||||
|
|
||||||
|
.rectangle {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
width: 40rpx;
|
||||||
|
height: 36rpx;
|
||||||
|
background: var(--ui-BG-Main);
|
||||||
|
border-radius: 4px;
|
||||||
|
|
||||||
|
.num {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
font-size: 24rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--ui-BG);
|
||||||
|
line-height: 32rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.triangle {
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
border-left: 4rpx solid transparent;
|
||||||
|
border-right: 4rpx solid transparent;
|
||||||
|
border-top: 8rpx solid var(--ui-BG-Main);
|
||||||
|
position: absolute;
|
||||||
|
left: 16rpx;
|
||||||
|
bottom: -4rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
border-bottom: 1rpx solid #dfdfdf;
|
||||||
|
|
||||||
|
.text {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #666666;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
54
pages/public/richtext.vue
Normal file
54
pages/public/richtext.vue
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<!-- 文章展示 -->
|
||||||
|
<template>
|
||||||
|
<s-layout class="set-wrap" :title="state.title" :bgStyle="{ color: '#FFF' }">
|
||||||
|
<view class="ss-p-30">
|
||||||
|
<mp-html class="richtext" :content="state.content" />
|
||||||
|
</view>
|
||||||
|
</s-layout>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { onLoad } from '@dcloudio/uni-app';
|
||||||
|
import { reactive } from 'vue';
|
||||||
|
import ArticleApi from '@/sheep/api/promotion/article';
|
||||||
|
|
||||||
|
const state = reactive({
|
||||||
|
title: '',
|
||||||
|
content: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
async function getRichTextContent(id, title) {
|
||||||
|
const { code, data } = await ArticleApi.getArticle(id, title);
|
||||||
|
if (code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state.content = data.content;
|
||||||
|
// 标题不一致时,修改标题
|
||||||
|
if (state.title !== data.title) {
|
||||||
|
state.title = data.title;
|
||||||
|
uni.setNavigationBarTitle({
|
||||||
|
title: state.title,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onLoad((options) => {
|
||||||
|
if (options.title) {
|
||||||
|
state.title = options.title;
|
||||||
|
uni.setNavigationBarTitle({
|
||||||
|
title: state.title,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
getRichTextContent(options.id, options.title);
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.set-title {
|
||||||
|
margin: 0 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.richtext {
|
||||||
|
}
|
||||||
|
</style>
|
||||||
242
pages/public/setting.vue
Normal file
242
pages/public/setting.vue
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
<template>
|
||||||
|
<s-layout class="set-wrap" title="系统设置" :bgStyle="{ color: '#fff' }">
|
||||||
|
<view class="header-box ss-flex-col ss-row-center ss-col-center">
|
||||||
|
<image
|
||||||
|
class="logo-img ss-m-b-46"
|
||||||
|
:src="sheep.$url.cdn(appInfo.logo)"
|
||||||
|
mode="aspectFit"
|
||||||
|
></image>
|
||||||
|
<view class="name ss-m-b-24">{{ appInfo.name }}</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="container-list">
|
||||||
|
<uni-list :border="false">
|
||||||
|
<!-- <uni-list-item
|
||||||
|
title="当前版本"
|
||||||
|
:rightText="appInfo.version"
|
||||||
|
showArrow
|
||||||
|
clickable
|
||||||
|
:border="false"
|
||||||
|
class="list-border"
|
||||||
|
@tap="onCheckUpdate"
|
||||||
|
/>
|
||||||
|
<uni-list-item
|
||||||
|
title="本地缓存"
|
||||||
|
:rightText="storageSize"
|
||||||
|
showArrow
|
||||||
|
:border="false"
|
||||||
|
class="list-border"
|
||||||
|
/>
|
||||||
|
<uni-list-item
|
||||||
|
title="关于我们"
|
||||||
|
showArrow
|
||||||
|
clickable
|
||||||
|
:border="false"
|
||||||
|
class="list-border"
|
||||||
|
@tap="
|
||||||
|
sheep.$router.go('/pages/public/richtext', {
|
||||||
|
title: '关于我们'
|
||||||
|
})
|
||||||
|
"
|
||||||
|
/> -->
|
||||||
|
<!-- 为了过审 只有 iOS-App 有注销账号功能 -->
|
||||||
|
<uni-list-item
|
||||||
|
v-if="isLogin && sheep.$platform.os === 'ios' && sheep.$platform.name === 'App'"
|
||||||
|
title="注销账号"
|
||||||
|
rightText=""
|
||||||
|
showArrow
|
||||||
|
clickable
|
||||||
|
:border="false"
|
||||||
|
class="list-border"
|
||||||
|
@click="onLogoff"
|
||||||
|
/>
|
||||||
|
</uni-list>
|
||||||
|
</view>
|
||||||
|
<view class="set-footer ss-flex-col ss-row-center ss-col-center">
|
||||||
|
<view class="agreement-box ss-flex ss-col-center ss-m-b-40">
|
||||||
|
<view class="ss-flex ss-col-center ss-m-b-10">
|
||||||
|
<!-- <view
|
||||||
|
class="tcp-text"
|
||||||
|
@tap="
|
||||||
|
sheep.$router.go('/pages/public/richtext', {
|
||||||
|
title: '用户协议'
|
||||||
|
})
|
||||||
|
"
|
||||||
|
>
|
||||||
|
《用户协议》
|
||||||
|
</view>
|
||||||
|
<view class="agreement-text">与</view> -->
|
||||||
|
<view
|
||||||
|
class="tcp-text"
|
||||||
|
@tap="
|
||||||
|
sheep.$router.go('/pages/public/richtext', {
|
||||||
|
title: '隐私协议'
|
||||||
|
})
|
||||||
|
"
|
||||||
|
>
|
||||||
|
《隐私协议》
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<!-- <view class="copyright-text ss-m-b-10">{{ appInfo.copyright }}</view> -->
|
||||||
|
<!-- <view class="copyright-text">{{ appInfo.copytime }}</view> -->
|
||||||
|
</view>
|
||||||
|
<su-fixed bottom placeholder>
|
||||||
|
<view class="ss-p-x-20 ss-p-b-40">
|
||||||
|
<button
|
||||||
|
class="loginout-btn ss-reset-button ui-BG-Main ui-Shadow-Main"
|
||||||
|
@tap="onLogout"
|
||||||
|
v-if="isLogin"
|
||||||
|
>
|
||||||
|
退出登录
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
</su-fixed>
|
||||||
|
</s-layout>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import { computed, reactive } from 'vue';
|
||||||
|
import AuthUtil from '@/sheep/api/member/auth';
|
||||||
|
|
||||||
|
const appInfo = computed(() => sheep.$store('app').info);
|
||||||
|
const isLogin = computed(() => sheep.$store('user').isLogin);
|
||||||
|
const storageSize = uni.getStorageInfoSync().currentSize + 'Kb';
|
||||||
|
const state = reactive({
|
||||||
|
showModal: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
function onCheckUpdate() {
|
||||||
|
sheep.$platform.checkUpdate();
|
||||||
|
// 小程序初始化时已检查更新
|
||||||
|
// H5实时更新无需检查
|
||||||
|
// App 1.跳转应用市场更新 2.手动热更新 3.整包更新
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注销账号
|
||||||
|
function onLogoff() {
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '确认注销账号?',
|
||||||
|
success: async function (res) {
|
||||||
|
if (!res.confirm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { code } = await AuthUtil.logout();
|
||||||
|
if (code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sheep.$store('user').logout();
|
||||||
|
sheep.$router.go('/pages/index/user');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 退出账号
|
||||||
|
function onLogout() {
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '确认退出账号?',
|
||||||
|
success: async function (res) {
|
||||||
|
if (!res.confirm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { code } = await AuthUtil.logout();
|
||||||
|
if (code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
uni.clearStorageSync();
|
||||||
|
console.log('缓存清空成功');
|
||||||
|
} catch (e) {
|
||||||
|
console.log('缓存清空失败', e);
|
||||||
|
}
|
||||||
|
sheep.$store('user').logout();
|
||||||
|
sheep.$router.go('/pages/index/user');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.container-list {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.set-title {
|
||||||
|
margin: 0 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-box {
|
||||||
|
padding: 100rpx 0;
|
||||||
|
|
||||||
|
.logo-img {
|
||||||
|
width: 160rpx;
|
||||||
|
height: 160rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.name {
|
||||||
|
font-size: 42rpx;
|
||||||
|
font-weight: 400;
|
||||||
|
color: $dark-3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version {
|
||||||
|
font-size: 32rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
line-height: 32rpx;
|
||||||
|
color: $gray-b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.set-footer {
|
||||||
|
margin: 100rpx 0 0 0;
|
||||||
|
|
||||||
|
.copyright-text {
|
||||||
|
font-size: 22rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: $gray-c;
|
||||||
|
line-height: 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agreement-box {
|
||||||
|
font-size: 26rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
|
||||||
|
.tcp-text {
|
||||||
|
color: var(--ui-BG-Main);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agreement-text {
|
||||||
|
color: $dark-9;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.loginout-btn {
|
||||||
|
width: 100%;
|
||||||
|
height: 80rpx;
|
||||||
|
border-radius: 40rpx;
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-border {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 400;
|
||||||
|
color: #333333;
|
||||||
|
border-bottom: 2rpx solid #eeeeee;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.uni-list-item__content-title) {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.uni-list-item__extra-text) {
|
||||||
|
color: #bbbbbb;
|
||||||
|
font-size: 28rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
18
pages/public/webview.vue
Normal file
18
pages/public/webview.vue
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<!-- 网页加载 -->
|
||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<web-view :src="url" />
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { onLoad } from '@dcloudio/uni-app';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
const url = ref('');
|
||||||
|
onLoad((options) => {
|
||||||
|
url.value = decodeURIComponent(options.url);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped></style>
|
||||||
470
pages/user/info.vue
Normal file
470
pages/user/info.vue
Normal file
@@ -0,0 +1,470 @@
|
|||||||
|
<!-- 用户信息 -->
|
||||||
|
<template>
|
||||||
|
<s-layout title="用户信息" class="set-userinfo-wrap">
|
||||||
|
<uni-forms
|
||||||
|
:model="state.model"
|
||||||
|
:rules="state.rules"
|
||||||
|
labelPosition="left"
|
||||||
|
border
|
||||||
|
class="form-box"
|
||||||
|
>
|
||||||
|
<!-- 头像 -->
|
||||||
|
<view class="ss-flex ss-row-center ss-col-center ss-p-t-60 ss-p-b-0 bg-white">
|
||||||
|
<view class="header-box-content">
|
||||||
|
<su-image
|
||||||
|
class="content-img"
|
||||||
|
isPreview
|
||||||
|
:current="0"
|
||||||
|
:src="state.model?.avatar"
|
||||||
|
:height="160"
|
||||||
|
:width="160"
|
||||||
|
:radius="80"
|
||||||
|
mode="scaleToFill"
|
||||||
|
/>
|
||||||
|
<view class="avatar-action">
|
||||||
|
<!-- #ifdef MP -->
|
||||||
|
<button
|
||||||
|
class="ss-reset-button avatar-action-btn"
|
||||||
|
open-type="chooseAvatar"
|
||||||
|
@chooseavatar="onChooseAvatar"
|
||||||
|
>
|
||||||
|
修改
|
||||||
|
</button>
|
||||||
|
<!-- #endif -->
|
||||||
|
<!-- #ifndef MP -->
|
||||||
|
<button class="ss-reset-button avatar-action-btn" @tap="onChangeAvatar">修改</button>
|
||||||
|
<!-- #endif -->
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="bg-white ss-p-x-30">
|
||||||
|
<!-- 昵称 + 性别 -->
|
||||||
|
<uni-forms-item name="nickname" label="昵称">
|
||||||
|
<uni-easyinput
|
||||||
|
v-model="state.model.nickname"
|
||||||
|
type="nickname"
|
||||||
|
placeholder="设置昵称"
|
||||||
|
:inputBorder="false"
|
||||||
|
:placeholderStyle="placeholderStyle"
|
||||||
|
/>
|
||||||
|
</uni-forms-item>
|
||||||
|
<uni-forms-item name="sex" label="性别">
|
||||||
|
<view class="ss-flex ss-col-center ss-h-100">
|
||||||
|
<radio-group @change="onChangeGender" class="ss-flex ss-col-center">
|
||||||
|
<label class="radio" v-for="item in sexRadioMap" :key="item.value">
|
||||||
|
<view class="ss-flex ss-col-center ss-m-r-32">
|
||||||
|
<radio
|
||||||
|
:value="item.value"
|
||||||
|
color="var(--ui-BG-Main)"
|
||||||
|
style="transform: scale(0.8)"
|
||||||
|
:checked="parseInt(item.value) === state.model?.sex"
|
||||||
|
/>
|
||||||
|
<view class="gender-name">{{ item.name }}</view>
|
||||||
|
</view>
|
||||||
|
</label>
|
||||||
|
</radio-group>
|
||||||
|
</view>
|
||||||
|
</uni-forms-item>
|
||||||
|
|
||||||
|
<uni-forms-item name="mobile" label="手机号" @tap="onChangeMobile">
|
||||||
|
<uni-easyinput
|
||||||
|
v-model="userInfo.mobile"
|
||||||
|
placeholder="请绑定手机号"
|
||||||
|
:inputBorder="false"
|
||||||
|
disabled
|
||||||
|
:styles="{ disableColor: '#fff' }"
|
||||||
|
:placeholderStyle="placeholderStyle"
|
||||||
|
:clearable="false"
|
||||||
|
>
|
||||||
|
<template v-slot:right>
|
||||||
|
<view class="ss-flex ss-col-center">
|
||||||
|
<su-radio v-if="userInfo.verification?.mobile" :modelValue="true" />
|
||||||
|
<button v-else class="ss-reset-button ss-flex ss-col-center ss-row-center">
|
||||||
|
<text class="_icon-forward" style="color: #bbbbbb; font-size: 26rpx"></text>
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
</uni-easyinput>
|
||||||
|
</uni-forms-item>
|
||||||
|
|
||||||
|
<!-- <uni-forms-item name="password" label="登录密码" @tap="onSetPassword">
|
||||||
|
<uni-easyinput
|
||||||
|
v-model="userInfo.password"
|
||||||
|
placeholder="点击修改登录密码"
|
||||||
|
:inputBorder="false"
|
||||||
|
:styles="{ disableColor: '#fff' }"
|
||||||
|
disabled
|
||||||
|
placeholderStyle="color:#BBBBBB;font-size:28rpx;line-height:normal"
|
||||||
|
:clearable="false"
|
||||||
|
>
|
||||||
|
<template v-slot:right>
|
||||||
|
<view class="ss-flex ss-col-center">
|
||||||
|
<su-radio
|
||||||
|
class="ss-flex"
|
||||||
|
v-if="userInfo.verification?.password"
|
||||||
|
:modelValue="true"
|
||||||
|
/>
|
||||||
|
<button v-else class="ss-reset-button ss-flex ss-col-center ss-row-center">
|
||||||
|
<text class="_icon-forward" style="color: #bbbbbb; font-size: 26rpx" />
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
</uni-easyinput>
|
||||||
|
</uni-forms-item> -->
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- <view class="bg-white ss-m-t-14">
|
||||||
|
<uni-list>
|
||||||
|
<uni-list-item
|
||||||
|
clickable
|
||||||
|
@tap="sheep.$router.go('/pages/user/address/list')"
|
||||||
|
title="地址管理"
|
||||||
|
showArrow
|
||||||
|
:border="false"
|
||||||
|
class="list-border"
|
||||||
|
/>
|
||||||
|
</uni-list>
|
||||||
|
</view> -->
|
||||||
|
</uni-forms>
|
||||||
|
|
||||||
|
<!-- 当前社交平台的绑定关系,只处理 wechat 微信场景 -->
|
||||||
|
<!-- <view v-if="sheep.$platform.name !== 'H5'">
|
||||||
|
<view class="title-box ss-p-l-30">第三方账号绑定</view>
|
||||||
|
<view class="account-list ss-flex ss-row-between">
|
||||||
|
<view v-if="'WechatOfficialAccount' === sheep.$platform.name" class="ss-flex ss-col-center">
|
||||||
|
<image
|
||||||
|
class="list-img"
|
||||||
|
:src="sheep.$url.static('/static/img/shop/platform/WechatOfficialAccount.png')"
|
||||||
|
/>
|
||||||
|
<text class="list-name">微信公众号</text>
|
||||||
|
</view>
|
||||||
|
<view v-if="'WechatMiniProgram' === sheep.$platform.name" class="ss-flex ss-col-center">
|
||||||
|
<image
|
||||||
|
class="list-img"
|
||||||
|
:src="sheep.$url.static('/static/img/shop/platform/WechatMiniProgram.png')"
|
||||||
|
/>
|
||||||
|
<text class="list-name">微信小程序</text>
|
||||||
|
</view>
|
||||||
|
<view v-if="'App' === sheep.$platform.name" class="ss-flex ss-col-center">
|
||||||
|
<image
|
||||||
|
class="list-img"
|
||||||
|
:src="sheep.$url.static('/static/img/shop/platform/wechat.png')"
|
||||||
|
/>
|
||||||
|
<text class="list-name">微信开放平台</text>
|
||||||
|
</view>
|
||||||
|
<view class="ss-flex ss-col-center">
|
||||||
|
<view class="info ss-flex ss-col-center" v-if="state.thirdInfo">
|
||||||
|
<image class="avatar ss-m-r-20" :src="sheep.$url.cdn(state.thirdInfo.avatar)" />
|
||||||
|
<text class="name">{{ state.thirdInfo.nickname }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="bind-box ss-m-l-20">
|
||||||
|
<button
|
||||||
|
v-if="state.thirdInfo.openid"
|
||||||
|
class="ss-reset-button relieve-btn"
|
||||||
|
@tap="unBindThirdOauth"
|
||||||
|
>
|
||||||
|
解绑
|
||||||
|
</button>
|
||||||
|
<button v-else class="ss-reset-button bind-btn" @tap="bindThirdOauth">绑定</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view> -->
|
||||||
|
|
||||||
|
<su-fixed bottom placeholder bg="none">
|
||||||
|
<view class="footer-box ss-p-20">
|
||||||
|
<button class="ss-rest-button logout-btn ui-Shadow-Main" @tap="onSubmit">保存</button>
|
||||||
|
</view>
|
||||||
|
</su-fixed>
|
||||||
|
</s-layout>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed, reactive, onBeforeMount } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import { clone } from 'lodash-es';
|
||||||
|
import { showAuthModal } from '@/sheep/hooks/useModal';
|
||||||
|
import FileApi from '@/sheep/api/infra/file';
|
||||||
|
import UserApi from '@/sheep/api/member/user';
|
||||||
|
|
||||||
|
const state = reactive({
|
||||||
|
model: {}, // 个人信息
|
||||||
|
rules: {},
|
||||||
|
thirdInfo: {}, // 社交用户的信息
|
||||||
|
});
|
||||||
|
|
||||||
|
const placeholderStyle = 'color:#BBBBBB;font-size:28rpx;line-height:normal';
|
||||||
|
|
||||||
|
const sexRadioMap = [
|
||||||
|
{
|
||||||
|
name: '男',
|
||||||
|
value: '1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '女',
|
||||||
|
value: '2',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const userInfo = computed(() => sheep.$store('user').userInfo);
|
||||||
|
|
||||||
|
// 选择性别
|
||||||
|
function onChangeGender(e) {
|
||||||
|
state.model.sex = e.detail.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改手机号
|
||||||
|
const onChangeMobile = () => {
|
||||||
|
showAuthModal('changeMobile');
|
||||||
|
};
|
||||||
|
|
||||||
|
// 选择微信的头像,进行上传
|
||||||
|
function onChooseAvatar(e) {
|
||||||
|
const tempUrl = e.detail.avatarUrl || '';
|
||||||
|
uploadAvatar(tempUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 手动选择头像,进行上传
|
||||||
|
function onChangeAvatar() {
|
||||||
|
uni.chooseImage({
|
||||||
|
success: async (chooseImageRes) => {
|
||||||
|
const tempUrl = chooseImageRes.tempFilePaths[0];
|
||||||
|
await uploadAvatar(tempUrl);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 上传头像文件
|
||||||
|
async function uploadAvatar(tempUrl) {
|
||||||
|
if (!tempUrl) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let { data } = await FileApi.uploadFile(tempUrl);
|
||||||
|
state.model.avatar = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改密码
|
||||||
|
function onSetPassword() {
|
||||||
|
showAuthModal('changePassword');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 绑定第三方账号
|
||||||
|
async function bindThirdOauth() {
|
||||||
|
let result = await sheep.$platform.useProvider('wechat').bind();
|
||||||
|
if (result) {
|
||||||
|
await getUserInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解绑第三方账号
|
||||||
|
function unBindThirdOauth() {
|
||||||
|
uni.showModal({
|
||||||
|
title: '解绑提醒',
|
||||||
|
content: '解绑后您将无法通过微信登录此账号',
|
||||||
|
cancelText: '再想想',
|
||||||
|
confirmText: '确定',
|
||||||
|
success: async function (res) {
|
||||||
|
if (!res.confirm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await sheep.$platform.useProvider('wechat').unbind(state.thirdInfo.openid);
|
||||||
|
if (result) {
|
||||||
|
await getUserInfo();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存信息
|
||||||
|
async function onSubmit() {
|
||||||
|
const { code } = await UserApi.updateUser({
|
||||||
|
avatar: state.model.avatar,
|
||||||
|
nickname: state.model.nickname,
|
||||||
|
sex: state.model.sex,
|
||||||
|
});
|
||||||
|
if (code === 0) {
|
||||||
|
await getUserInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获得用户信息
|
||||||
|
const getUserInfo = async () => {
|
||||||
|
// 个人信息
|
||||||
|
const userInfo = await sheep.$store('user').getInfo();
|
||||||
|
state.model = clone(userInfo);
|
||||||
|
|
||||||
|
// 获得社交用户的信息
|
||||||
|
if (sheep.$platform.name !== 'H5') {
|
||||||
|
const result = await sheep.$platform.useProvider('wechat').getInfo();
|
||||||
|
state.thirdInfo = result || {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onBeforeMount(() => {
|
||||||
|
getUserInfo();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
:deep() {
|
||||||
|
.uni-file-picker {
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-file-picker__container {
|
||||||
|
margin: -14rpx -12rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-picker__progress {
|
||||||
|
height: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-list-item__content-title {
|
||||||
|
font-size: 28rpx !important;
|
||||||
|
color: #333333 !important;
|
||||||
|
line-height: normal !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-icons {
|
||||||
|
font-size: 40rpx !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-disabled {
|
||||||
|
color: #333333;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.disabled) {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gender-name {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
line-height: normal;
|
||||||
|
color: #333333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title-box {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #666666;
|
||||||
|
line-height: 100rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logout-btn {
|
||||||
|
width: 710rpx;
|
||||||
|
height: 80rpx;
|
||||||
|
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
|
||||||
|
border-radius: 40rpx;
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: $white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-dark {
|
||||||
|
filter: grayscale(100%);
|
||||||
|
filter: gray;
|
||||||
|
opacity: 0.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-img {
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
.header-box-content {
|
||||||
|
position: relative;
|
||||||
|
width: 160rpx;
|
||||||
|
height: 160rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
.avatar-action {
|
||||||
|
position: absolute;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
bottom: 0;
|
||||||
|
z-index: 1;
|
||||||
|
width: 160rpx;
|
||||||
|
height: 46rpx;
|
||||||
|
background: rgba(#000000, 0.3);
|
||||||
|
|
||||||
|
.avatar-action-btn {
|
||||||
|
width: 160rpx;
|
||||||
|
height: 46rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 绑定项
|
||||||
|
.account-list {
|
||||||
|
background-color: $white;
|
||||||
|
height: 100rpx;
|
||||||
|
padding: 0 20rpx;
|
||||||
|
|
||||||
|
.list-img {
|
||||||
|
width: 40rpx;
|
||||||
|
height: 40rpx;
|
||||||
|
margin-right: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-name {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info {
|
||||||
|
.avatar {
|
||||||
|
width: 38rpx;
|
||||||
|
height: 38rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.name {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 400;
|
||||||
|
color: $dark-9;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.bind-box {
|
||||||
|
width: 100rpx;
|
||||||
|
height: 50rpx;
|
||||||
|
line-height: normal;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
font-size: 24rpx;
|
||||||
|
|
||||||
|
.bind-btn {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 25rpx;
|
||||||
|
background: #f4f4f4;
|
||||||
|
color: #999999;
|
||||||
|
}
|
||||||
|
.relieve-btn {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 25rpx;
|
||||||
|
background: var(--ui-BG-Main-opacity-1);
|
||||||
|
color: var(--ui-BG-Main);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-border {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 400;
|
||||||
|
color: #333333;
|
||||||
|
border-bottom: 2rpx solid #eeeeee;
|
||||||
|
}
|
||||||
|
|
||||||
|
image {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
66
sheep/api/infra/file.js
Normal file
66
sheep/api/infra/file.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import { baseUrl, apiPath, tenantId } from '@/sheep/config';
|
||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const FileApi = {
|
||||||
|
// 上传文件
|
||||||
|
uploadFile: (file) => {
|
||||||
|
// TODO 芋艿:访问令牌的接入;
|
||||||
|
const token = uni.getStorageSync('token');
|
||||||
|
uni.showLoading({
|
||||||
|
title: '上传中',
|
||||||
|
});
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
uni.uploadFile({
|
||||||
|
url: baseUrl + apiPath + '/infra/file/upload',
|
||||||
|
filePath: file,
|
||||||
|
name: 'file',
|
||||||
|
header: {
|
||||||
|
// Accept: 'text/json',
|
||||||
|
Accept: '*/*',
|
||||||
|
'tenant-id': tenantId,
|
||||||
|
// Authorization: 'Bearer test247',
|
||||||
|
},
|
||||||
|
success: (uploadFileRes) => {
|
||||||
|
let result = JSON.parse(uploadFileRes.data);
|
||||||
|
if (result.error === 1) {
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: result.msg,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return resolve(result);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (error) => {
|
||||||
|
console.log('上传失败:', error);
|
||||||
|
return resolve(false);
|
||||||
|
},
|
||||||
|
complete: () => {
|
||||||
|
uni.hideLoading();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取文件预签名地址
|
||||||
|
getFilePresignedUrl: (path) => {
|
||||||
|
return request({
|
||||||
|
url: '/infra/file/presigned-url',
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
path,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 创建文件
|
||||||
|
createFile: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/infra/file/create', // 请求的 URL
|
||||||
|
method: 'POST', // 请求方法
|
||||||
|
data: data, // 要发送的数据
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FileApi;
|
||||||
61
sheep/api/member/address.js
Normal file
61
sheep/api/member/address.js
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const AddressApi = {
|
||||||
|
// 获得用户收件地址列表
|
||||||
|
getAddressList: () => {
|
||||||
|
return request({
|
||||||
|
url: '/member/address/list',
|
||||||
|
method: 'GET'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 创建用户收件地址
|
||||||
|
createAddress: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/address/create',
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
custom: {
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '保存成功'
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 更新用户收件地址
|
||||||
|
updateAddress: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/address/update',
|
||||||
|
method: 'PUT',
|
||||||
|
data,
|
||||||
|
custom: {
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '更新成功'
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得用户收件地址
|
||||||
|
getAddress: (id) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/address/get',
|
||||||
|
method: 'GET',
|
||||||
|
params: { id }
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 删除用户收件地址
|
||||||
|
deleteAddress: (id) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/address/delete',
|
||||||
|
method: 'DELETE',
|
||||||
|
params: { id }
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得商户关联的冷库列表
|
||||||
|
getStorehouseList: () => {
|
||||||
|
return request({
|
||||||
|
url: '/delivery/storehouse/list',
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AddressApi;
|
||||||
132
sheep/api/member/auth.js
Normal file
132
sheep/api/member/auth.js
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const AuthUtil = {
|
||||||
|
// 使用手机 + 密码登录
|
||||||
|
login: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/auth/login',
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
custom: {
|
||||||
|
showSuccess: true,
|
||||||
|
loadingMsg: '登录中',
|
||||||
|
successMsg: '登录成功',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 使用手机 + 验证码登录
|
||||||
|
smsLogin: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/auth/sms-login',
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
custom: {
|
||||||
|
showSuccess: true,
|
||||||
|
loadingMsg: '登录中',
|
||||||
|
successMsg: '登录成功',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 发送手机验证码
|
||||||
|
sendSmsCode: (mobile, scene) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/auth/send-sms-code',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
mobile,
|
||||||
|
scene,
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
loadingMsg: '发送中',
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '发送成功',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 登出系统
|
||||||
|
logout: () => {
|
||||||
|
return request({
|
||||||
|
url: '/member/auth/logout',
|
||||||
|
method: 'POST',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 刷新令牌
|
||||||
|
refreshToken: (refreshToken) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/auth/refresh-token',
|
||||||
|
method: 'POST',
|
||||||
|
params: {
|
||||||
|
refreshToken
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
loading: false, // 不用加载中
|
||||||
|
showError: false, // 不展示错误提示
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 社交授权的跳转
|
||||||
|
socialAuthRedirect: (type, redirectUri) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/auth/social-auth-redirect',
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
type,
|
||||||
|
redirectUri,
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
showSuccess: true,
|
||||||
|
loadingMsg: '登陆中',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 社交快捷登录
|
||||||
|
socialLogin: (type, code, state) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/auth/social-login',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
type,
|
||||||
|
code,
|
||||||
|
state,
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
showSuccess: true,
|
||||||
|
loadingMsg: '登陆中',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 微信小程序的一键登录
|
||||||
|
weixinMiniAppLogin: (phoneCode, loginCode, state) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/auth/weixin-mini-app-login',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
phoneCode,
|
||||||
|
loginCode,
|
||||||
|
state
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
showSuccess: true,
|
||||||
|
loadingMsg: '登陆中',
|
||||||
|
successMsg: '登录成功',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 创建微信 JS SDK 初始化所需的签名
|
||||||
|
createWeixinMpJsapiSignature: (url) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/auth/create-weixin-jsapi-signature',
|
||||||
|
method: 'POST',
|
||||||
|
params: {
|
||||||
|
url
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
showError: false,
|
||||||
|
showLoading: false,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
//
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AuthUtil;
|
||||||
76
sheep/api/member/social.js
Normal file
76
sheep/api/member/social.js
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const SocialApi = {
|
||||||
|
// 获得社交用户
|
||||||
|
getSocialUser: (type) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/social-user/get',
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
type
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 社交绑定
|
||||||
|
socialBind: (type, code, state) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/social-user/bind',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
type,
|
||||||
|
code,
|
||||||
|
state
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
custom: {
|
||||||
|
showSuccess: true,
|
||||||
|
loadingMsg: '绑定中',
|
||||||
|
successMsg: '绑定成功',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 社交绑定
|
||||||
|
socialUnbind: (type, openid) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/social-user/unbind',
|
||||||
|
method: 'DELETE',
|
||||||
|
data: {
|
||||||
|
type,
|
||||||
|
openid
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
loadingMsg: '解除绑定',
|
||||||
|
successMsg: '解绑成功',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获取订阅消息模板列表
|
||||||
|
getSubscribeTemplateList: () =>
|
||||||
|
request({
|
||||||
|
url: '/member/social-user/get-subscribe-template-list',
|
||||||
|
method: 'GET',
|
||||||
|
custom: {
|
||||||
|
showError: false,
|
||||||
|
showLoading: false,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
// 获取微信小程序码
|
||||||
|
getWxaQrcode: async (path, query) => {
|
||||||
|
return await request({
|
||||||
|
url: '/member/social-user/wxa-qrcode',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
scene: query,
|
||||||
|
path,
|
||||||
|
checkPath: false, // TODO 开发环境暂不检查 path 是否存在
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SocialApi;
|
||||||
98
sheep/api/member/user.js
Normal file
98
sheep/api/member/user.js
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const UserApi = {
|
||||||
|
// 获得基本信息
|
||||||
|
getUserInfo: () => {
|
||||||
|
return request({
|
||||||
|
url: '/member/user/get',
|
||||||
|
method: 'GET',
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
auth: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 修改基本信息
|
||||||
|
updateUser: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/user/update',
|
||||||
|
method: 'PUT',
|
||||||
|
data,
|
||||||
|
custom: {
|
||||||
|
auth: true,
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '更新成功'
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 修改用户手机
|
||||||
|
updateUserMobile: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/user/update-mobile',
|
||||||
|
method: 'PUT',
|
||||||
|
data,
|
||||||
|
custom: {
|
||||||
|
loadingMsg: '验证中',
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '修改成功'
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 基于微信小程序的授权码,修改用户手机
|
||||||
|
updateUserMobileByWeixin: (code) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/user/update-mobile-by-weixin',
|
||||||
|
method: 'PUT',
|
||||||
|
data: {
|
||||||
|
code
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
showSuccess: true,
|
||||||
|
loadingMsg: '获取中',
|
||||||
|
successMsg: '修改成功'
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 修改密码
|
||||||
|
updateUserPassword: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/user/update-password',
|
||||||
|
method: 'PUT',
|
||||||
|
data,
|
||||||
|
custom: {
|
||||||
|
loadingMsg: '验证中',
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '修改成功'
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 修改密码
|
||||||
|
updateUserPasswordReset: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/user/update-password-by-reset',
|
||||||
|
method: 'PUT',
|
||||||
|
data,
|
||||||
|
custom: {
|
||||||
|
loadingMsg: '验证中',
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '修改成功'
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 重置密码
|
||||||
|
resetUserPassword: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/member/user/reset-password',
|
||||||
|
method: 'PUT',
|
||||||
|
data,
|
||||||
|
custom: {
|
||||||
|
loadingMsg: '验证中',
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '修改成功'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UserApi;
|
||||||
21
sheep/api/migration/app.js
Normal file
21
sheep/api/migration/app.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
// TODO 芋艿:小程序直播还不支持
|
||||||
|
export default {
|
||||||
|
//小程序直播
|
||||||
|
mplive: {
|
||||||
|
getRoomList: (ids) =>
|
||||||
|
request({
|
||||||
|
url: 'app/mplive/getRoomList',
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
ids: ids.join(','),
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
getMpLink: () =>
|
||||||
|
request({
|
||||||
|
url: 'app/mplive/getMpLink',
|
||||||
|
method: 'GET'
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
10
sheep/api/migration/index.js
Normal file
10
sheep/api/migration/index.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
const files = import.meta.glob('./*.js', { eager: true });
|
||||||
|
let api = {};
|
||||||
|
Object.keys(files).forEach((key) => {
|
||||||
|
api = {
|
||||||
|
...api,
|
||||||
|
[key.replace(/(.*\/)*([^.]+).*/gi, '$2')]: files[key].default,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
export default api;
|
||||||
18
sheep/api/migration/third.js
Normal file
18
sheep/api/migration/third.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
// 苹果相关
|
||||||
|
apple: {
|
||||||
|
// 第三方登录
|
||||||
|
login: (data) =>
|
||||||
|
request({
|
||||||
|
url: 'third/apple/login',
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
custom: {
|
||||||
|
showSuccess: true,
|
||||||
|
loadingMsg: '登陆中',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
14
sheep/api/pay/channel.js
Normal file
14
sheep/api/pay/channel.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const PayChannelApi = {
|
||||||
|
// 获得指定应用的开启的支付渠道编码列表
|
||||||
|
getEnableChannelCodeList: (appId) => {
|
||||||
|
return request({
|
||||||
|
url: '/pay/channel/get-enable-code-list',
|
||||||
|
method: 'GET',
|
||||||
|
params: { appId }
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PayChannelApi;
|
||||||
22
sheep/api/pay/order.js
Normal file
22
sheep/api/pay/order.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const PayOrderApi = {
|
||||||
|
// 获得支付订单
|
||||||
|
getOrder: (id, sync) => {
|
||||||
|
return request({
|
||||||
|
url: '/pay/order/get',
|
||||||
|
method: 'GET',
|
||||||
|
params: { id, sync },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 提交支付订单
|
||||||
|
submitOrder: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/pay/order/submit',
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PayOrderApi;
|
||||||
68
sheep/api/pay/wallet.js
Normal file
68
sheep/api/pay/wallet.js
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const PayWalletApi = {
|
||||||
|
// 获取钱包
|
||||||
|
getPayWallet() {
|
||||||
|
return request({
|
||||||
|
url: '/pay/wallet/get',
|
||||||
|
method: 'GET',
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
auth: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得钱包流水分页
|
||||||
|
getWalletTransactionPage: (params) => {
|
||||||
|
const queryString = Object.keys(params)
|
||||||
|
.map((key) => encodeURIComponent(key) + '=' + params[key])
|
||||||
|
.join('&');
|
||||||
|
return request({
|
||||||
|
url: `/pay/wallet-transaction/page?${queryString}`,
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得钱包流水统计
|
||||||
|
getWalletTransactionSummary: (params) => {
|
||||||
|
const queryString = `createTime=${params.createTime[0]}&createTime=${params.createTime[1]}`;
|
||||||
|
return request({
|
||||||
|
url: `/pay/wallet-transaction/get-summary?${queryString}`,
|
||||||
|
// url: `/pay/wallet-transaction/get-summary`,
|
||||||
|
method: 'GET',
|
||||||
|
// params: params
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得钱包充值套餐列表
|
||||||
|
getWalletRechargePackageList: () => {
|
||||||
|
return request({
|
||||||
|
url: '/pay/wallet-recharge-package/list',
|
||||||
|
method: 'GET',
|
||||||
|
custom: {
|
||||||
|
showError: false,
|
||||||
|
showLoading: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 创建钱包充值记录(发起充值)
|
||||||
|
createWalletRecharge: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/pay/wallet-recharge/create',
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得钱包充值记录分页
|
||||||
|
getWalletRechargePage: (params) => {
|
||||||
|
return request({
|
||||||
|
url: '/pay/wallet-recharge/page',
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
custom: {
|
||||||
|
showError: false,
|
||||||
|
showLoading: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PayWalletApi;
|
||||||
21
sheep/api/product/category.js
Normal file
21
sheep/api/product/category.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const CategoryApi = {
|
||||||
|
// 查询分类列表
|
||||||
|
getCategoryList: () => {
|
||||||
|
return request({
|
||||||
|
url: '/product/category/list',
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 查询分类列表,指定编号
|
||||||
|
getCategoryListByIds: (ids) => {
|
||||||
|
return request({
|
||||||
|
url: '/product/category/list-by-ids',
|
||||||
|
method: 'GET',
|
||||||
|
params: { ids },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CategoryApi;
|
||||||
22
sheep/api/product/comment.js
Normal file
22
sheep/api/product/comment.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const CommentApi = {
|
||||||
|
// 获得商品评价分页
|
||||||
|
getCommentPage: (spuId, pageNo, pageSize, type) => {
|
||||||
|
return request({
|
||||||
|
url: '/product/comment/page',
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
spuId,
|
||||||
|
pageNo,
|
||||||
|
pageSize,
|
||||||
|
type,
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
showError: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export default CommentApi;
|
||||||
54
sheep/api/product/favorite.js
Normal file
54
sheep/api/product/favorite.js
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const FavoriteApi = {
|
||||||
|
// 获得商品收藏分页
|
||||||
|
getFavoritePage: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/product/favorite/page',
|
||||||
|
method: 'GET',
|
||||||
|
params: data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 检查是否收藏过商品
|
||||||
|
isFavoriteExists: (spuId) => {
|
||||||
|
return request({
|
||||||
|
url: '/product/favorite/exits',
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
spuId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 添加商品收藏
|
||||||
|
createFavorite: (spuId) => {
|
||||||
|
return request({
|
||||||
|
url: '/product/favorite/create',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
spuId,
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
auth: true,
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '收藏成功',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 取消商品收藏
|
||||||
|
deleteFavorite: (spuId) => {
|
||||||
|
return request({
|
||||||
|
url: '/product/favorite/delete',
|
||||||
|
method: 'DELETE',
|
||||||
|
data: {
|
||||||
|
spuId,
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
auth: true,
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '取消成功',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FavoriteApi;
|
||||||
39
sheep/api/product/history.js
Normal file
39
sheep/api/product/history.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const SpuHistoryApi = {
|
||||||
|
// 删除商品浏览记录
|
||||||
|
deleteBrowseHistory: (spuIds) => {
|
||||||
|
return request({
|
||||||
|
url: '/product/browse-history/delete',
|
||||||
|
method: 'DELETE',
|
||||||
|
data: { spuIds },
|
||||||
|
custom: {
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '删除成功',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 清空商品浏览记录
|
||||||
|
cleanBrowseHistory: () => {
|
||||||
|
return request({
|
||||||
|
url: '/product/browse-history/clean',
|
||||||
|
method: 'DELETE',
|
||||||
|
custom: {
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '清空成功',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得商品浏览记录分页
|
||||||
|
getBrowseHistoryPage: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/product/browse-history/page',
|
||||||
|
method: 'GET',
|
||||||
|
data,
|
||||||
|
custom: {
|
||||||
|
showLoading: false
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export default SpuHistoryApi;
|
||||||
53
sheep/api/product/spu.js
Normal file
53
sheep/api/product/spu.js
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const SpuApi = {
|
||||||
|
// 获得商品 SPU 列表
|
||||||
|
getSpuListByIds: (ids) => {
|
||||||
|
return request({
|
||||||
|
url: '/product/spu/list-by-ids',
|
||||||
|
method: 'GET',
|
||||||
|
params: { ids },
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
showError: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得商品结算信息
|
||||||
|
getSettlementProduct: (spuIds) => {
|
||||||
|
return request({
|
||||||
|
url: '/trade/order/settlement-product',
|
||||||
|
method: 'GET',
|
||||||
|
params: { spuIds },
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
showError: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得商品 SPU 分页
|
||||||
|
getSpuPage: (params) => {
|
||||||
|
return request({
|
||||||
|
url: '/product/spu/page',
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
showError: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 查询商品
|
||||||
|
getSpuDetail: (id) => {
|
||||||
|
return request({
|
||||||
|
url: '/product/spu/get-detail',
|
||||||
|
method: 'GET',
|
||||||
|
params: { id },
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
showError: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export default SpuApi;
|
||||||
16
sheep/api/promotion/activity.js
Normal file
16
sheep/api/promotion/activity.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const ActivityApi = {
|
||||||
|
// 获得单个商品,进行中的拼团、秒杀、砍价活动信息
|
||||||
|
getActivityListBySpuId: (spuId) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/activity/list-by-spu-id',
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
spuId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ActivityApi;
|
||||||
12
sheep/api/promotion/article.js
Normal file
12
sheep/api/promotion/article.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
// 获得文章详情
|
||||||
|
getArticle: (id, title) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/article/get',
|
||||||
|
method: 'GET',
|
||||||
|
params: { id, title }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
78
sheep/api/promotion/combination.js
Normal file
78
sheep/api/promotion/combination.js
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
// 拼团 API
|
||||||
|
const CombinationApi = {
|
||||||
|
// 获得拼团活动分页
|
||||||
|
getCombinationActivityPage: (params) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/combination-activity/page',
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获得拼团活动明细
|
||||||
|
getCombinationActivity: (id) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/combination-activity/get-detail',
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获得拼团活动列表,基于活动编号数组
|
||||||
|
getCombinationActivityListByIds: (ids) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/combination-activity/list-by-ids',
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
ids,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获得最近 n 条拼团记录(团长发起的)
|
||||||
|
getHeadCombinationRecordList: (activityId, status, count) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/combination-record/get-head-list',
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
activityId,
|
||||||
|
status,
|
||||||
|
count,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获得我的拼团记录分页
|
||||||
|
getCombinationRecordPage: (params) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/combination-record/page',
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获得拼团记录明细
|
||||||
|
getCombinationRecordDetail: (id) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/combination-record/get-detail',
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获得拼团记录的概要信息
|
||||||
|
getCombinationRecordSummary: () => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/combination-record/get-summary',
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CombinationApi;
|
||||||
84
sheep/api/promotion/coupon.js
Normal file
84
sheep/api/promotion/coupon.js
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const CouponApi = {
|
||||||
|
// 获得优惠劵模板列表
|
||||||
|
getCouponTemplateListByIds: (ids) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/coupon-template/list-by-ids',
|
||||||
|
method: 'GET',
|
||||||
|
params: { ids },
|
||||||
|
custom: {
|
||||||
|
showLoading: false, // 不展示 Loading,避免领取优惠劵时,不成功提示
|
||||||
|
showError: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得优惠劵模版列表
|
||||||
|
getCouponTemplateList: (spuId, productScope, count) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/coupon-template/list',
|
||||||
|
method: 'GET',
|
||||||
|
params: { spuId, productScope, count },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得优惠劵模版分页
|
||||||
|
getCouponTemplatePage: (params) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/coupon-template/page',
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得优惠劵模版
|
||||||
|
getCouponTemplate: (id) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/coupon-template/get',
|
||||||
|
method: 'GET',
|
||||||
|
params: { id },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 我的优惠劵列表
|
||||||
|
getCouponPage: (params) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/coupon/page',
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 领取优惠券
|
||||||
|
takeCoupon: (templateId) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/coupon/take',
|
||||||
|
method: 'POST',
|
||||||
|
data: { templateId },
|
||||||
|
custom: {
|
||||||
|
auth: true,
|
||||||
|
showLoading: true,
|
||||||
|
loadingMsg: '领取中',
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '领取成功',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得优惠劵
|
||||||
|
getCoupon: (id) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/coupon/get',
|
||||||
|
method: 'GET',
|
||||||
|
params: { id },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得未使用的优惠劵数量
|
||||||
|
getUnusedCouponCount: () => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/coupon/get-unused-count',
|
||||||
|
method: 'GET',
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
auth: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CouponApi;
|
||||||
38
sheep/api/promotion/diy.js
Normal file
38
sheep/api/promotion/diy.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const DiyApi = {
|
||||||
|
getUsedDiyTemplate: () => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/diy-template/used',
|
||||||
|
method: 'GET',
|
||||||
|
custom: {
|
||||||
|
showError: false,
|
||||||
|
showLoading: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getDiyTemplate: (id) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/diy-template/get',
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
id
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
showError: false,
|
||||||
|
showLoading: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getDiyPage: (id) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/diy-page/get',
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DiyApi;
|
||||||
31
sheep/api/promotion/kefu.js
Normal file
31
sheep/api/promotion/kefu.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const KeFuApi = {
|
||||||
|
sendKefuMessage: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/kefu-message/send',
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
custom: {
|
||||||
|
auth: true,
|
||||||
|
showLoading: true,
|
||||||
|
loadingMsg: '发送中',
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '发送成功',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getKefuMessageList: (params) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/kefu-message/list',
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
custom: {
|
||||||
|
auth: true,
|
||||||
|
showLoading: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default KeFuApi;
|
||||||
30
sheep/api/promotion/point.js
Normal file
30
sheep/api/promotion/point.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const PointApi = {
|
||||||
|
// 获得积分商城活动分页
|
||||||
|
getPointActivityPage: (params) => {
|
||||||
|
return request({ url: 'promotion/point-activity/page', method: 'GET', params });
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获得积分商城活动列表,基于活动编号数组
|
||||||
|
getPointActivityListByIds: (ids) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/point-activity/list-by-ids',
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
ids,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获得积分商城活动明细
|
||||||
|
getPointActivity: (id) => {
|
||||||
|
return request({
|
||||||
|
url: 'promotion/point-activity/get-detail',
|
||||||
|
method: 'GET',
|
||||||
|
params: { id },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PointApi;
|
||||||
14
sheep/api/promotion/rewardActivity.js
Normal file
14
sheep/api/promotion/rewardActivity.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const RewardActivityApi = {
|
||||||
|
// 获得满减送活动
|
||||||
|
getRewardActivity: (id) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/reward-activity/get',
|
||||||
|
method: 'GET',
|
||||||
|
params: { id },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RewardActivityApi;
|
||||||
44
sheep/api/promotion/seckill.js
Normal file
44
sheep/api/promotion/seckill.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const SeckillApi = {
|
||||||
|
// 获得秒杀时间段列表
|
||||||
|
getSeckillConfigList: () => {
|
||||||
|
return request({ url: 'promotion/seckill-config/list', method: 'GET' });
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获得当前秒杀活动
|
||||||
|
getNowSeckillActivity: () => {
|
||||||
|
return request({ url: 'promotion/seckill-activity/get-now', method: 'GET' });
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获得秒杀活动分页
|
||||||
|
getSeckillActivityPage: (params) => {
|
||||||
|
return request({ url: 'promotion/seckill-activity/page', method: 'GET', params });
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获得秒杀活动列表,基于活动编号数组
|
||||||
|
getSeckillActivityListByIds: (ids) => {
|
||||||
|
return request({
|
||||||
|
url: '/promotion/seckill-activity/list-by-ids',
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
ids,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得秒杀活动明细
|
||||||
|
* @param {number} id 秒杀活动编号
|
||||||
|
* @return {*}
|
||||||
|
*/
|
||||||
|
getSeckillActivity: (id) => {
|
||||||
|
return request({
|
||||||
|
url: 'promotion/seckill-activity/get-detail',
|
||||||
|
method: 'GET',
|
||||||
|
params: { id },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SeckillApi;
|
||||||
13
sheep/api/system/area.js
Normal file
13
sheep/api/system/area.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const AreaApi = {
|
||||||
|
// 获得地区树
|
||||||
|
getAreaTree: () => {
|
||||||
|
return request({
|
||||||
|
url: '/system/area/tree',
|
||||||
|
method: 'GET'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AreaApi;
|
||||||
16
sheep/api/system/dict.js
Normal file
16
sheep/api/system/dict.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const DictApi = {
|
||||||
|
// 根据字典类型查询字典数据信息
|
||||||
|
getDictDataListByType: (type) => {
|
||||||
|
return request({
|
||||||
|
url: `/system/dict-data/type`,
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
type,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DictApi;
|
||||||
115
sheep/api/trade/afterSale.js
Normal file
115
sheep/api/trade/afterSale.js
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const AfterSaleApi = {
|
||||||
|
// 获得售后分页
|
||||||
|
getAfterSalePage: (params) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/after-sale/page`,
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 创建售后
|
||||||
|
createAfterSale: (data) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/after-sale/create`,
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得售后
|
||||||
|
getAfterSale: (id) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/after-sale/get`,
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 取消售后
|
||||||
|
cancelAfterSale: (id) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/after-sale/cancel`,
|
||||||
|
method: 'DELETE',
|
||||||
|
params: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得售后日志列表
|
||||||
|
getAfterSaleLogList: (afterSaleId) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/after-sale-log/list`,
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
afterSaleId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 退回货物
|
||||||
|
deliveryAfterSale: (data) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/after-sale/delivery`,
|
||||||
|
method: 'PUT',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 创建售后单
|
||||||
|
afterOrderCreate: (data) => {
|
||||||
|
return request({
|
||||||
|
url: `/merchants/after-order/create`,
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得售后单分页
|
||||||
|
afterOrderPage: (data) => {
|
||||||
|
return request({
|
||||||
|
url: `/merchants/after-order/page`,
|
||||||
|
method: 'GET',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得售后单详情
|
||||||
|
afterOrderGet: (id) => {
|
||||||
|
return request({
|
||||||
|
url: `/merchants/after-order/get`,
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 取消售后
|
||||||
|
afterOrderCancel: (id) => {
|
||||||
|
return request({
|
||||||
|
url: `/merchants/after-order/cancel`,
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 修改售后单
|
||||||
|
afterOrderUpdate: (data) => {
|
||||||
|
return request({
|
||||||
|
url: `/merchants/after-order/update`,
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 售后单发货状态标记已完成
|
||||||
|
afterOrderFinish: (data) => {
|
||||||
|
return request({
|
||||||
|
url: `/merchants/after-order/finish`,
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AfterSaleApi;
|
||||||
93
sheep/api/trade/brokerage.js
Normal file
93
sheep/api/trade/brokerage.js
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const BrokerageApi = {
|
||||||
|
// 绑定分销用户
|
||||||
|
bindBrokerageUser: (data)=>{
|
||||||
|
return request({
|
||||||
|
url: '/trade/brokerage-user/bind',
|
||||||
|
method: 'PUT',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得个人分销信息
|
||||||
|
getBrokerageUser: () => {
|
||||||
|
return request({
|
||||||
|
url: '/trade/brokerage-user/get',
|
||||||
|
method: 'GET'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得个人分销统计
|
||||||
|
getBrokerageUserSummary: () => {
|
||||||
|
return request({
|
||||||
|
url: '/trade/brokerage-user/get-summary',
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得分销记录分页
|
||||||
|
getBrokerageRecordPage: params => {
|
||||||
|
if (params.status === undefined) {
|
||||||
|
delete params.status
|
||||||
|
}
|
||||||
|
const queryString = Object.keys(params)
|
||||||
|
.map(key => encodeURIComponent(key) + '=' + params[key])
|
||||||
|
.join('&');
|
||||||
|
return request({
|
||||||
|
url: `/trade/brokerage-record/page?${queryString}`,
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 创建分销提现
|
||||||
|
createBrokerageWithdraw: data => {
|
||||||
|
return request({
|
||||||
|
url: '/trade/brokerage-withdraw/create',
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得商品的分销金额
|
||||||
|
getProductBrokeragePrice: spuId => {
|
||||||
|
return request({
|
||||||
|
url: '/trade/brokerage-record/get-product-brokerage-price',
|
||||||
|
method: 'GET',
|
||||||
|
params: { spuId }
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得分销用户排行(基于佣金)
|
||||||
|
getRankByPrice: params => {
|
||||||
|
const queryString = `times=${params.times[0]}×=${params.times[1]}`;
|
||||||
|
return request({
|
||||||
|
url: `/trade/brokerage-user/get-rank-by-price?${queryString}`,
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得分销用户排行分页(基于佣金)
|
||||||
|
getBrokerageUserChildSummaryPageByPrice: params => {
|
||||||
|
const queryString = Object.keys(params)
|
||||||
|
.map(key => encodeURIComponent(key) + '=' + params[key])
|
||||||
|
.join('&');
|
||||||
|
return request({
|
||||||
|
url: `/trade/brokerage-user/rank-page-by-price?${queryString}`,
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得分销用户排行分页(基于用户量)
|
||||||
|
getBrokerageUserRankPageByUserCount: params => {
|
||||||
|
const queryString = Object.keys(params)
|
||||||
|
.map(key => encodeURIComponent(key) + '=' + params[key])
|
||||||
|
.join('&');
|
||||||
|
return request({
|
||||||
|
url: `/trade/brokerage-user/rank-page-by-user-count?${queryString}`,
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得下级分销统计分页
|
||||||
|
getBrokerageUserChildSummaryPage: params => {
|
||||||
|
return request({
|
||||||
|
url: '/trade/brokerage-user/child-summary-page',
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BrokerageApi
|
||||||
50
sheep/api/trade/cart.js
Normal file
50
sheep/api/trade/cart.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const CartApi = {
|
||||||
|
addCart: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/trade/cart/add',
|
||||||
|
method: 'POST',
|
||||||
|
data: data,
|
||||||
|
custom: {
|
||||||
|
showSuccess: true,
|
||||||
|
successMsg: '已添加到购物车~',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
updateCartCount: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/trade/cart/update-count',
|
||||||
|
method: 'PUT',
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
},
|
||||||
|
updateCartSelected: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/trade/cart/update-selected',
|
||||||
|
method: 'PUT',
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
},
|
||||||
|
deleteCart: (ids) => {
|
||||||
|
return request({
|
||||||
|
url: '/trade/cart/delete',
|
||||||
|
method: 'DELETE',
|
||||||
|
params: {
|
||||||
|
ids
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getCartList: () => {
|
||||||
|
return request({
|
||||||
|
url: '/trade/cart/list',
|
||||||
|
method: 'GET',
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
auth: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CartApi;
|
||||||
16
sheep/api/trade/config.js
Normal file
16
sheep/api/trade/config.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const TradeConfigApi = {
|
||||||
|
// 获得交易配置
|
||||||
|
getTradeConfig: () => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/config/get`,
|
||||||
|
method: 'GET',
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TradeConfigApi;
|
||||||
31
sheep/api/trade/delivery.js
Normal file
31
sheep/api/trade/delivery.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const DeliveryApi = {
|
||||||
|
// 获得快递公司列表
|
||||||
|
getDeliveryExpressList: () => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/delivery/express/list`,
|
||||||
|
method: 'get',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得自提门店列表
|
||||||
|
getDeliveryPickUpStoreList: (params) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/delivery/pick-up-store/list`,
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得自提门店
|
||||||
|
getDeliveryPickUpStore: (id) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/delivery/pick-up-store/get`,
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DeliveryApi;
|
||||||
196
sheep/api/trade/order.js
Normal file
196
sheep/api/trade/order.js
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
import request from '@/sheep/request';
|
||||||
|
import { isEmpty } from '@/sheep/helper/utils';
|
||||||
|
|
||||||
|
const OrderApi = {
|
||||||
|
// 计算订单信息
|
||||||
|
settlementOrder: (data) => {
|
||||||
|
const data2 = {
|
||||||
|
...data,
|
||||||
|
};
|
||||||
|
// 移除多余字段
|
||||||
|
if (!(data.couponId > 0)) {
|
||||||
|
delete data2.couponId;
|
||||||
|
}
|
||||||
|
if (!(data.addressId > 0)) {
|
||||||
|
delete data2.addressId;
|
||||||
|
}
|
||||||
|
if (!(data.pickUpStoreId > 0)) {
|
||||||
|
delete data2.pickUpStoreId;
|
||||||
|
}
|
||||||
|
if (isEmpty(data.receiverName)) {
|
||||||
|
delete data2.receiverName;
|
||||||
|
}
|
||||||
|
if (isEmpty(data.receiverMobile)) {
|
||||||
|
delete data2.receiverMobile;
|
||||||
|
}
|
||||||
|
if (!(data.combinationActivityId > 0)) {
|
||||||
|
delete data2.combinationActivityId;
|
||||||
|
}
|
||||||
|
if (!(data.combinationHeadId > 0)) {
|
||||||
|
delete data2.combinationHeadId;
|
||||||
|
}
|
||||||
|
if (!(data.seckillActivityId > 0)) {
|
||||||
|
delete data2.seckillActivityId;
|
||||||
|
}
|
||||||
|
if (!(data.pointActivityId > 0)) {
|
||||||
|
delete data2.pointActivityId;
|
||||||
|
}
|
||||||
|
if (!(data.deliveryType > 0)) {
|
||||||
|
delete data2.deliveryType;
|
||||||
|
}
|
||||||
|
// 解决 SpringMVC 接受 List<Item> 参数的问题
|
||||||
|
delete data2.items;
|
||||||
|
for (let i = 0; i < data.items.length; i++) {
|
||||||
|
data2[encodeURIComponent('items[' + i + '' + '].skuId')] = data.items[i].skuId + '';
|
||||||
|
data2[encodeURIComponent('items[' + i + '' + '].count')] = data.items[i].count + '';
|
||||||
|
if (data.items[i].cartId) {
|
||||||
|
data2[encodeURIComponent('items[' + i + '' + '].cartId')] = data.items[i].cartId + '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const queryString = Object.keys(data2)
|
||||||
|
.map((key) => key + '=' + data2[key])
|
||||||
|
.join('&');
|
||||||
|
return request({
|
||||||
|
url: `/trade/order/settlement?${queryString}`,
|
||||||
|
method: 'GET',
|
||||||
|
custom: {
|
||||||
|
showError: true,
|
||||||
|
showLoading: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得商品结算信息
|
||||||
|
getSettlementProduct: (spuIds) => {
|
||||||
|
return request({
|
||||||
|
url: '/trade/order/settlement-product',
|
||||||
|
method: 'GET',
|
||||||
|
params: { spuIds },
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
showError: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 创建订单
|
||||||
|
createOrder: (data) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/order/create`,
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得订单详细:sync 是可选参数
|
||||||
|
getOrderDetail: (id, sync) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/order/get-detail`,
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
id,
|
||||||
|
sync,
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 订单列表
|
||||||
|
getOrderPage: (params) => {
|
||||||
|
return request({
|
||||||
|
url: '/trade/order/page',
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 确认收货
|
||||||
|
receiveOrder: (id) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/order/receive`,
|
||||||
|
method: 'PUT',
|
||||||
|
params: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 取消订单
|
||||||
|
cancelOrder: (id, cancelReason) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/order/cancel`,
|
||||||
|
method: 'DELETE',
|
||||||
|
params: {
|
||||||
|
id,
|
||||||
|
cancelReason
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 删除订单
|
||||||
|
deleteOrder: (id) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/order/delete`,
|
||||||
|
method: 'DELETE',
|
||||||
|
params: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得交易订单的物流轨迹
|
||||||
|
getOrderExpressTrackList: (id) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/order/get-express-track-list`,
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得交易订单数量
|
||||||
|
getOrderCount: () => {
|
||||||
|
return request({
|
||||||
|
url: '/trade/order/get-count',
|
||||||
|
method: 'GET',
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
auth: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 创建单个评论
|
||||||
|
createOrderItemComment: (data) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/order/item/create-comment`,
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 通过商户订单ID获取相关发货单列表
|
||||||
|
getListByTradeOrderId: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/delivery/order/getListByTradeOrderId',
|
||||||
|
method: 'GET',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 确认签收
|
||||||
|
confirmSign: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/delivery/sign-order/confirmSign',
|
||||||
|
method: 'POST',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 撤回取消交易订单
|
||||||
|
withdrawOrder: (id) => {
|
||||||
|
return request({
|
||||||
|
url: `/trade/order/withdraw`,
|
||||||
|
method: 'PUT',
|
||||||
|
params: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export default OrderApi;
|
||||||
196
sheep/components/countDown/index.vue
Normal file
196
sheep/components/countDown/index.vue
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
<!-- TODO 霖:是不是怎么复用 s-count-down 组件 -->
|
||||||
|
<template>
|
||||||
|
<view class="time" :style="justifyLeft">
|
||||||
|
<text class="" v-if="tipText">{{ tipText }}</text>
|
||||||
|
<text
|
||||||
|
class="styleAll p6"
|
||||||
|
v-if="isDay === true"
|
||||||
|
:style="{ background: bgColor.bgColor, color: bgColor.Color }"
|
||||||
|
>{{ day }}{{ bgColor.isDay ? '天' : '' }}</text
|
||||||
|
>
|
||||||
|
<text
|
||||||
|
class="timeTxt"
|
||||||
|
v-if="dayText"
|
||||||
|
:style="{ width: bgColor.timeTxtwidth, color: bgColor.bgColor }"
|
||||||
|
>{{ dayText }}</text
|
||||||
|
>
|
||||||
|
<text
|
||||||
|
class="styleAll"
|
||||||
|
:class="isCol ? 'timeCol' : ''"
|
||||||
|
:style="{ background: bgColor.bgColor, color: bgColor.Color, width: bgColor.width }"
|
||||||
|
>{{ hour }}</text
|
||||||
|
>
|
||||||
|
<text
|
||||||
|
class="timeTxt"
|
||||||
|
v-if="hourText"
|
||||||
|
:class="isCol ? 'whit' : ''"
|
||||||
|
:style="{ width: bgColor.timeTxtwidth, color: bgColor.bgColor }"
|
||||||
|
>{{ hourText }}</text
|
||||||
|
>
|
||||||
|
<text
|
||||||
|
class="styleAll"
|
||||||
|
:class="isCol ? 'timeCol' : ''"
|
||||||
|
:style="{ background: bgColor.bgColor, color: bgColor.Color, width: bgColor.width }"
|
||||||
|
>{{ minute }}</text
|
||||||
|
>
|
||||||
|
<text
|
||||||
|
class="timeTxt"
|
||||||
|
v-if="minuteText"
|
||||||
|
:class="isCol ? 'whit' : ''"
|
||||||
|
:style="{ width: bgColor.timeTxtwidth, color: bgColor.bgColor }"
|
||||||
|
>{{ minuteText }}</text
|
||||||
|
>
|
||||||
|
<text
|
||||||
|
class="styleAll"
|
||||||
|
:class="isCol ? 'timeCol' : ''"
|
||||||
|
:style="{ background: bgColor.bgColor, color: bgColor.Color, width: bgColor.width }"
|
||||||
|
>{{ second }}</text
|
||||||
|
>
|
||||||
|
<text class="timeTxt" v-if="secondText">{{ secondText }}</text>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'countDown',
|
||||||
|
props: {
|
||||||
|
justifyLeft: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
//距离开始提示文字
|
||||||
|
tipText: {
|
||||||
|
type: String,
|
||||||
|
default: '倒计时',
|
||||||
|
},
|
||||||
|
dayText: {
|
||||||
|
type: String,
|
||||||
|
default: '天',
|
||||||
|
},
|
||||||
|
hourText: {
|
||||||
|
type: String,
|
||||||
|
default: '时',
|
||||||
|
},
|
||||||
|
minuteText: {
|
||||||
|
type: String,
|
||||||
|
default: '分',
|
||||||
|
},
|
||||||
|
secondText: {
|
||||||
|
type: String,
|
||||||
|
default: '秒',
|
||||||
|
},
|
||||||
|
datatime: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
isDay: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
isCol: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
bgColor: {
|
||||||
|
type: Object,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data: function () {
|
||||||
|
return {
|
||||||
|
day: '00',
|
||||||
|
hour: '00',
|
||||||
|
minute: '00',
|
||||||
|
second: '00',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
created: function () {
|
||||||
|
this.show_time();
|
||||||
|
},
|
||||||
|
mounted: function () {},
|
||||||
|
methods: {
|
||||||
|
show_time: function () {
|
||||||
|
let that = this;
|
||||||
|
|
||||||
|
function runTime() {
|
||||||
|
//时间函数
|
||||||
|
let intDiff = that.datatime - Date.parse(new Date()) / 1000; //获取数据中的时间戳的时间差;
|
||||||
|
let day = 0,
|
||||||
|
hour = 0,
|
||||||
|
minute = 0,
|
||||||
|
second = 0;
|
||||||
|
if (intDiff > 0) {
|
||||||
|
//转换时间
|
||||||
|
if (that.isDay === true) {
|
||||||
|
day = Math.floor(intDiff / (60 * 60 * 24));
|
||||||
|
} else {
|
||||||
|
day = 0;
|
||||||
|
}
|
||||||
|
hour = Math.floor(intDiff / (60 * 60)) - day * 24;
|
||||||
|
minute = Math.floor(intDiff / 60) - day * 24 * 60 - hour * 60;
|
||||||
|
second = Math.floor(intDiff) - day * 24 * 60 * 60 - hour * 60 * 60 - minute * 60;
|
||||||
|
if (hour <= 9) hour = '0' + hour;
|
||||||
|
if (minute <= 9) minute = '0' + minute;
|
||||||
|
if (second <= 9) second = '0' + second;
|
||||||
|
that.day = day;
|
||||||
|
that.hour = hour;
|
||||||
|
that.minute = minute;
|
||||||
|
that.second = second;
|
||||||
|
} else {
|
||||||
|
that.day = '00';
|
||||||
|
that.hour = '00';
|
||||||
|
that.minute = '00';
|
||||||
|
that.second = '00';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
runTime();
|
||||||
|
setInterval(runTime, 1000);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.p6 {
|
||||||
|
padding: 0 8rpx;
|
||||||
|
}
|
||||||
|
.styleAll {
|
||||||
|
/* color: #fff; */
|
||||||
|
font-size: 24rpx;
|
||||||
|
height: 36rpx;
|
||||||
|
line-height: 36rpx;
|
||||||
|
border-radius: 6rpx;
|
||||||
|
text-align: center;
|
||||||
|
/* padding: 0 6rpx; */
|
||||||
|
}
|
||||||
|
.timeTxt {
|
||||||
|
text-align: center;
|
||||||
|
/* width: 16rpx; */
|
||||||
|
height: 36rpx;
|
||||||
|
line-height: 36rpx;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
.whit {
|
||||||
|
color: #fff !important;
|
||||||
|
}
|
||||||
|
.time {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.red {
|
||||||
|
color: #fc4141;
|
||||||
|
margin: 0 4rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeCol {
|
||||||
|
/* width: 40rpx;
|
||||||
|
height: 40rpx;
|
||||||
|
line-height: 40rpx;
|
||||||
|
text-align:center;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #fff;
|
||||||
|
font-size: 24rpx; */
|
||||||
|
color: #e93323;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
108
sheep/components/s-auth-modal/components/account-login.vue
Normal file
108
sheep/components/s-auth-modal/components/account-login.vue
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
<!-- 账号密码登录 accountLogin -->
|
||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<!-- 标题栏 -->
|
||||||
|
<view class="head-box ss-m-b-60">
|
||||||
|
<view class="ss-m-b-20">
|
||||||
|
<!-- <view class="head-title-active head-title-line" @tap="showAuthModal('smsLogin')">
|
||||||
|
短信登录
|
||||||
|
</view> -->
|
||||||
|
<view class="head-title head-title-animation">登录账号</view>
|
||||||
|
</view>
|
||||||
|
<view class="head-subtitle">如无账号请联系平台开通</view>
|
||||||
|
<!-- <view class="head-subtitle">如果未设置过密码,请点击忘记密码</view> -->
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 表单项 -->
|
||||||
|
<uni-forms
|
||||||
|
ref="accountLoginRef"
|
||||||
|
v-model="state.model"
|
||||||
|
:rules="state.rules"
|
||||||
|
validateTrigger="bind"
|
||||||
|
labelWidth="140"
|
||||||
|
labelAlign="center"
|
||||||
|
>
|
||||||
|
<uni-forms-item name="mobile" label="账号">
|
||||||
|
<uni-easyinput placeholder="请输入手机号" v-model="state.model.mobile" :inputBorder="false">
|
||||||
|
<!-- <template v-slot:right>
|
||||||
|
<button class="ss-reset-button forgot-btn" @tap="showAuthModal('resetPassword')">
|
||||||
|
忘记密码
|
||||||
|
</button>
|
||||||
|
</template> -->
|
||||||
|
</uni-easyinput>
|
||||||
|
</uni-forms-item>
|
||||||
|
|
||||||
|
<uni-forms-item name="password" label="密码">
|
||||||
|
<uni-easyinput
|
||||||
|
type="password"
|
||||||
|
placeholder="请输入密码"
|
||||||
|
v-model="state.model.password"
|
||||||
|
:inputBorder="false"
|
||||||
|
>
|
||||||
|
<template v-slot:right>
|
||||||
|
<button class="ss-reset-button login-btn-start" @tap="accountLoginSubmit">登录</button>
|
||||||
|
</template>
|
||||||
|
</uni-easyinput>
|
||||||
|
</uni-forms-item>
|
||||||
|
</uni-forms>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, reactive, unref } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import { mobile, password } from '@/sheep/validate/form';
|
||||||
|
import { showAuthModal, closeAuthModal } from '@/sheep/hooks/useModal';
|
||||||
|
import AuthUtil from '@/sheep/api/member/auth';
|
||||||
|
|
||||||
|
const accountLoginRef = ref(null);
|
||||||
|
|
||||||
|
const emits = defineEmits(['onConfirm']);
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
agreeStatus: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 数据
|
||||||
|
const state = reactive({
|
||||||
|
model: {
|
||||||
|
mobile: '', // 账号
|
||||||
|
password: '', // 密码
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
mobile,
|
||||||
|
password,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 账号登录
|
||||||
|
async function accountLoginSubmit() {
|
||||||
|
// 表单验证
|
||||||
|
const validate = await unref(accountLoginRef)
|
||||||
|
.validate()
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('error: ', error);
|
||||||
|
});
|
||||||
|
if (!validate) return;
|
||||||
|
|
||||||
|
// 同意协议
|
||||||
|
if (!props.agreeStatus) {
|
||||||
|
emits('onConfirm', true)
|
||||||
|
sheep.$helper.toast('请勾选同意');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提交数据
|
||||||
|
const { code, data } = await AuthUtil.login(state.model);
|
||||||
|
if (code === 0) {
|
||||||
|
closeAuthModal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import '../index.scss';
|
||||||
|
</style>
|
||||||
127
sheep/components/s-auth-modal/components/change-mobile.vue
Normal file
127
sheep/components/s-auth-modal/components/change-mobile.vue
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
<!-- 绑定/更换手机号 changeMobile -->
|
||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<!-- 标题栏 -->
|
||||||
|
<view class="head-box ss-m-b-60">
|
||||||
|
<view class="head-title ss-m-b-20">
|
||||||
|
{{ userInfo.mobile ? '更换手机号' : '绑定手机号' }}
|
||||||
|
</view>
|
||||||
|
<view class="head-subtitle">为了您的账号安全,请使用本人手机号码</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 表单项 -->
|
||||||
|
<uni-forms
|
||||||
|
ref="changeMobileRef"
|
||||||
|
v-model="state.model"
|
||||||
|
:rules="state.rules"
|
||||||
|
validateTrigger="bind"
|
||||||
|
labelWidth="140"
|
||||||
|
labelAlign="center"
|
||||||
|
>
|
||||||
|
<uni-forms-item name="mobile" label="手机号">
|
||||||
|
<uni-easyinput
|
||||||
|
placeholder="请输入手机号"
|
||||||
|
v-model="state.model.mobile"
|
||||||
|
:inputBorder="false"
|
||||||
|
type="number"
|
||||||
|
>
|
||||||
|
<template v-slot:right>
|
||||||
|
<button
|
||||||
|
class="ss-reset-button code-btn-start"
|
||||||
|
:disabled="state.isMobileEnd"
|
||||||
|
:class="{ 'code-btn-end': state.isMobileEnd }"
|
||||||
|
@tap="getSmsCode('changeMobile', state.model.mobile)"
|
||||||
|
>
|
||||||
|
{{ getSmsTimer('changeMobile') }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</uni-easyinput>
|
||||||
|
</uni-forms-item>
|
||||||
|
|
||||||
|
<uni-forms-item name="code" label="验证码">
|
||||||
|
<uni-easyinput
|
||||||
|
placeholder="请输入验证码"
|
||||||
|
v-model="state.model.code"
|
||||||
|
:inputBorder="false"
|
||||||
|
type="number"
|
||||||
|
maxlength="4"
|
||||||
|
>
|
||||||
|
<template v-slot:right>
|
||||||
|
<button class="ss-reset-button login-btn-start" @tap="changeMobileSubmit">
|
||||||
|
确认
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</uni-easyinput>
|
||||||
|
</uni-forms-item>
|
||||||
|
</uni-forms>
|
||||||
|
|
||||||
|
<!-- 微信独有:读取手机号 -->
|
||||||
|
<button
|
||||||
|
v-if="'WechatMiniProgram' === sheep.$platform.name"
|
||||||
|
class="ss-reset-button type-btn"
|
||||||
|
open-type="getPhoneNumber"
|
||||||
|
@getphonenumber="getPhoneNumber"
|
||||||
|
>
|
||||||
|
使用微信手机号
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed, ref, reactive, unref } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import { code, mobile } from '@/sheep/validate/form';
|
||||||
|
import { closeAuthModal, getSmsCode, getSmsTimer } from '@/sheep/hooks/useModal';
|
||||||
|
import UserApi from '@/sheep/api/member/user';
|
||||||
|
|
||||||
|
const changeMobileRef = ref(null);
|
||||||
|
const userInfo = computed(() => sheep.$store('user').userInfo);
|
||||||
|
|
||||||
|
// 数据
|
||||||
|
const state = reactive({
|
||||||
|
isMobileEnd: false, // 手机号输入完毕
|
||||||
|
model: {
|
||||||
|
mobile: '', // 手机号
|
||||||
|
code: '', // 验证码
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
code,
|
||||||
|
mobile,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 绑定手机号
|
||||||
|
async function changeMobileSubmit() {
|
||||||
|
const validate = await unref(changeMobileRef)
|
||||||
|
.validate()
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('error: ', error);
|
||||||
|
});
|
||||||
|
if (!validate) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 提交更新请求
|
||||||
|
const { code } = await UserApi.updateUserMobile(state.model);
|
||||||
|
if (code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sheep.$store('user').getInfo();
|
||||||
|
closeAuthModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用微信手机号
|
||||||
|
async function getPhoneNumber(e) {
|
||||||
|
if (e.detail.errMsg !== 'getPhoneNumber:ok') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await sheep.$platform.useProvider().bindUserPhoneNumber(e.detail);
|
||||||
|
if (result) {
|
||||||
|
sheep.$store('user').getInfo();
|
||||||
|
closeAuthModal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import '../index.scss';
|
||||||
|
</style>
|
||||||
113
sheep/components/s-auth-modal/components/change-password.vue
Normal file
113
sheep/components/s-auth-modal/components/change-password.vue
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
<!-- 修改密码(登录时) -->
|
||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<!-- 标题栏 -->
|
||||||
|
<view class="head-box ss-m-b-60">
|
||||||
|
<view class="head-title ss-m-b-20 head-title-animation text-bold">修改密码</view>
|
||||||
|
<view class="head-subtitle">您目前的登录密码为初始密码,为了您的账号安全,请对您的密码进行修改。</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 表单项 -->
|
||||||
|
<uni-forms
|
||||||
|
ref="changePasswordRef"
|
||||||
|
v-model="state.model"
|
||||||
|
:rules="state.rules"
|
||||||
|
validateTrigger="bind"
|
||||||
|
labelWidth="140"
|
||||||
|
labelAlign="center"
|
||||||
|
>
|
||||||
|
<uni-forms-item name="reNewPassword" label="手机号">
|
||||||
|
<uni-easyinput
|
||||||
|
type="number"
|
||||||
|
placeholder="请输入手机号"
|
||||||
|
v-model="state.model.mobile"
|
||||||
|
:inputBorder="false"
|
||||||
|
maxlength="11"
|
||||||
|
>
|
||||||
|
</uni-easyinput>
|
||||||
|
</uni-forms-item>
|
||||||
|
|
||||||
|
<uni-forms-item name="reNewPassword" label="新密码">
|
||||||
|
<uni-easyinput
|
||||||
|
type="password"
|
||||||
|
placeholder="请输入新密码"
|
||||||
|
v-model="state.model.newPassword"
|
||||||
|
:inputBorder="false"
|
||||||
|
maxlength="16"
|
||||||
|
>
|
||||||
|
</uni-easyinput>
|
||||||
|
</uni-forms-item>
|
||||||
|
|
||||||
|
<uni-forms-item name="reNewPassword" label="确认密码">
|
||||||
|
<uni-easyinput
|
||||||
|
type="password"
|
||||||
|
placeholder="请重新输入新密码进行确认"
|
||||||
|
v-model="state.model.ackPassword"
|
||||||
|
:inputBorder="false"
|
||||||
|
maxlength="16"
|
||||||
|
>
|
||||||
|
<template v-slot:right>
|
||||||
|
<button class="ss-reset-button login-btn-start" @tap="changePasswordSubmit">
|
||||||
|
确认
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</uni-easyinput>
|
||||||
|
</uni-forms-item>
|
||||||
|
</uni-forms>
|
||||||
|
|
||||||
|
<button class="ss-reset-button type-btn" @tap="closeAuthModal">
|
||||||
|
取消修改
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, reactive, unref } from 'vue';
|
||||||
|
import { ackPassword, newPassword, mobile } from '@/sheep/validate/form';
|
||||||
|
import { closeAuthModal, getSmsCode, getSmsTimer } from '@/sheep/hooks/useModal';
|
||||||
|
import UserApi from '@/sheep/api/member/user';
|
||||||
|
|
||||||
|
const changePasswordRef = ref(null);
|
||||||
|
|
||||||
|
// 数据
|
||||||
|
const state = reactive({
|
||||||
|
model: {
|
||||||
|
mobile: '', // 手机号
|
||||||
|
newPassword: '', // 密码
|
||||||
|
ackPassword: '', // 密码
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
mobile,
|
||||||
|
newPassword,
|
||||||
|
ackPassword
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 更改密码
|
||||||
|
async function changePasswordSubmit() {
|
||||||
|
// 参数校验
|
||||||
|
const validate = await unref(changePasswordRef)
|
||||||
|
.validate()
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('error: ', error);
|
||||||
|
});
|
||||||
|
if (!validate) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 发起请求
|
||||||
|
const { code } = await UserApi.updateUserPasswordReset(state.model);
|
||||||
|
if (code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 成功后,只需要关闭弹窗
|
||||||
|
closeAuthModal();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import '../index.scss';
|
||||||
|
|
||||||
|
.text-bold {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
152
sheep/components/s-auth-modal/components/mp-authorization.vue
Normal file
152
sheep/components/s-auth-modal/components/mp-authorization.vue
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
<!-- 微信授权信息 mpAuthorization -->
|
||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<!-- 标题栏 -->
|
||||||
|
<view class="head-box ss-m-b-60 ss-flex-col">
|
||||||
|
<view class="ss-flex ss-m-b-20">
|
||||||
|
<view class="head-title ss-m-r-40 head-title-animation">授权信息</view>
|
||||||
|
</view>
|
||||||
|
<view class="head-subtitle">完善您的头像、昵称、手机号</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 表单项 -->
|
||||||
|
<uni-forms
|
||||||
|
ref="accountLoginRef"
|
||||||
|
v-model="state.model"
|
||||||
|
:rules="state.rules"
|
||||||
|
validateTrigger="bind"
|
||||||
|
labelWidth="140"
|
||||||
|
labelAlign="center"
|
||||||
|
>
|
||||||
|
<!-- 获取头像昵称:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/userProfile.html -->
|
||||||
|
<uni-forms-item name="avatar" label="头像">
|
||||||
|
<button
|
||||||
|
class="ss-reset-button avatar-btn"
|
||||||
|
open-type="chooseAvatar"
|
||||||
|
@chooseavatar="onChooseAvatar"
|
||||||
|
>
|
||||||
|
<image
|
||||||
|
class="avatar-img"
|
||||||
|
:src="sheep.$url.cdn(state.model.avatar)"
|
||||||
|
mode="aspectFill"
|
||||||
|
@tap="sheep.$router.go('/pages/user/info')"
|
||||||
|
/>
|
||||||
|
<text class="cicon-forward" />
|
||||||
|
</button>
|
||||||
|
</uni-forms-item>
|
||||||
|
<uni-forms-item name="nickname" label="昵称">
|
||||||
|
<uni-easyinput
|
||||||
|
type="nickname"
|
||||||
|
placeholder="请输入昵称"
|
||||||
|
v-model="state.model.nickname"
|
||||||
|
:inputBorder="false"
|
||||||
|
/>
|
||||||
|
</uni-forms-item>
|
||||||
|
<view class="foot-box">
|
||||||
|
<button class="ss-reset-button authorization-btn" @tap="onConfirm"> 确认授权 </button>
|
||||||
|
</view>
|
||||||
|
</uni-forms>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed, ref, reactive } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import { closeAuthModal } from '@/sheep/hooks/useModal';
|
||||||
|
import FileApi from '@/sheep/api/infra/file';
|
||||||
|
import UserApi from '@/sheep/api/member/user';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
agreeStatus: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const userInfo = computed(() => sheep.$store('user').userInfo);
|
||||||
|
|
||||||
|
const accountLoginRef = ref(null);
|
||||||
|
|
||||||
|
// 数据
|
||||||
|
const state = reactive({
|
||||||
|
model: {
|
||||||
|
nickname: userInfo.value.nickname,
|
||||||
|
avatar: userInfo.value.avatar,
|
||||||
|
},
|
||||||
|
rules: {},
|
||||||
|
disabledStyle: {
|
||||||
|
color: '#999',
|
||||||
|
disableColor: '#fff',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 选择头像(来自微信)
|
||||||
|
function onChooseAvatar(e) {
|
||||||
|
const tempUrl = e.detail.avatarUrl || '';
|
||||||
|
uploadAvatar(tempUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选择头像(来自文件系统)
|
||||||
|
async function uploadAvatar(tempUrl) {
|
||||||
|
if (!tempUrl) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let { data } = await FileApi.uploadFile(tempUrl);
|
||||||
|
state.model.avatar = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确认授权
|
||||||
|
async function onConfirm() {
|
||||||
|
const { model } = state;
|
||||||
|
const { nickname, avatar } = model;
|
||||||
|
if (!nickname) {
|
||||||
|
sheep.$helper.toast('请输入昵称');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!avatar) {
|
||||||
|
sheep.$helper.toast('请选择头像');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 发起更新
|
||||||
|
const { code } = await UserApi.updateUser({
|
||||||
|
avatar: state.model.avatar,
|
||||||
|
nickname: state.model.nickname,
|
||||||
|
});
|
||||||
|
// 更新成功
|
||||||
|
if (code === 0) {
|
||||||
|
sheep.$helper.toast('授权成功');
|
||||||
|
await sheep.$store('user').getInfo();
|
||||||
|
closeAuthModal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import '../index.scss';
|
||||||
|
|
||||||
|
.foot-box {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.authorization-btn {
|
||||||
|
width: 686rpx;
|
||||||
|
height: 80rpx;
|
||||||
|
background-color: var(--ui-BG-Main);
|
||||||
|
border-radius: 40rpx;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.avatar-img {
|
||||||
|
width: 72rpx;
|
||||||
|
height: 72rpx;
|
||||||
|
border-radius: 36rpx;
|
||||||
|
}
|
||||||
|
.cicon-forward {
|
||||||
|
font-size: 30rpx;
|
||||||
|
color: #595959;
|
||||||
|
}
|
||||||
|
.avatar-btn {
|
||||||
|
width: 100%;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
119
sheep/components/s-auth-modal/components/reset-password.vue
Normal file
119
sheep/components/s-auth-modal/components/reset-password.vue
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<!-- 重置密码(未登录时) -->
|
||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<!-- 标题栏 -->
|
||||||
|
<view class="head-box ss-m-b-60">
|
||||||
|
<view class="head-title ss-m-b-20">重置密码</view>
|
||||||
|
<view class="head-subtitle">为了您的账号安全,设置密码前请先进行安全验证</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 表单项 -->
|
||||||
|
<uni-forms
|
||||||
|
ref="resetPasswordRef"
|
||||||
|
v-model="state.model"
|
||||||
|
:rules="state.rules"
|
||||||
|
validateTrigger="bind"
|
||||||
|
labelWidth="140"
|
||||||
|
labelAlign="center"
|
||||||
|
>
|
||||||
|
<uni-forms-item name="mobile" label="手机号">
|
||||||
|
<uni-easyinput
|
||||||
|
placeholder="请输入手机号"
|
||||||
|
v-model="state.model.mobile"
|
||||||
|
type="number"
|
||||||
|
:inputBorder="false"
|
||||||
|
>
|
||||||
|
<template v-slot:right>
|
||||||
|
<button
|
||||||
|
class="ss-reset-button code-btn code-btn-start"
|
||||||
|
:disabled="state.isMobileEnd"
|
||||||
|
:class="{ 'code-btn-end': state.isMobileEnd }"
|
||||||
|
@tap="getSmsCode('resetPassword', state.model.mobile)"
|
||||||
|
>
|
||||||
|
{{ getSmsTimer('resetPassword') }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</uni-easyinput>
|
||||||
|
</uni-forms-item>
|
||||||
|
|
||||||
|
<uni-forms-item name="code" label="验证码">
|
||||||
|
<uni-easyinput
|
||||||
|
placeholder="请输入验证码"
|
||||||
|
v-model="state.model.code"
|
||||||
|
type="number"
|
||||||
|
maxlength="4"
|
||||||
|
:inputBorder="false"
|
||||||
|
/>
|
||||||
|
</uni-forms-item>
|
||||||
|
|
||||||
|
<uni-forms-item name="password" label="密码">
|
||||||
|
<uni-easyinput
|
||||||
|
type="password"
|
||||||
|
placeholder="请输入密码"
|
||||||
|
v-model="state.model.password"
|
||||||
|
:inputBorder="false"
|
||||||
|
>
|
||||||
|
<template v-slot:right>
|
||||||
|
<button class="ss-reset-button login-btn-start" @tap="resetPasswordSubmit">
|
||||||
|
确认
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</uni-easyinput>
|
||||||
|
</uni-forms-item>
|
||||||
|
</uni-forms>
|
||||||
|
|
||||||
|
<button v-if="!isLogin" class="ss-reset-button type-btn" @tap="showAuthModal('accountLogin')">
|
||||||
|
返回登录
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed, ref, reactive, unref } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import { code, mobile, password } from '@/sheep/validate/form';
|
||||||
|
import { showAuthModal, closeAuthModal, getSmsCode, getSmsTimer } from '@/sheep/hooks/useModal';
|
||||||
|
import UserApi from '@/sheep/api/member/user';
|
||||||
|
|
||||||
|
const resetPasswordRef = ref(null);
|
||||||
|
const isLogin = computed(() => sheep.$store('user').isLogin);
|
||||||
|
|
||||||
|
// 数据
|
||||||
|
const state = reactive({
|
||||||
|
isMobileEnd: false, // 手机号输入完毕
|
||||||
|
model: {
|
||||||
|
mobile: '', // 手机号
|
||||||
|
code: '', // 验证码
|
||||||
|
password: '', // 密码
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
code,
|
||||||
|
mobile,
|
||||||
|
password,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 重置密码
|
||||||
|
const resetPasswordSubmit = async () => {
|
||||||
|
// 参数校验
|
||||||
|
const validate = await unref(resetPasswordRef)
|
||||||
|
.validate()
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('error: ', error);
|
||||||
|
});
|
||||||
|
if (!validate) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 发起请求
|
||||||
|
const { code } = await UserApi.resetUserPassword(state.model);
|
||||||
|
if (code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 成功后,用户重新登录
|
||||||
|
showAuthModal('accountLogin')
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import '../index.scss';
|
||||||
|
</style>
|
||||||
119
sheep/components/s-auth-modal/components/sms-login.vue
Normal file
119
sheep/components/s-auth-modal/components/sms-login.vue
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<!-- 短信登录 - smsLogin -->
|
||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<!-- 标题栏 -->
|
||||||
|
<view class="head-box ss-m-b-60">
|
||||||
|
<view class="ss-flex ss-m-b-20">
|
||||||
|
<view class="head-title head-title-line head-title-animation">短信登录</view>
|
||||||
|
<view class="head-title-active ss-m-r-40" @tap="showAuthModal('accountLogin')">
|
||||||
|
账号登录
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="head-subtitle">未注册的手机号,验证后自动注册账号</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 表单项 -->
|
||||||
|
<uni-forms
|
||||||
|
ref="smsLoginRef"
|
||||||
|
v-model="state.model"
|
||||||
|
:rules="state.rules"
|
||||||
|
validateTrigger="bind"
|
||||||
|
labelWidth="140"
|
||||||
|
labelAlign="center"
|
||||||
|
>
|
||||||
|
<uni-forms-item name="mobile" label="手机号">
|
||||||
|
<uni-easyinput
|
||||||
|
placeholder="请输入手机号"
|
||||||
|
v-model="state.model.mobile"
|
||||||
|
:inputBorder="false"
|
||||||
|
type="number"
|
||||||
|
>
|
||||||
|
<template v-slot:right>
|
||||||
|
<button
|
||||||
|
class="ss-reset-button code-btn code-btn-start"
|
||||||
|
:disabled="state.isMobileEnd"
|
||||||
|
:class="{ 'code-btn-end': state.isMobileEnd }"
|
||||||
|
@tap="getSmsCode('smsLogin', state.model.mobile)"
|
||||||
|
>
|
||||||
|
{{ getSmsTimer('smsLogin') }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</uni-easyinput>
|
||||||
|
</uni-forms-item>
|
||||||
|
|
||||||
|
<uni-forms-item name="code" label="验证码">
|
||||||
|
<uni-easyinput
|
||||||
|
placeholder="请输入验证码"
|
||||||
|
v-model="state.model.code"
|
||||||
|
:inputBorder="false"
|
||||||
|
type="number"
|
||||||
|
maxlength="4"
|
||||||
|
>
|
||||||
|
<template v-slot:right>
|
||||||
|
<button class="ss-reset-button login-btn-start" @tap="smsLoginSubmit"> 登录 </button>
|
||||||
|
</template>
|
||||||
|
</uni-easyinput>
|
||||||
|
</uni-forms-item>
|
||||||
|
</uni-forms>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, reactive, unref } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import { code, mobile } from '@/sheep/validate/form';
|
||||||
|
import { showAuthModal, closeAuthModal, getSmsCode, getSmsTimer } from '@/sheep/hooks/useModal';
|
||||||
|
import AuthUtil from '@/sheep/api/member/auth';
|
||||||
|
|
||||||
|
const smsLoginRef = ref(null);
|
||||||
|
|
||||||
|
const emits = defineEmits(['onConfirm']);
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
agreeStatus: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 数据
|
||||||
|
const state = reactive({
|
||||||
|
isMobileEnd: false, // 手机号输入完毕
|
||||||
|
codeText: '获取验证码',
|
||||||
|
model: {
|
||||||
|
mobile: '', // 手机号
|
||||||
|
code: '', // 验证码
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
code,
|
||||||
|
mobile,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 短信登录
|
||||||
|
async function smsLoginSubmit() {
|
||||||
|
// 参数校验
|
||||||
|
const validate = await unref(smsLoginRef)
|
||||||
|
.validate()
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('error: ', error);
|
||||||
|
});
|
||||||
|
if (!validate) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!props.agreeStatus) {
|
||||||
|
emits('onConfirm', true)
|
||||||
|
sheep.$helper.toast('请勾选同意');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 提交数据
|
||||||
|
const { code } = await AuthUtil.smsLogin(state.model);
|
||||||
|
if (code === 0) {
|
||||||
|
closeAuthModal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import '../index.scss';
|
||||||
|
</style>
|
||||||
156
sheep/components/s-auth-modal/index.scss
Normal file
156
sheep/components/s-auth-modal/index.scss
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
@keyframes title-animation {
|
||||||
|
0% {
|
||||||
|
font-size: 32rpx;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
font-size: 36rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-wrap {
|
||||||
|
padding: 50rpx 34rpx;
|
||||||
|
min-height: 500rpx;
|
||||||
|
background-color: #fff;
|
||||||
|
border-radius: 20rpx 20rpx 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.head-box {
|
||||||
|
.head-title {
|
||||||
|
min-width: 160rpx;
|
||||||
|
font-size: 36rpx;
|
||||||
|
// font-weight: bold;
|
||||||
|
color: #333333;
|
||||||
|
font-weight: 500;
|
||||||
|
line-height: 36rpx;
|
||||||
|
}
|
||||||
|
.head-title-active {
|
||||||
|
width: 160rpx;
|
||||||
|
font-size: 32rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #999;
|
||||||
|
line-height: 36rpx;
|
||||||
|
}
|
||||||
|
.head-title-animation {
|
||||||
|
text-align: center;
|
||||||
|
animation-name: title-animation;
|
||||||
|
animation-duration: 0.1s;
|
||||||
|
animation-timing-function: ease-out;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
.head-title-line {
|
||||||
|
position: relative;
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
width: 1rpx;
|
||||||
|
height: 34rpx;
|
||||||
|
background-color: #e4e7ed;
|
||||||
|
position: absolute;
|
||||||
|
left: -30rpx;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.head-subtitle {
|
||||||
|
// font-size: 26rpx;
|
||||||
|
font-weight: 400;
|
||||||
|
// color: #afb6c0;
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #999999;
|
||||||
|
// text-align: left;
|
||||||
|
text-align: center;
|
||||||
|
// display: flex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// .code-btn[disabled] {
|
||||||
|
// background-color: #fff;
|
||||||
|
// }
|
||||||
|
.code-btn-start {
|
||||||
|
width: 160rpx;
|
||||||
|
height: 56rpx;
|
||||||
|
line-height: normal;
|
||||||
|
border: 2rpx solid var(--ui-BG-Main);
|
||||||
|
border-radius: 28rpx;
|
||||||
|
font-size: 26rpx;
|
||||||
|
font-weight: 400;
|
||||||
|
color: var(--ui-BG-Main);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forgot-btn {
|
||||||
|
width: 160rpx;
|
||||||
|
line-height: 56rpx;
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-btn-start {
|
||||||
|
width: 158rpx;
|
||||||
|
height: 56rpx;
|
||||||
|
line-height: normal;
|
||||||
|
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
|
||||||
|
border-radius: 28rpx;
|
||||||
|
font-size: 26rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.type-btn {
|
||||||
|
padding: 20rpx;
|
||||||
|
margin: 40rpx auto;
|
||||||
|
width: 200rpx;
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #999999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auto-login-box {
|
||||||
|
width: 100%;
|
||||||
|
.auto-login-btn {
|
||||||
|
width: 68rpx;
|
||||||
|
height: 68rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
margin: 0 30rpx;
|
||||||
|
}
|
||||||
|
.auto-login-img {
|
||||||
|
width: 68rpx;
|
||||||
|
height: 68rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.agreement-box {
|
||||||
|
margin: 80rpx auto 0;
|
||||||
|
.protocol-check {
|
||||||
|
transform: scale(0.7);
|
||||||
|
}
|
||||||
|
.agreement-text {
|
||||||
|
font-size: 26rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #999999;
|
||||||
|
.tcp-text {
|
||||||
|
color: var(--ui-BG-Main);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改密码
|
||||||
|
.editPwd-btn-box {
|
||||||
|
.save-btn {
|
||||||
|
width: 690rpx;
|
||||||
|
line-height: 70rpx;
|
||||||
|
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
|
||||||
|
border-radius: 35rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
.forgot-btn {
|
||||||
|
width: 690rpx;
|
||||||
|
line-height: 70rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #999999;
|
||||||
|
}
|
||||||
|
}
|
||||||
251
sheep/components/s-auth-modal/s-auth-modal.vue
Normal file
251
sheep/components/s-auth-modal/s-auth-modal.vue
Normal file
@@ -0,0 +1,251 @@
|
|||||||
|
<template>
|
||||||
|
<!-- 规格弹窗 -->
|
||||||
|
<su-popup :show="authType !== ''" round="10" :showClose="true" @close="closeAuthModal">
|
||||||
|
<view class="login-wrap main-blue">
|
||||||
|
<!-- 1. 账号密码登录 accountLogin -->
|
||||||
|
<account-login
|
||||||
|
v-if="authType === 'accountLogin'"
|
||||||
|
:agreeStatus="state.protocol"
|
||||||
|
@onConfirm="onConfirm"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- 2. 短信登录 smsLogin -->
|
||||||
|
<!-- <sms-login
|
||||||
|
v-if="authType === 'smsLogin'"
|
||||||
|
:agreeStatus="state.protocol"
|
||||||
|
@onConfirm="onConfirm"
|
||||||
|
/> -->
|
||||||
|
|
||||||
|
<!-- 3. 忘记密码 resetPassword-->
|
||||||
|
<reset-password v-if="authType === 'resetPassword'" />
|
||||||
|
|
||||||
|
<!-- 4. 绑定手机号 changeMobile -->
|
||||||
|
<change-mobile v-if="authType === 'changeMobile'" />
|
||||||
|
|
||||||
|
<!-- 5. 修改密码 changePassword-->
|
||||||
|
<changePassword v-if="authType === 'changePassword'" />
|
||||||
|
|
||||||
|
<!-- 6. 微信小程序授权 -->
|
||||||
|
<mp-authorization v-if="authType === 'mpAuthorization'" />
|
||||||
|
|
||||||
|
<!-- 7. 第三方登录 -->
|
||||||
|
<view
|
||||||
|
v-if="['accountLogin', 'smsLogin'].includes(authType)"
|
||||||
|
class="auto-login-box ss-flex ss-flex-col ss-row-center ss-col-center"
|
||||||
|
>
|
||||||
|
<!-- 7.1 微信小程序的快捷登录 -->
|
||||||
|
<view v-if="sheep.$platform.name === 'WechatMiniProgram'" class="ss-flex register-box">
|
||||||
|
<!-- <view class="register-title">还没有账号?</view> -->
|
||||||
|
<view class="register-title">已经拥有账号可以,</view>
|
||||||
|
<button
|
||||||
|
class="ss-reset-button login-btn"
|
||||||
|
open-type="getPhoneNumber"
|
||||||
|
@getphonenumber="getPhoneNumber"
|
||||||
|
>
|
||||||
|
快捷登录
|
||||||
|
</button>
|
||||||
|
<view class="circle"></view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 7.2 微信的公众号、App、小程序的登录,基于 openid + code -->
|
||||||
|
<!-- <button
|
||||||
|
v-if="
|
||||||
|
['WechatOfficialAccount', 'WechatMiniProgram', 'App'].includes(sheep.$platform.name) &&
|
||||||
|
sheep.$platform.isWechatInstalled
|
||||||
|
"
|
||||||
|
@tap="thirdLogin('wechat')"
|
||||||
|
class="ss-reset-button auto-login-btn"
|
||||||
|
>
|
||||||
|
<image
|
||||||
|
class="auto-login-img"
|
||||||
|
:src="sheep.$url.static('/static/img/shop/platform/wechat.png')"
|
||||||
|
/>
|
||||||
|
</button> -->
|
||||||
|
|
||||||
|
<!-- 7.3 iOS 登录 TODO 芋艿:等后面搞 App 再弄 -->
|
||||||
|
<!-- <button
|
||||||
|
v-if="sheep.$platform.os === 'ios' && sheep.$platform.name === 'App'"
|
||||||
|
@tap="thirdLogin('apple')"
|
||||||
|
class="ss-reset-button auto-login-btn"
|
||||||
|
>
|
||||||
|
<image
|
||||||
|
class="auto-login-img"
|
||||||
|
:src="sheep.$url.static('/static/img/shop/platform/apple.png')"
|
||||||
|
/>
|
||||||
|
</button> -->
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 用户协议的勾选 -->
|
||||||
|
<view
|
||||||
|
v-if="['accountLogin', 'smsLogin'].includes(authType)"
|
||||||
|
class="agreement-box ss-flex ss-row-center"
|
||||||
|
:class="{ shake: currentProtocol }"
|
||||||
|
>
|
||||||
|
<label class="radio ss-flex ss-col-center" @tap="onChange">
|
||||||
|
<radio
|
||||||
|
:checked="state.protocol"
|
||||||
|
color="var(--ui-BG-Main)"
|
||||||
|
style="transform: scale(0.8)"
|
||||||
|
@tap.stop="onChange"
|
||||||
|
/>
|
||||||
|
<view class="agreement-text ss-flex ss-col-center ss-m-l-8">
|
||||||
|
我已阅读并同意
|
||||||
|
<view class="tcp-text" @tap.stop="onProtocol('用户协议')"> 《用户协议》 </view>
|
||||||
|
<view class="agreement-text">与</view>
|
||||||
|
<view class="tcp-text" @tap.stop="onProtocol('隐私协议')"> 《隐私协议》 </view>
|
||||||
|
</view>
|
||||||
|
</label>
|
||||||
|
</view>
|
||||||
|
<view class="safe-box" />
|
||||||
|
</view>
|
||||||
|
</su-popup>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed, reactive, ref } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import accountLogin from './components/account-login.vue';
|
||||||
|
import smsLogin from './components/sms-login.vue';
|
||||||
|
import resetPassword from './components/reset-password.vue';
|
||||||
|
import changeMobile from './components/change-mobile.vue';
|
||||||
|
import changePassword from './components/change-password.vue';
|
||||||
|
import mpAuthorization from './components/mp-authorization.vue';
|
||||||
|
import { closeAuthModal, showAuthModal } from '@/sheep/hooks/useModal';
|
||||||
|
|
||||||
|
const modalStore = sheep.$store('modal');
|
||||||
|
// 授权弹窗类型
|
||||||
|
const authType = computed(() => modalStore.auth);
|
||||||
|
// const authType = "accountLogin";
|
||||||
|
|
||||||
|
const state = reactive({
|
||||||
|
protocol: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const currentProtocol = ref(false);
|
||||||
|
|
||||||
|
// 勾选协议
|
||||||
|
function onChange() {
|
||||||
|
state.protocol = !state.protocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查看协议
|
||||||
|
function onProtocol(title) {
|
||||||
|
closeAuthModal();
|
||||||
|
sheep.$router.go('/pages/public/richtext', {
|
||||||
|
title,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 点击登录 / 注册事件
|
||||||
|
function onConfirm(e) {
|
||||||
|
currentProtocol.value = e;
|
||||||
|
setTimeout(() => {
|
||||||
|
currentProtocol.value = false;
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 第三方授权登陆(微信小程序、Apple)
|
||||||
|
const thirdLogin = async (provider) => {
|
||||||
|
if (!state.protocol) {
|
||||||
|
currentProtocol.value = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
currentProtocol.value = false;
|
||||||
|
}, 1000);
|
||||||
|
sheep.$helper.toast('请勾选同意');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const loginRes = await sheep.$platform.useProvider(provider).login();
|
||||||
|
if (loginRes) {
|
||||||
|
const userInfo = await sheep.$store('user').getInfo();
|
||||||
|
closeAuthModal();
|
||||||
|
// 如果用户已经有头像和昵称,不需要再次授权
|
||||||
|
if (userInfo.avatar && userInfo.nickname) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 触发小程序授权信息弹框
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
showAuthModal('mpAuthorization');
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 微信小程序的“手机号快速验证”:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html
|
||||||
|
const getPhoneNumber = async (e) => {
|
||||||
|
if (e.detail.errMsg !== 'getPhoneNumber:ok') {
|
||||||
|
sheep.$helper.toast('快捷登录失败');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log("e", e);
|
||||||
|
let result = await sheep.$platform.useProvider().mobileLogin(e.detail);
|
||||||
|
console.log("result", result);
|
||||||
|
if (result) {
|
||||||
|
closeAuthModal();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import './index.scss';
|
||||||
|
|
||||||
|
.shake {
|
||||||
|
animation: shake 0.05s linear 4 alternate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes shake {
|
||||||
|
from {
|
||||||
|
transform: translateX(-10rpx);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: translateX(10rpx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.register-box {
|
||||||
|
position: relative;
|
||||||
|
justify-content: center;
|
||||||
|
.register-btn {
|
||||||
|
color: #999999;
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.register-title {
|
||||||
|
color: #999999;
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: 400;
|
||||||
|
margin-right: 24rpx;
|
||||||
|
}
|
||||||
|
.or-title {
|
||||||
|
margin: 0 16rpx;
|
||||||
|
color: #999999;
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
.login-btn {
|
||||||
|
color: var(--ui-BG-Main);
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.circle {
|
||||||
|
position: absolute;
|
||||||
|
right: 0rpx;
|
||||||
|
top: 18rpx;
|
||||||
|
width: 8rpx;
|
||||||
|
height: 8rpx;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
background: var(--ui-BG-Main);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.safe-box {
|
||||||
|
height: calc(constant(safe-area-inset-bottom) / 5 * 3);
|
||||||
|
height: calc(env(safe-area-inset-bottom) / 5 * 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tcp-text {
|
||||||
|
color: var(--ui-BG-Main);
|
||||||
|
}
|
||||||
|
|
||||||
|
.agreement-text {
|
||||||
|
color: $dark-9;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
69
sheep/components/s-custom-navbar/components/navbar-item.vue
Normal file
69
sheep/components/s-custom-navbar/components/navbar-item.vue
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<!-- 顶部导航栏 - 单元格 -->
|
||||||
|
<template>
|
||||||
|
<view class="ss-flex ss-col-center">
|
||||||
|
<!-- 类型一: 文字 -->
|
||||||
|
<view
|
||||||
|
v-if="data.type === 'text'"
|
||||||
|
class="nav-title inline"
|
||||||
|
:style="[{ color: data.textColor, width: width }]"
|
||||||
|
>
|
||||||
|
{{ data.text }}
|
||||||
|
</view>
|
||||||
|
<!-- 类型二: 图片 -->
|
||||||
|
<view
|
||||||
|
v-if="data.type === 'image'"
|
||||||
|
:style="[{ width: width }]"
|
||||||
|
class="menu-icon-wrap ss-flex ss-row-center ss-col-center"
|
||||||
|
@tap="sheep.$router.go(data.url)"
|
||||||
|
>
|
||||||
|
<image class="nav-image radius-img" v-if="data.imgUrl == imgSrc" :src="userInfo.avatar?userInfo.avatar:defautAvatar" mode="aspectFit"></image>
|
||||||
|
<image class="nav-image" v-else :src="sheep.$url.cdn(data.imgUrl)" mode="aspectFit"></image>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import { computed } from 'vue';
|
||||||
|
|
||||||
|
// 接收参数
|
||||||
|
const props = defineProps({
|
||||||
|
data: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({}),
|
||||||
|
},
|
||||||
|
width: {
|
||||||
|
type: String,
|
||||||
|
default: '1px',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const imgSrc = 'http://api.jnmall.zq-hightech.com/admin-api/infra/file/29/get/e2f8b02bae129322f99ed06226543a55a8c13226fa688017f1454508a974d7bb.png'
|
||||||
|
const defautAvatar = 'http://api.jnmall.zq-hightech.com/admin-api/infra/file/29/get/e2f8b02bae129322f99ed06226543a55a8c13226fa688017f1454508a974d7bb.png'
|
||||||
|
const userInfo = computed(() => sheep.$store('user').userInfo);
|
||||||
|
|
||||||
|
|
||||||
|
const height = computed(() => sheep.$platform.capsule.height);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.nav-title {
|
||||||
|
font-size: 36rpx;
|
||||||
|
color: #333;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-icon-wrap {
|
||||||
|
.nav-image {
|
||||||
|
// height: 24px;
|
||||||
|
height: 65rpx;
|
||||||
|
width: 65rpx;
|
||||||
|
border-radius: 50% !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.radius-img {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
314
sheep/components/s-custom-navbar/components/navbar.vue
Normal file
314
sheep/components/s-custom-navbar/components/navbar.vue
Normal file
@@ -0,0 +1,314 @@
|
|||||||
|
<template>
|
||||||
|
<su-fixed
|
||||||
|
:noFixed="props.noFixed"
|
||||||
|
:alway="props.alway"
|
||||||
|
:bgStyles="props.bgStyles"
|
||||||
|
:val="0"
|
||||||
|
:index="props.zIndex"
|
||||||
|
noNav
|
||||||
|
:bg="props.bg"
|
||||||
|
:ui="props.ui"
|
||||||
|
:opacity="props.opacity"
|
||||||
|
:placeholder="props.placeholder"
|
||||||
|
:sticky="props.sticky"
|
||||||
|
>
|
||||||
|
<su-status-bar />
|
||||||
|
<!--
|
||||||
|
:class="[{ 'border-bottom': !props.opacity && props.bg != 'bg-none' }]"
|
||||||
|
-->
|
||||||
|
<view class="ui-navbar-box">
|
||||||
|
<view
|
||||||
|
class="ui-bar"
|
||||||
|
:class="
|
||||||
|
props.status == '' ? `text-a` : props.status == 'light' ? 'text-white' : 'text-black'
|
||||||
|
"
|
||||||
|
:style="[{ height: sys_navBar - sys_statusBar + 'px' }]"
|
||||||
|
>
|
||||||
|
<slot name="item"></slot>
|
||||||
|
<view class="right">
|
||||||
|
<!-- #ifdef MP -->
|
||||||
|
<view :style="[state.capsuleStyle]"></view>
|
||||||
|
<!-- #endif -->
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</su-fixed>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
/**
|
||||||
|
* 标题栏 - 基础组件navbar
|
||||||
|
*
|
||||||
|
* @param {Number} zIndex = 100 - 层级
|
||||||
|
* @param {Boolean} back = true - 是否返回上一页
|
||||||
|
* @param {String} backtext = '' - 返回文本
|
||||||
|
* @param {String} bg = 'bg-white' - 公共Class
|
||||||
|
* @param {String} status = '' - 状态栏颜色
|
||||||
|
* @param {Boolean} alway = true - 是否常驻
|
||||||
|
* @param {Boolean} opacity = false - 是否开启透明渐变
|
||||||
|
* @param {Boolean} opacityBg = false - 开启滑动渐变后,返回按钮是否添加背景
|
||||||
|
* @param {Boolean} noFixed = false - 是否浮动
|
||||||
|
* @param {String} ui = '' - 公共Class
|
||||||
|
* @param {Boolean} capsule = false - 是否开启胶囊返回
|
||||||
|
* @param {Boolean} stopBack = false - 是否禁用返回
|
||||||
|
* @param {Boolean} placeholder = true - 是否开启占位
|
||||||
|
* @param {Object} bgStyles = {} - 背景样式
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { computed, reactive, onBeforeMount } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
|
||||||
|
// 本地数据
|
||||||
|
const state = reactive({
|
||||||
|
statusCur: '',
|
||||||
|
capsuleStyle: {},
|
||||||
|
capsuleBack: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
const sys_statusBar = sheep.$platform.device.statusBarHeight;
|
||||||
|
const sys_navBar = sheep.$platform.navbar;
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
sticky: Boolean,
|
||||||
|
zIndex: {
|
||||||
|
type: Number,
|
||||||
|
default: 100,
|
||||||
|
},
|
||||||
|
back: {
|
||||||
|
//是否返回上一页
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
backtext: {
|
||||||
|
//返回文本
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
bg: {
|
||||||
|
type: String,
|
||||||
|
default: 'bg-white',
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
//状态栏颜色 可以选择light dark/其他字符串视为黑色
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
// 常驻
|
||||||
|
alway: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
opacity: {
|
||||||
|
//是否开启滑动渐变
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
opacityBg: {
|
||||||
|
//开启滑动渐变后 返回按钮是否添加背景
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
noFixed: {
|
||||||
|
//是否浮动
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
ui: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
capsule: {
|
||||||
|
//是否开启胶囊返回
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
stopBack: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
placeholder: {
|
||||||
|
type: [Boolean],
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
bgStyles: {
|
||||||
|
type: Object,
|
||||||
|
default() {},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const emits = defineEmits(['navback']);
|
||||||
|
|
||||||
|
onBeforeMount(() => {
|
||||||
|
init();
|
||||||
|
});
|
||||||
|
|
||||||
|
// 返回
|
||||||
|
const onNavback = () => {
|
||||||
|
sheep.$router.back();
|
||||||
|
};
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
const init = () => {
|
||||||
|
state.capsuleStyle = {
|
||||||
|
width: sheep.$platform.capsule.width + 'px',
|
||||||
|
height: sheep.$platform.capsule.height + 'px',
|
||||||
|
margin: '0 ' + (sheep.$platform.device.windowWidth - sheep.$platform.capsule.right) + 'px',
|
||||||
|
};
|
||||||
|
|
||||||
|
state.capsuleBack = state.capsuleStyle;
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.ui-navbar-box {
|
||||||
|
background-color: transparent;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
.ui-bar {
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
|
white-space: nowrap;
|
||||||
|
display: flex;
|
||||||
|
position: relative;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
|
||||||
|
.left {
|
||||||
|
@include flex-bar;
|
||||||
|
|
||||||
|
.back {
|
||||||
|
@include flex-bar;
|
||||||
|
|
||||||
|
.back-icon {
|
||||||
|
@include flex-center;
|
||||||
|
width: 56rpx;
|
||||||
|
height: 56rpx;
|
||||||
|
margin: 0 10rpx;
|
||||||
|
font-size: 46rpx !important;
|
||||||
|
|
||||||
|
&.opacityIcon {
|
||||||
|
position: relative;
|
||||||
|
border-radius: 50%;
|
||||||
|
background-color: rgba(127, 127, 127, 0.5);
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
content: '';
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
height: 200%;
|
||||||
|
width: 200%;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
border-radius: inherit;
|
||||||
|
transform: scale(0.5);
|
||||||
|
transform-origin: 0 0;
|
||||||
|
opacity: 0.1;
|
||||||
|
border: 1px solid currentColor;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
transform: scale(0.9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #ifdef MP-ALIPAY */
|
||||||
|
._icon-back {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.capsule {
|
||||||
|
@include flex-bar;
|
||||||
|
border-radius: 100px;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&.dark {
|
||||||
|
background-color: rgba(255, 255, 255, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.light {
|
||||||
|
background-color: rgba(0, 0, 0, 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
content: '';
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
height: 60%;
|
||||||
|
width: 1px;
|
||||||
|
left: 50%;
|
||||||
|
top: 20%;
|
||||||
|
background-color: currentColor;
|
||||||
|
opacity: 0.1;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
height: 200%;
|
||||||
|
width: 200%;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
border-radius: inherit;
|
||||||
|
transform: scale(0.5);
|
||||||
|
transform-origin: 0 0;
|
||||||
|
opacity: 0.1;
|
||||||
|
border: 1px solid currentColor;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.capsule-back,
|
||||||
|
.capsule-home {
|
||||||
|
@include flex-center;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.isFristPage {
|
||||||
|
.capsule-back,
|
||||||
|
&::after {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.right {
|
||||||
|
@include flex-bar;
|
||||||
|
|
||||||
|
.right-content {
|
||||||
|
@include flex;
|
||||||
|
flex-direction: row-reverse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.center {
|
||||||
|
@include flex-center;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
text-align: center;
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
.image {
|
||||||
|
display: block;
|
||||||
|
height: 36px;
|
||||||
|
max-width: calc(100vw - 200px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.ui-bar-bg {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
top: 0;
|
||||||
|
z-index: 1;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
207
sheep/components/s-custom-navbar/s-custom-navbar.vue
Normal file
207
sheep/components/s-custom-navbar/s-custom-navbar.vue
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
<!-- 顶部导航栏 -->
|
||||||
|
<template>
|
||||||
|
<navbar
|
||||||
|
:alway="isAlways"
|
||||||
|
:back="false"
|
||||||
|
bg=""
|
||||||
|
:placeholder="isPlaceholder"
|
||||||
|
:bgStyles="bgStyles"
|
||||||
|
:opacity="isOpacity"
|
||||||
|
:sticky="sticky"
|
||||||
|
>
|
||||||
|
<template #item>
|
||||||
|
<view class="nav-box">
|
||||||
|
<view class="nav-icon" v-if="showLeftButton">
|
||||||
|
<view class="icon-box ss-flex" :class="{ 'inner-icon-box': data.styleType === 'inner' }">
|
||||||
|
<view class="icon-button icon-button-left ss-flex ss-row-center" @tap="onClickLeft">
|
||||||
|
<text class="sicon-back" v-if="hasHistory" />
|
||||||
|
<text class="sicon-home" v-else />
|
||||||
|
</view>
|
||||||
|
<view class="line"></view>
|
||||||
|
<view class="icon-button icon-button-right ss-flex ss-row-center" @tap="onClickRight">
|
||||||
|
<text class="sicon-more" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
class="nav-item"
|
||||||
|
v-for="(item, index) in navList"
|
||||||
|
:key="index"
|
||||||
|
:style="[parseImgStyle(item)]"
|
||||||
|
:class="[{ 'ss-flex ss-col-center ss-row-center': item.type !== 'search' }]"
|
||||||
|
>
|
||||||
|
<navbar-item :data="item" :width="parseImgStyle(item).width" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
</navbar>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
/**
|
||||||
|
* 装修组件 - 自定义标题栏
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @property {Number | String} alwaysShow = [0,1] - 是否常驻
|
||||||
|
* @property {Number | String} styleType = [inner] - 是否沉浸式
|
||||||
|
* @property {String | Number} type - 标题背景模式
|
||||||
|
* @property {String} color - 页面背景色
|
||||||
|
* @property {String} src - 页面背景图片
|
||||||
|
*/
|
||||||
|
import { computed, unref } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import Navbar from './components/navbar.vue';
|
||||||
|
import NavbarItem from './components/navbar-item.vue';
|
||||||
|
import { showMenuTools } from '@/sheep/hooks/useModal';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
data: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({}),
|
||||||
|
},
|
||||||
|
showLeftButton: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const hasHistory = sheep.$router.hasHistory();
|
||||||
|
const sticky = computed(() => {
|
||||||
|
if (props.data.styleType === 'inner') {
|
||||||
|
if (props.data.alwaysShow) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (props.data.styleType === 'normal') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const navList = computed(() => {
|
||||||
|
// #ifdef MP
|
||||||
|
return props.data.mpCells || [];
|
||||||
|
// #endif
|
||||||
|
return props.data.otherCells || [];
|
||||||
|
});
|
||||||
|
// 页面宽度
|
||||||
|
const windowWidth = sheep.$platform.device.windowWidth;
|
||||||
|
// 单元格宽度
|
||||||
|
const cell = computed(() => {
|
||||||
|
if (unref(navList).length) {
|
||||||
|
// 默认宽度为8个格子,微信公众号右上角有胶囊按钮所以是6个格子
|
||||||
|
let cell = (windowWidth - 90) / 8;
|
||||||
|
// #ifdef MP
|
||||||
|
cell = (windowWidth - 80 - unref(sheep.$platform.capsule).width) / 6;
|
||||||
|
// #endif
|
||||||
|
return cell;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 解析位置
|
||||||
|
const parseImgStyle = (item) => {
|
||||||
|
let obj = {
|
||||||
|
width: item.width * cell.value + (item.width - 1) * 10 + 'px',
|
||||||
|
left: item.left * cell.value + (item.left + 1) * 10 + 'px',
|
||||||
|
'border-radius': item.borderRadius + 'px',
|
||||||
|
};
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
const isAlways = computed(() =>
|
||||||
|
props.data.styleType === 'inner' ? Boolean(props.data.alwaysShow) : true,
|
||||||
|
);
|
||||||
|
const isOpacity = computed(() =>
|
||||||
|
props.data.styleType === 'normal'
|
||||||
|
? false
|
||||||
|
: props.showLeftButton
|
||||||
|
? false
|
||||||
|
: props.data.styleType === 'inner',
|
||||||
|
);
|
||||||
|
const isPlaceholder = computed(() => props.data.styleType === 'normal');
|
||||||
|
const bgStyles = computed(() => {
|
||||||
|
return {
|
||||||
|
background:
|
||||||
|
props.data.bgType === 'img' && props.data.bgImg
|
||||||
|
? `url(${sheep.$url.cdn(props.data.bgImg)}) no-repeat top center / 100% 100%`
|
||||||
|
: props.data.bgColor,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// 左侧按钮:返回上一页或首页
|
||||||
|
function onClickLeft() {
|
||||||
|
if (hasHistory) {
|
||||||
|
sheep.$router.back();
|
||||||
|
} else {
|
||||||
|
sheep.$router.go('/pages/index/index');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 右侧按钮:打开快捷菜单
|
||||||
|
function onClickRight() {
|
||||||
|
showMenuTools();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.nav-box {
|
||||||
|
width: 750rpx;
|
||||||
|
position: relative;
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
.nav-item {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-icon {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
left: 20rpx;
|
||||||
|
|
||||||
|
.inner-icon-box {
|
||||||
|
border: 1px solid rgba(#fff, 0.4);
|
||||||
|
background: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-box {
|
||||||
|
background: #ffffff;
|
||||||
|
box-shadow: 0px 0px 4rpx rgba(51, 51, 51, 0.08), 0px 4rpx 6rpx 2rpx rgba(102, 102, 102, 0.12);
|
||||||
|
border-radius: 30rpx;
|
||||||
|
width: 134rpx;
|
||||||
|
height: 56rpx;
|
||||||
|
margin-left: 8rpx;
|
||||||
|
|
||||||
|
.line {
|
||||||
|
width: 2rpx;
|
||||||
|
height: 24rpx;
|
||||||
|
background: #e5e5e7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sicon-back {
|
||||||
|
font-size: 32rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sicon-home {
|
||||||
|
font-size: 32rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sicon-more {
|
||||||
|
font-size: 32rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-button {
|
||||||
|
width: 67rpx;
|
||||||
|
height: 56rpx;
|
||||||
|
|
||||||
|
&-left:hover {
|
||||||
|
background: rgba(0, 0, 0, 0.16);
|
||||||
|
border-radius: 30rpx 0px 0px 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-right:hover {
|
||||||
|
background: rgba(0, 0, 0, 0.16);
|
||||||
|
border-radius: 0px 30rpx 30rpx 0px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
93
sheep/components/s-empty/s-empty.vue
Normal file
93
sheep/components/s-empty/s-empty.vue
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
<template>
|
||||||
|
<view
|
||||||
|
class="ss-flex-col ss-col-center ss-row-center empty-box"
|
||||||
|
:style="[{ paddingTop: paddingTop + 'rpx' }]"
|
||||||
|
>
|
||||||
|
<view class=""><image class="empty-icon" :src="icon" mode="widthFix"></image></view>
|
||||||
|
<view class="empty-text ss-m-t-28 ss-m-b-40">
|
||||||
|
<text v-if="text !== ''">{{ text }}</text>
|
||||||
|
</view>
|
||||||
|
<button class="ss-reset-button empty-btn" v-if="showAction" @tap="clickAction">
|
||||||
|
{{ actionText }}
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
/**
|
||||||
|
* 容器组件 - 装修组件的样式容器
|
||||||
|
*/
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
// 图标
|
||||||
|
icon: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
// 描述
|
||||||
|
text: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
// 是否显示button
|
||||||
|
showAction: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
// button 文字
|
||||||
|
actionText: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
// 链接
|
||||||
|
actionUrl: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
// 间距
|
||||||
|
paddingTop: {
|
||||||
|
type: String,
|
||||||
|
default: '260',
|
||||||
|
},
|
||||||
|
//主题色
|
||||||
|
buttonColor: {
|
||||||
|
type: String,
|
||||||
|
default: 'var(--ui-BG-Main)',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const emits = defineEmits(['clickAction']);
|
||||||
|
|
||||||
|
function clickAction() {
|
||||||
|
if (props.actionUrl !== '') {
|
||||||
|
sheep.$router.go(props.actionUrl);
|
||||||
|
}
|
||||||
|
emits('clickAction');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.empty-box {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.empty-icon {
|
||||||
|
width: 240rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-text {
|
||||||
|
font-size: 26rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #999999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-btn {
|
||||||
|
width: 320rpx;
|
||||||
|
height: 70rpx;
|
||||||
|
border: 2rpx solid v-bind('buttonColor');
|
||||||
|
border-radius: 35rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: v-bind('buttonColor');
|
||||||
|
font-size: 28rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
250
sheep/components/s-layout/s-layout.vue
Normal file
250
sheep/components/s-layout/s-layout.vue
Normal file
@@ -0,0 +1,250 @@
|
|||||||
|
<template>
|
||||||
|
<view
|
||||||
|
class="page-app"
|
||||||
|
:class="['theme-' + sys.mode, 'main-' + sys.theme, 'font-' + sys.fontSize]"
|
||||||
|
>
|
||||||
|
<view class="page-main" :style="[bgMain]">
|
||||||
|
<!-- 顶部导航栏-情况1:默认通用顶部导航栏 -->
|
||||||
|
<su-navbar
|
||||||
|
v-if="navbar === 'normal'"
|
||||||
|
:title="title"
|
||||||
|
statusBar
|
||||||
|
:color="color"
|
||||||
|
:tools="tools"
|
||||||
|
:opacityBgUi="opacityBgUi"
|
||||||
|
@search="(e) => emits('search', e)"
|
||||||
|
:defaultSearch="defaultSearch"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- 顶部导航栏-情况2:装修组件导航栏-标准 -->
|
||||||
|
<s-custom-navbar
|
||||||
|
v-else-if="navbar === 'custom' && navbarMode === 'normal'"
|
||||||
|
:data="navbarStyle"
|
||||||
|
:showLeftButton="showLeftButton"
|
||||||
|
/>
|
||||||
|
<view class="page-body" :style="[bgBody]">
|
||||||
|
<!-- 顶部导航栏-情况3:沉浸式头部 -->
|
||||||
|
<su-inner-navbar v-if="navbar === 'inner'" :title="title" />
|
||||||
|
<view
|
||||||
|
v-if="navbar === 'inner'"
|
||||||
|
:style="[{ paddingTop: sheep.$platform.navbar + 'px' }]"
|
||||||
|
></view>
|
||||||
|
|
||||||
|
<!-- 顶部导航栏-情况4:装修组件导航栏-沉浸式 -->
|
||||||
|
<s-custom-navbar
|
||||||
|
v-if="navbar === 'custom' && navbarMode === 'inner'"
|
||||||
|
:data="navbarStyle"
|
||||||
|
:showLeftButton="showLeftButton"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- 页面内容插槽 -->
|
||||||
|
<slot />
|
||||||
|
|
||||||
|
<!-- 底部导航 -->
|
||||||
|
<s-tabbar v-if="tabbar !== ''" :path="tabbar" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="page-modal">
|
||||||
|
<!-- 全局授权弹窗 -->
|
||||||
|
<s-auth-modal />
|
||||||
|
<!-- 全局分享弹窗 -->
|
||||||
|
<s-share-modal :shareInfo="shareInfo" />
|
||||||
|
<!-- 全局快捷入口 -->
|
||||||
|
<s-menu-tools />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
/**
|
||||||
|
* 模板组件 - 提供页面公共组件,属性,方法
|
||||||
|
*/
|
||||||
|
import { computed, reactive, ref } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import { isEmpty } from 'lodash-es';
|
||||||
|
import { onShow } from '@dcloudio/uni-app';
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
import { onShareAppMessage } from '@dcloudio/uni-app';
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
navbar: {
|
||||||
|
type: String,
|
||||||
|
default: 'normal',
|
||||||
|
},
|
||||||
|
opacityBgUi: {
|
||||||
|
type: String,
|
||||||
|
default: 'bg-white',
|
||||||
|
},
|
||||||
|
color: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
tools: {
|
||||||
|
type: String,
|
||||||
|
default: 'title',
|
||||||
|
},
|
||||||
|
keyword: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
navbarStyle: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({
|
||||||
|
styleType: '',
|
||||||
|
type: '',
|
||||||
|
color: '',
|
||||||
|
src: '',
|
||||||
|
list: [],
|
||||||
|
alwaysShow: 0,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
bgStyle: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({
|
||||||
|
src: '',
|
||||||
|
color: 'var(--ui-BG-1)',
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
tabbar: {
|
||||||
|
type: [String, Boolean],
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
onShareAppMessage: {
|
||||||
|
type: [Boolean, Object],
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
leftWidth: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: 100,
|
||||||
|
},
|
||||||
|
rightWidth: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: 100,
|
||||||
|
},
|
||||||
|
defaultSearch: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
//展示返回按钮
|
||||||
|
showLeftButton: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const emits = defineEmits(['search']);
|
||||||
|
|
||||||
|
const sysStore = sheep.$store('sys');
|
||||||
|
const userStore = sheep.$store('user');
|
||||||
|
const appStore = sheep.$store('app');
|
||||||
|
const modalStore = sheep.$store('modal');
|
||||||
|
const sys = computed(() => sysStore);
|
||||||
|
|
||||||
|
// 导航栏模式(因为有自定义导航栏 需要计算)
|
||||||
|
const navbarMode = computed(() => {
|
||||||
|
if (props.navbar === 'normal' || props.navbarStyle.styleType === 'normal') {
|
||||||
|
return 'normal';
|
||||||
|
}
|
||||||
|
return 'inner';
|
||||||
|
});
|
||||||
|
|
||||||
|
// 背景1
|
||||||
|
const bgMain = computed(() => {
|
||||||
|
if (navbarMode.value === 'inner') {
|
||||||
|
return {
|
||||||
|
background: `${props.bgStyle.backgroundColor} url(${sheep.$url.cdn(
|
||||||
|
props.bgStyle.backgroundImage,
|
||||||
|
)}) no-repeat top center / 100% auto`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
|
||||||
|
// 背景2
|
||||||
|
const bgBody = computed(() => {
|
||||||
|
if (navbarMode.value === 'normal') {
|
||||||
|
// return {
|
||||||
|
// background: `${props.bgStyle.backgroundColor} url(${sheep.$url.cdn(
|
||||||
|
// props.bgStyle.backgroundImage,
|
||||||
|
// )}) no-repeat top center / 100% auto`,
|
||||||
|
// };
|
||||||
|
return {
|
||||||
|
background: `linear-gradient(to bottom, ${props.bgStyle.backgroundColor} 20%, #fafafa 50%)`,
|
||||||
|
// background: `linear-gradient( 180deg, #00B85B 0%, rgba(2,189,94,0.74) 66%, #07CC68 100%)`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
|
||||||
|
// 分享信息
|
||||||
|
const shareInfo = computed(() => {
|
||||||
|
if (props.onShareAppMessage === true) {
|
||||||
|
return sheep.$platform.share.getShareInfo();
|
||||||
|
} else {
|
||||||
|
if (!isEmpty(props.onShareAppMessage)) {
|
||||||
|
sheep.$platform.share.updateShareInfo(props.onShareAppMessage);
|
||||||
|
return props.onShareAppMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
// 微信小程序分享
|
||||||
|
onShareAppMessage(() => {
|
||||||
|
return {
|
||||||
|
title: shareInfo.value.title,
|
||||||
|
path: shareInfo.value.path,
|
||||||
|
imageUrl: shareInfo.value.image,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
onShow(() => {
|
||||||
|
if (!isEmpty(shareInfo.value)) {
|
||||||
|
sheep.$platform.share.updateShareInfo(shareInfo.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.page-app {
|
||||||
|
position: relative;
|
||||||
|
color: var(--ui-TC);
|
||||||
|
background-color: var(--ui-BG-1) !important;
|
||||||
|
z-index: 2;
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
height: 100vh;
|
||||||
|
|
||||||
|
.page-main {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 1;
|
||||||
|
width: 100%;
|
||||||
|
min-height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
.page-body {
|
||||||
|
width: 100%;
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-img {
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
118
sheep/components/s-menu-tools/s-menu-tools.vue
Normal file
118
sheep/components/s-menu-tools/s-menu-tools.vue
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<!-- 全局 - 快捷入口 -->
|
||||||
|
<template>
|
||||||
|
<su-popup :show="show" type="top" round="20" backgroundColor="#F0F0F0" @close="closeMenuTools">
|
||||||
|
<su-status-bar />
|
||||||
|
<view class="tools-wrap ss-m-x-30 ss-m-b-16">
|
||||||
|
<view class="title ss-m-b-34 ss-p-t-20">快捷菜单</view>
|
||||||
|
<view class="container-list ss-flex ss-flex-wrap">
|
||||||
|
<view class="list-item ss-m-b-24" v-for="item in list" :key="item.title">
|
||||||
|
<view class="ss-flex-col ss-col-center">
|
||||||
|
<button
|
||||||
|
class="ss-reset-button list-image ss-flex ss-row-center ss-col-center"
|
||||||
|
@tap="onClick(item)"
|
||||||
|
>
|
||||||
|
<image v-if="show" :src="sheep.$url.static(item.icon)" class="list-icon" />
|
||||||
|
</button>
|
||||||
|
<view class="list-title ss-m-t-20">{{ item.title }}</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</su-popup>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { reactive, computed } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import { showMenuTools, closeMenuTools } from '@/sheep/hooks/useModal';
|
||||||
|
|
||||||
|
const show = computed(() => sheep.$store('modal').menu);
|
||||||
|
|
||||||
|
function onClick(item) {
|
||||||
|
closeMenuTools();
|
||||||
|
if (item.url) sheep.$router.go(item.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
const list = [
|
||||||
|
{
|
||||||
|
url: '/pages/index/index',
|
||||||
|
icon: '/static/img/shop/tools/home.png',
|
||||||
|
title: '首页',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: '/pages/index/search',
|
||||||
|
icon: '/static/img/shop/tools/search.png',
|
||||||
|
title: '搜索',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: '/pages/index/user',
|
||||||
|
icon: '/static/img/shop/tools/user.png',
|
||||||
|
title: '个人中心',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: '/pages/index/cart',
|
||||||
|
icon: '/static/img/shop/tools/cart.png',
|
||||||
|
title: '购物车',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: '/pages/user/goods-log',
|
||||||
|
icon: '/static/img/shop/tools/browse.png',
|
||||||
|
title: '浏览记录',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: '/pages/user/goods-collect',
|
||||||
|
icon: '/static/img/shop/tools/collect.png',
|
||||||
|
title: '我的收藏',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: '/pages/chat/index',
|
||||||
|
icon: '/static/img/shop/tools/service.png',
|
||||||
|
title: '客服',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.tools-wrap {
|
||||||
|
// background: #F0F0F0;
|
||||||
|
// box-shadow: 0px 0px 28rpx 7rpx rgba(0, 0, 0, 0.13);
|
||||||
|
// opacity: 0.98;
|
||||||
|
// border-radius: 0 0 20rpx 20rpx;
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-size: 36rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #333333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-item {
|
||||||
|
width: calc(25vw - 20rpx);
|
||||||
|
|
||||||
|
.list-image {
|
||||||
|
width: 104rpx;
|
||||||
|
height: 104rpx;
|
||||||
|
border-radius: 52rpx;
|
||||||
|
background: var(--ui-BG);
|
||||||
|
|
||||||
|
.list-icon {
|
||||||
|
width: 54rpx;
|
||||||
|
height: 54rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-title {
|
||||||
|
font-size: 26rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #333333;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-popup {
|
||||||
|
top: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.button-hover) {
|
||||||
|
background: #fafafa !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
168
sheep/components/s-share-modal/canvas-poster/index.vue
Normal file
168
sheep/components/s-share-modal/canvas-poster/index.vue
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
<!-- 海报弹窗 -->
|
||||||
|
<template>
|
||||||
|
<su-popup :show="show" round="10" @close="onClosePoster" type="center" class="popup-box">
|
||||||
|
<view class="ss-flex-col ss-col-center ss-row-center">
|
||||||
|
<image
|
||||||
|
v-if="!!painterImageUrl"
|
||||||
|
class="poster-img"
|
||||||
|
:src="painterImageUrl"
|
||||||
|
:style="{
|
||||||
|
height: poster.css.height+ 'px',
|
||||||
|
width: poster.css.width + 'px',
|
||||||
|
}"
|
||||||
|
:show-menu-by-longpress="true"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
class="poster-btn-box ss-m-t-20 ss-flex ss-row-between ss-col-center"
|
||||||
|
v-if="!!painterImageUrl"
|
||||||
|
>
|
||||||
|
<button class="cancel-btn ss-reset-button" @tap="onClosePoster">取消</button>
|
||||||
|
<button class="save-btn ss-reset-button ui-BG-Main" @tap="onSavePoster">
|
||||||
|
{{
|
||||||
|
['wechatOfficialAccount', 'H5'].includes(sheep.$platform.name)
|
||||||
|
? '长按图片保存'
|
||||||
|
: '保存图片'
|
||||||
|
}}
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
<!-- 海报画板:默认隐藏只用来生成海报。生成方式为主动调用 -->
|
||||||
|
<l-painter
|
||||||
|
isCanvasToTempFilePath
|
||||||
|
pathType="url"
|
||||||
|
@success="setPainterImageUrl"
|
||||||
|
hidden
|
||||||
|
ref="painterRef"
|
||||||
|
/>
|
||||||
|
</su-popup>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
/**
|
||||||
|
* 海报生成和展示
|
||||||
|
* 提示:小程序码默认跳转首页,由首页进行 spm 参数解析后跳转到对应的分享页面
|
||||||
|
* @description 用于生成分享海报,如:分享商品海报。
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=2389
|
||||||
|
* @property {Boolean} show 弹出层控制
|
||||||
|
* @property {Object} shareInfo 分享信息
|
||||||
|
*/
|
||||||
|
import { reactive, ref, unref } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import { getPosterData } from '@/sheep/components/s-share-modal/canvas-poster/poster';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
show: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
shareInfo: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const poster = reactive({
|
||||||
|
css: {
|
||||||
|
// 根节点若无尺寸,自动获取父级节点
|
||||||
|
width: sheep.$platform.device.windowWidth * 0.9,
|
||||||
|
height: 600,
|
||||||
|
},
|
||||||
|
views: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
const emits = defineEmits(['success', 'close']);
|
||||||
|
|
||||||
|
const onClosePoster = () => {
|
||||||
|
emits('close');
|
||||||
|
};
|
||||||
|
|
||||||
|
const painterRef = ref(); // 海报画板
|
||||||
|
const painterImageUrl = ref(); // 海报 url
|
||||||
|
// 渲染海报
|
||||||
|
const renderPoster = async () => {
|
||||||
|
await painterRef.value.render(unref(poster));
|
||||||
|
};
|
||||||
|
// 获得生成的图片
|
||||||
|
const setPainterImageUrl = (path) => {
|
||||||
|
painterImageUrl.value = path;
|
||||||
|
};
|
||||||
|
// 保存海报图片
|
||||||
|
const onSavePoster = () => {
|
||||||
|
if (['WechatOfficialAccount', 'H5'].includes(sheep.$platform.name)) {
|
||||||
|
sheep.$helper.toast('请长按图片保存');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 非H5 保存到相册
|
||||||
|
uni.saveImageToPhotosAlbum({
|
||||||
|
filePath: painterImageUrl.value,
|
||||||
|
success: (res) => {
|
||||||
|
onClosePoster();
|
||||||
|
sheep.$helper.toast('保存成功');
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
sheep.$helper.toast('保存失败');
|
||||||
|
console.log('图片保存失败:', err);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获得海报数据
|
||||||
|
async function getPoster() {
|
||||||
|
painterImageUrl.value = undefined
|
||||||
|
poster.views = await getPosterData({
|
||||||
|
width: poster.css.width,
|
||||||
|
shareInfo: props.shareInfo,
|
||||||
|
});
|
||||||
|
await renderPoster();
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
getPoster,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.popup-box {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.poster-title {
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分享海报
|
||||||
|
.poster-btn-box {
|
||||||
|
width: 600rpx;
|
||||||
|
position: absolute;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
bottom: -80rpx;
|
||||||
|
|
||||||
|
.cancel-btn {
|
||||||
|
width: 240rpx;
|
||||||
|
height: 70rpx;
|
||||||
|
line-height: 70rpx;
|
||||||
|
background: $white;
|
||||||
|
border-radius: 35rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: $dark-9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.save-btn {
|
||||||
|
width: 240rpx;
|
||||||
|
height: 70rpx;
|
||||||
|
line-height: 70rpx;
|
||||||
|
border-radius: 35rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.poster-img {
|
||||||
|
border-radius: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
125
sheep/components/s-share-modal/canvas-poster/poster/goods.js
Normal file
125
sheep/components/s-share-modal/canvas-poster/poster/goods.js
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
import sheep from '@/sheep';
|
||||||
|
import { formatImageUrlProtocol, getWxaQrcode } from './index';
|
||||||
|
|
||||||
|
const goods = async (poster) => {
|
||||||
|
const width = poster.width;
|
||||||
|
const userInfo = sheep.$store('user').userInfo;
|
||||||
|
const wxa_qrcode = await getWxaQrcode(poster.shareInfo.path, poster.shareInfo.query);
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
type: 'image',
|
||||||
|
src: formatImageUrlProtocol(sheep.$url.cdn(sheep.$store('app').platform.share.posterInfo.goods_bg)),
|
||||||
|
css: {
|
||||||
|
width,
|
||||||
|
position: 'fixed',
|
||||||
|
'object-fit': 'contain',
|
||||||
|
top: '0',
|
||||||
|
left: '0',
|
||||||
|
zIndex: -1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: userInfo.nickname,
|
||||||
|
css: {
|
||||||
|
color: '#333',
|
||||||
|
fontSize: 16,
|
||||||
|
fontFamily: 'sans-serif',
|
||||||
|
position: 'fixed',
|
||||||
|
top: width * 0.06,
|
||||||
|
left: width * 0.22,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'image',
|
||||||
|
src: formatImageUrlProtocol(sheep.$url.cdn(userInfo.avatar)),
|
||||||
|
css: {
|
||||||
|
position: 'fixed',
|
||||||
|
left: width * 0.04,
|
||||||
|
top: width * 0.04,
|
||||||
|
width: width * 0.14,
|
||||||
|
height: width * 0.14,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'image',
|
||||||
|
src: formatImageUrlProtocol(poster.shareInfo.poster.image),
|
||||||
|
css: {
|
||||||
|
position: 'fixed',
|
||||||
|
left: width * 0.03,
|
||||||
|
top: width * 0.21,
|
||||||
|
width: width * 0.94,
|
||||||
|
height: width * 0.94,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: poster.shareInfo.poster.title,
|
||||||
|
css: {
|
||||||
|
position: 'fixed',
|
||||||
|
left: width * 0.04,
|
||||||
|
top: width * 1.18,
|
||||||
|
color: '#333',
|
||||||
|
fontSize: 14,
|
||||||
|
lineHeight: 15,
|
||||||
|
maxWidth: width * 0.91,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: '¥' + poster.shareInfo.poster.price,
|
||||||
|
css: {
|
||||||
|
position: 'fixed',
|
||||||
|
left: width * 0.04,
|
||||||
|
top: width * 1.31,
|
||||||
|
fontSize: 20,
|
||||||
|
fontFamily: 'OPPOSANS',
|
||||||
|
color: '#333',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text:
|
||||||
|
poster.shareInfo.poster.original_price > 0
|
||||||
|
? '¥' + poster.shareInfo.poster.original_price
|
||||||
|
: '',
|
||||||
|
css: {
|
||||||
|
position: 'fixed',
|
||||||
|
left: width * 0.3,
|
||||||
|
top: width * 1.33,
|
||||||
|
color: '#999',
|
||||||
|
fontSize: 10,
|
||||||
|
fontFamily: 'OPPOSANS',
|
||||||
|
textDecoration: 'line-through',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// #ifndef MP-WEIXIN
|
||||||
|
{
|
||||||
|
type: 'qrcode',
|
||||||
|
text: poster.shareInfo.link,
|
||||||
|
css: {
|
||||||
|
position: 'fixed',
|
||||||
|
left: width * 0.75,
|
||||||
|
top: width * 1.3,
|
||||||
|
width: width * 0.2,
|
||||||
|
height: width * 0.2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
{
|
||||||
|
type: 'image',
|
||||||
|
src: wxa_qrcode,
|
||||||
|
css: {
|
||||||
|
position: 'fixed',
|
||||||
|
left: width * 0.75,
|
||||||
|
top: width * 1.3,
|
||||||
|
width: width * 0.2,
|
||||||
|
height: width * 0.2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
export default goods;
|
||||||
122
sheep/components/s-share-modal/canvas-poster/poster/groupon.js
Normal file
122
sheep/components/s-share-modal/canvas-poster/poster/groupon.js
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
import sheep from '@/sheep';
|
||||||
|
import { formatImageUrlProtocol, getWxaQrcode } from './index';
|
||||||
|
|
||||||
|
const groupon = async (poster) => {
|
||||||
|
const width = poster.width;
|
||||||
|
const userInfo = sheep.$store('user').userInfo;
|
||||||
|
const wxa_qrcode = await getWxaQrcode(poster.shareInfo.path, poster.shareInfo.query);
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
type: 'image',
|
||||||
|
src: formatImageUrlProtocol(sheep.$url.cdn(sheep.$store('app').platform.share.posterInfo.groupon_bg)),
|
||||||
|
css: {
|
||||||
|
width,
|
||||||
|
position: 'fixed',
|
||||||
|
'object-fit': 'contain',
|
||||||
|
top: '0',
|
||||||
|
left: '0',
|
||||||
|
zIndex: -1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: userInfo.nickname,
|
||||||
|
css: {
|
||||||
|
color: '#333',
|
||||||
|
fontSize: 16,
|
||||||
|
fontFamily: 'sans-serif',
|
||||||
|
position: 'fixed',
|
||||||
|
top: width * 0.06,
|
||||||
|
left: width * 0.22,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'image',
|
||||||
|
src: formatImageUrlProtocol(sheep.$url.cdn(userInfo.avatar)),
|
||||||
|
css: {
|
||||||
|
position: 'fixed',
|
||||||
|
left: width * 0.04,
|
||||||
|
top: width * 0.04,
|
||||||
|
width: width * 0.14,
|
||||||
|
height: width * 0.14,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'image',
|
||||||
|
src: formatImageUrlProtocol(poster.shareInfo.poster.image),
|
||||||
|
css: {
|
||||||
|
position: 'fixed',
|
||||||
|
left: width * 0.03,
|
||||||
|
top: width * 0.21,
|
||||||
|
width: width * 0.94,
|
||||||
|
height: width * 0.94,
|
||||||
|
borderRadius: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: poster.shareInfo.poster.title,
|
||||||
|
css: {
|
||||||
|
color: '#333',
|
||||||
|
fontSize: 14,
|
||||||
|
position: 'fixed',
|
||||||
|
top: width * 1.18,
|
||||||
|
left: width * 0.04,
|
||||||
|
maxWidth: width * 0.91,
|
||||||
|
lineHeight: 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: '¥' + poster.shareInfo.poster.price,
|
||||||
|
css: {
|
||||||
|
color: '#ff0000',
|
||||||
|
fontSize: 20,
|
||||||
|
fontFamily: 'OPPOSANS',
|
||||||
|
position: 'fixed',
|
||||||
|
top: width * 1.3,
|
||||||
|
left: width * 0.04,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: '2人团',
|
||||||
|
css: {
|
||||||
|
color: '#fff',
|
||||||
|
fontSize: 12,
|
||||||
|
fontFamily: 'OPPOSANS',
|
||||||
|
position: 'fixed',
|
||||||
|
left: width * 0.84,
|
||||||
|
top: width * 1.3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// #ifndef MP-WEIXIN
|
||||||
|
{
|
||||||
|
type: 'qrcode',
|
||||||
|
text: poster.shareInfo.link,
|
||||||
|
css: {
|
||||||
|
position: 'fixed',
|
||||||
|
left: width * 0.5,
|
||||||
|
top: width * 1.3,
|
||||||
|
width: width * 0.2,
|
||||||
|
height: width * 0.2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
{
|
||||||
|
type: 'image',
|
||||||
|
src: wxa_qrcode,
|
||||||
|
css: {
|
||||||
|
position: 'fixed',
|
||||||
|
left: width * 0.75,
|
||||||
|
top: width * 1.3,
|
||||||
|
width: width * 0.2,
|
||||||
|
height: width * 0.2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
export default groupon;
|
||||||
39
sheep/components/s-share-modal/canvas-poster/poster/index.js
Normal file
39
sheep/components/s-share-modal/canvas-poster/poster/index.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import user from './user';
|
||||||
|
import goods from './goods';
|
||||||
|
import groupon from './groupon';
|
||||||
|
import SocialApi from '@/sheep/api/member/social';
|
||||||
|
|
||||||
|
export function getPosterData(options) {
|
||||||
|
switch (options.shareInfo.poster.type) {
|
||||||
|
case 'user':
|
||||||
|
return user(options);
|
||||||
|
case 'goods':
|
||||||
|
return goods(options);
|
||||||
|
case 'groupon':
|
||||||
|
return groupon(options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatImageUrlProtocol(url) {
|
||||||
|
// #ifdef H5
|
||||||
|
// H5平台 https协议下需要转换
|
||||||
|
if (window.location.protocol === 'https:' && url.indexOf('http:') === 0) {
|
||||||
|
url = url.replace('http:', 'https:');
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
// 小程序平台 需要强制转换为https协议
|
||||||
|
if (url.indexOf('http:') === 0) {
|
||||||
|
url = url.replace('http:', 'https:');
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获得微信小程序码 (Base64 image)
|
||||||
|
export async function getWxaQrcode(path, query) {
|
||||||
|
const res = await SocialApi.getWxaQrcode(path, query);
|
||||||
|
return 'data:image/png;base64,' + res.data;
|
||||||
|
}
|
||||||
74
sheep/components/s-share-modal/canvas-poster/poster/user.js
Normal file
74
sheep/components/s-share-modal/canvas-poster/poster/user.js
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import sheep from '@/sheep';
|
||||||
|
import { formatImageUrlProtocol, getWxaQrcode } from './index';
|
||||||
|
|
||||||
|
const user = async (poster) => {
|
||||||
|
const width = poster.width;
|
||||||
|
const userInfo = sheep.$store('user').userInfo;
|
||||||
|
const wxa_qrcode = await getWxaQrcode(poster.shareInfo.path, poster.shareInfo.query);
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
type: 'image',
|
||||||
|
src: formatImageUrlProtocol(sheep.$url.cdn(sheep.$store('app').platform.share.posterInfo.user_bg)),
|
||||||
|
css: {
|
||||||
|
width,
|
||||||
|
position: 'fixed',
|
||||||
|
'object-fit': 'contain',
|
||||||
|
top: '0',
|
||||||
|
left: '0',
|
||||||
|
zIndex: -1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: userInfo.nickname,
|
||||||
|
css: {
|
||||||
|
color: '#333',
|
||||||
|
fontSize: 14,
|
||||||
|
textAlign: 'center',
|
||||||
|
fontFamily: 'sans-serif',
|
||||||
|
position: 'fixed',
|
||||||
|
top: width * 0.4,
|
||||||
|
left: width / 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'image',
|
||||||
|
src: formatImageUrlProtocol(sheep.$url.cdn(userInfo.avatar)),
|
||||||
|
css: {
|
||||||
|
position: 'fixed',
|
||||||
|
left: width * 0.4,
|
||||||
|
top: width * 0.16,
|
||||||
|
width: width * 0.2,
|
||||||
|
height: width * 0.2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// #ifndef MP-WEIXIN
|
||||||
|
{
|
||||||
|
type: 'qrcode',
|
||||||
|
text: poster.shareInfo.link,
|
||||||
|
css: {
|
||||||
|
position: 'fixed',
|
||||||
|
left: width * 0.35,
|
||||||
|
top: width * 0.84,
|
||||||
|
width: width * 0.3,
|
||||||
|
height: width * 0.3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
{
|
||||||
|
type: 'image',
|
||||||
|
src: wxa_qrcode,
|
||||||
|
css: {
|
||||||
|
position: 'fixed',
|
||||||
|
left: width * 0.35,
|
||||||
|
top: width * 0.84,
|
||||||
|
width: width * 0.3,
|
||||||
|
height: width * 0.3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
export default user;
|
||||||
196
sheep/components/s-share-modal/s-share-modal.vue
Normal file
196
sheep/components/s-share-modal/s-share-modal.vue
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
<!-- 全局分享弹框 -->
|
||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<su-popup :show="state.showShareGuide" :showClose="false" @close="onCloseGuide" />
|
||||||
|
<view v-if="state.showShareGuide" class="guide-wrap">
|
||||||
|
<image class="guide-image" :src="sheep.$url.static('/static/img/shop/share/share_guide.png')" />
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<su-popup :show="show" round="10" :showClose="false" @close="closeShareModal">
|
||||||
|
<!-- 分享 tools -->
|
||||||
|
<view class="share-box">
|
||||||
|
<view class="share-list-box ss-flex">
|
||||||
|
<!-- 操作 ①:发送给微信好友 -->
|
||||||
|
<button
|
||||||
|
v-if="shareConfig.methods.includes('forward')"
|
||||||
|
class="share-item share-btn ss-flex-col ss-col-center"
|
||||||
|
open-type="share"
|
||||||
|
@tap="onShareByForward"
|
||||||
|
>
|
||||||
|
<image class="share-img" :src="sheep.$url.static('/static/img/shop/share/share_wx.png')" mode="" />
|
||||||
|
<text class="share-title">微信好友</text>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- 操作 ②:生成海报图片 -->
|
||||||
|
<button
|
||||||
|
v-if="shareConfig.methods.includes('poster')"
|
||||||
|
class="share-item share-btn ss-flex-col ss-col-center"
|
||||||
|
@tap="onShareByPoster"
|
||||||
|
>
|
||||||
|
<image
|
||||||
|
class="share-img"
|
||||||
|
:src="sheep.$url.static('/static/img/shop/share/share_poster.png')"
|
||||||
|
mode=""
|
||||||
|
/>
|
||||||
|
<text class="share-title">生成海报</text>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- 操作 ③:生成链接 -->
|
||||||
|
<button
|
||||||
|
v-if="shareConfig.methods.includes('link')"
|
||||||
|
class="share-item share-btn ss-flex-col ss-col-center"
|
||||||
|
@tap="onShareByCopyLink"
|
||||||
|
>
|
||||||
|
<image class="share-img" :src="sheep.$url.static('/static/img/shop/share/share_link.png')" mode="" />
|
||||||
|
<text class="share-title">复制链接</text>
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
<view class="share-foot ss-flex ss-row-center ss-col-center" @tap="closeShareModal">
|
||||||
|
取消
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</su-popup>
|
||||||
|
|
||||||
|
<!-- 分享海报,对应操作 ② -->
|
||||||
|
<canvas-poster
|
||||||
|
ref="SharePosterRef"
|
||||||
|
:show="state.showPosterModal"
|
||||||
|
:shareInfo="shareInfo"
|
||||||
|
@close="state.showPosterModal = false"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
<script setup>
|
||||||
|
/**
|
||||||
|
* 分享弹窗
|
||||||
|
*/
|
||||||
|
import { ref, unref, reactive, computed } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
import canvasPoster from './canvas-poster/index.vue';
|
||||||
|
import { closeShareModal, showAuthModal } from '@/sheep/hooks/useModal';
|
||||||
|
|
||||||
|
const show = computed(() => sheep.$store('modal').share);
|
||||||
|
const shareConfig = computed(() => sheep.$store('app').platform.share);
|
||||||
|
const SharePosterRef = ref('');
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
shareInfo: {
|
||||||
|
type: Object,
|
||||||
|
default() {},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const state = reactive({
|
||||||
|
showShareGuide: false, // H5 的指引
|
||||||
|
showPosterModal: false, // 海报弹窗
|
||||||
|
});
|
||||||
|
|
||||||
|
// 操作 ②:生成海报分享
|
||||||
|
const onShareByPoster = () => {
|
||||||
|
closeShareModal();
|
||||||
|
if (!sheep.$store('user').isLogin) {
|
||||||
|
showAuthModal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(props.shareInfo);
|
||||||
|
unref(SharePosterRef).getPoster();
|
||||||
|
state.showPosterModal = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 操作 ①:直接转发分享
|
||||||
|
const onShareByForward = () => {
|
||||||
|
closeShareModal();
|
||||||
|
|
||||||
|
// #ifdef H5
|
||||||
|
if (['WechatOfficialAccount', 'H5'].includes(sheep.$platform.name)) {
|
||||||
|
state.showShareGuide = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
uni.share({
|
||||||
|
provider: 'weixin',
|
||||||
|
scene: 'WXSceneSession',
|
||||||
|
type: 0,
|
||||||
|
href: props.shareInfo.link,
|
||||||
|
title: props.shareInfo.title,
|
||||||
|
summary: props.shareInfo.desc,
|
||||||
|
imageUrl: props.shareInfo.image,
|
||||||
|
success: (res) => {
|
||||||
|
console.log('success:' + JSON.stringify(res));
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.log('fail:' + JSON.stringify(err));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// #endif
|
||||||
|
};
|
||||||
|
|
||||||
|
// 操作 ③:复制链接分享
|
||||||
|
const onShareByCopyLink = () => {
|
||||||
|
sheep.$helper.copyText(props.shareInfo.link);
|
||||||
|
closeShareModal();
|
||||||
|
};
|
||||||
|
|
||||||
|
function onCloseGuide() {
|
||||||
|
state.showShareGuide = false;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.guide-image {
|
||||||
|
right: 30rpx;
|
||||||
|
top: 0;
|
||||||
|
position: fixed;
|
||||||
|
width: 580rpx;
|
||||||
|
height: 430rpx;
|
||||||
|
z-index: 10080;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分享tool
|
||||||
|
.share-box {
|
||||||
|
background: $white;
|
||||||
|
width: 750rpx;
|
||||||
|
border-radius: 30rpx 30rpx 0 0;
|
||||||
|
padding-top: 30rpx;
|
||||||
|
|
||||||
|
.share-foot {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: $gray-b;
|
||||||
|
height: 80rpx;
|
||||||
|
border-top: 1rpx solid $gray-e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.share-list-box {
|
||||||
|
.share-btn {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
line-height: 1;
|
||||||
|
padding: 0;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.share-item {
|
||||||
|
flex: 1;
|
||||||
|
padding-bottom: 20rpx;
|
||||||
|
|
||||||
|
.share-img {
|
||||||
|
width: 70rpx;
|
||||||
|
height: 70rpx;
|
||||||
|
background: $gray-f;
|
||||||
|
border-radius: 50%;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.share-title {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: $dark-6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
90
sheep/components/s-tabbar/s-tabbar.vue
Normal file
90
sheep/components/s-tabbar/s-tabbar.vue
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
<template>
|
||||||
|
<view class="u-page__item" v-if="tabbar?.items?.length > 0">
|
||||||
|
<su-tabbar
|
||||||
|
:value="path"
|
||||||
|
:fixed="true"
|
||||||
|
:placeholder="true"
|
||||||
|
:safeAreaInsetBottom="true"
|
||||||
|
:inactiveColor="tabbar.style.color"
|
||||||
|
:activeColor="tabbar.style.activeColor"
|
||||||
|
:midTabBar="tabbar.mode === 2"
|
||||||
|
:customStyle="tabbarStyle"
|
||||||
|
>
|
||||||
|
<su-tabbar-item
|
||||||
|
v-for="(item, index) in tabbar.items"
|
||||||
|
:key="item.text"
|
||||||
|
:text="item.text"
|
||||||
|
:name="item.url"
|
||||||
|
:isCenter="getTabbarCenter(index)"
|
||||||
|
:centerImage="sheep.$url.cdn(item.iconUrl)"
|
||||||
|
@tap="sheep.$router.go(item.url)"
|
||||||
|
>
|
||||||
|
<template v-slot:active-icon>
|
||||||
|
<image class="u-page__item__slot-icon" :src="sheep.$url.cdn(item.activeIconUrl)"></image>
|
||||||
|
</template>
|
||||||
|
<template v-slot:inactive-icon>
|
||||||
|
<image class="u-page__item__slot-icon" :src="sheep.$url.cdn(item.iconUrl)"></image>
|
||||||
|
</template>
|
||||||
|
</su-tabbar-item>
|
||||||
|
</su-tabbar>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed, unref } from 'vue';
|
||||||
|
import sheep from '@/sheep';
|
||||||
|
|
||||||
|
const tabbar = computed(() => {
|
||||||
|
return sheep.$store('app').template.basic?.tabbar;
|
||||||
|
});
|
||||||
|
|
||||||
|
const tabbarStyle = computed(() => {
|
||||||
|
const backgroundStyle = tabbar.value.style;
|
||||||
|
if (backgroundStyle.bgType === 'color') {
|
||||||
|
return { background: backgroundStyle.bgColor };
|
||||||
|
}
|
||||||
|
if (backgroundStyle.bgType === 'img')
|
||||||
|
return {
|
||||||
|
background: `url(${sheep.$url.cdn(
|
||||||
|
backgroundStyle.bgImg,
|
||||||
|
)}) no-repeat top center / 100% auto`,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const getTabbarCenter = (index) => {
|
||||||
|
if (unref(tabbar).mode !== 2) return false;
|
||||||
|
return unref(tabbar).items % 2 > 0
|
||||||
|
? Math.ceil(unref(tabbar).items.length / 2) === index + 1
|
||||||
|
: false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
path: String,
|
||||||
|
default: '',
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.u-page {
|
||||||
|
padding: 0;
|
||||||
|
|
||||||
|
&__item {
|
||||||
|
&__title {
|
||||||
|
color: var(--textSize);
|
||||||
|
background-color: #fff;
|
||||||
|
padding: 15px;
|
||||||
|
font-size: 15px;
|
||||||
|
|
||||||
|
&__slot-title {
|
||||||
|
color: var(--textSize);
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__slot-icon {
|
||||||
|
width: 25px;
|
||||||
|
height: 25px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
23
sheep/config/index.js
Normal file
23
sheep/config/index.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// 开发环境配置
|
||||||
|
export let baseUrl;
|
||||||
|
export let version;
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
baseUrl = import.meta.env.SHOPRO_DEV_BASE_URL;
|
||||||
|
} else {
|
||||||
|
baseUrl = import.meta.env.SHOPRO_BASE_URL;
|
||||||
|
}
|
||||||
|
version = import.meta.env.SHOPRO_VERSION;
|
||||||
|
console.log(`[芋道商城 ${version}] http://doc.iocoder.cn`);
|
||||||
|
|
||||||
|
export const apiPath = import.meta.env.SHOPRO_API_PATH;
|
||||||
|
export const staticUrl = import.meta.env.SHOPRO_STATIC_URL;
|
||||||
|
export const tenantId = import.meta.env.SHOPRO_TENANT_ID;
|
||||||
|
export const websocketPath = import.meta.env.SHOPRO_WEBSOCKET_PATH;
|
||||||
|
|
||||||
|
export default {
|
||||||
|
baseUrl,
|
||||||
|
apiPath,
|
||||||
|
staticUrl,
|
||||||
|
tenantId,
|
||||||
|
websocketPath,
|
||||||
|
};
|
||||||
20
sheep/config/zIndex.js
Normal file
20
sheep/config/zIndex.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// uniapp在H5中各API的z-index值如下:
|
||||||
|
/**
|
||||||
|
* actionsheet: 999
|
||||||
|
* modal: 999
|
||||||
|
* navigate: 998
|
||||||
|
* tabbar: 998
|
||||||
|
* toast: 999
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default {
|
||||||
|
toast: 10090,
|
||||||
|
noNetwork: 10080,
|
||||||
|
popup: 10075, // popup包含popup,actionsheet,keyboard,picker的值
|
||||||
|
mask: 10070,
|
||||||
|
navbar: 980,
|
||||||
|
topTips: 975,
|
||||||
|
sticky: 970,
|
||||||
|
indexListSticky: 965,
|
||||||
|
popover: 960,
|
||||||
|
};
|
||||||
168
sheep/helper/digit.js
Normal file
168
sheep/helper/digit.js
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
let _boundaryCheckingState = true; // 是否进行越界检查的全局开关
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把错误的数据转正
|
||||||
|
* @private
|
||||||
|
* @example strip(0.09999999999999998)=0.1
|
||||||
|
*/
|
||||||
|
function strip(num, precision = 15) {
|
||||||
|
return +parseFloat(Number(num).toPrecision(precision));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return digits length of a number
|
||||||
|
* @private
|
||||||
|
* @param {*number} num Input number
|
||||||
|
*/
|
||||||
|
function digitLength(num) {
|
||||||
|
// Get digit length of e
|
||||||
|
const eSplit = num.toString().split(/[eE]/);
|
||||||
|
const len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
|
||||||
|
return len > 0 ? len : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把小数转成整数,如果是小数则放大成整数
|
||||||
|
* @private
|
||||||
|
* @param {*number} num 输入数
|
||||||
|
*/
|
||||||
|
function float2Fixed(num) {
|
||||||
|
if (num.toString().indexOf('e') === -1) {
|
||||||
|
return Number(num.toString().replace('.', ''));
|
||||||
|
}
|
||||||
|
const dLen = digitLength(num);
|
||||||
|
return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测数字是否越界,如果越界给出提示
|
||||||
|
* @private
|
||||||
|
* @param {*number} num 输入数
|
||||||
|
*/
|
||||||
|
function checkBoundary(num) {
|
||||||
|
if (_boundaryCheckingState) {
|
||||||
|
if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
|
||||||
|
console.warn(`${num} 超出了精度限制,结果可能不正确`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把递归操作扁平迭代化
|
||||||
|
* @param {number[]} arr 要操作的数字数组
|
||||||
|
* @param {function} operation 迭代操作
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
function iteratorOperation(arr, operation) {
|
||||||
|
const [num1, num2, ...others] = arr;
|
||||||
|
let res = operation(num1, num2);
|
||||||
|
|
||||||
|
others.forEach((num) => {
|
||||||
|
res = operation(res, num);
|
||||||
|
});
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 高精度乘法
|
||||||
|
* @export
|
||||||
|
*/
|
||||||
|
export function times(...nums) {
|
||||||
|
if (nums.length > 2) {
|
||||||
|
return iteratorOperation(nums, times);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [num1, num2] = nums;
|
||||||
|
const num1Changed = float2Fixed(num1);
|
||||||
|
const num2Changed = float2Fixed(num2);
|
||||||
|
const baseNum = digitLength(num1) + digitLength(num2);
|
||||||
|
const leftValue = num1Changed * num2Changed;
|
||||||
|
|
||||||
|
checkBoundary(leftValue);
|
||||||
|
|
||||||
|
return leftValue / Math.pow(10, baseNum);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 高精度加法
|
||||||
|
* @export
|
||||||
|
*/
|
||||||
|
export function plus(...nums) {
|
||||||
|
if (nums.length > 2) {
|
||||||
|
return iteratorOperation(nums, plus);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [num1, num2] = nums;
|
||||||
|
// 取最大的小数位
|
||||||
|
const baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
||||||
|
// 把小数都转为整数然后再计算
|
||||||
|
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 高精度减法
|
||||||
|
* @export
|
||||||
|
*/
|
||||||
|
export function minus(...nums) {
|
||||||
|
if (nums.length > 2) {
|
||||||
|
return iteratorOperation(nums, minus);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [num1, num2] = nums;
|
||||||
|
const baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
||||||
|
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 高精度除法
|
||||||
|
* @export
|
||||||
|
*/
|
||||||
|
export function divide(...nums) {
|
||||||
|
if (nums.length > 2) {
|
||||||
|
return iteratorOperation(nums, divide);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [num1, num2] = nums;
|
||||||
|
const num1Changed = float2Fixed(num1);
|
||||||
|
const num2Changed = float2Fixed(num2);
|
||||||
|
checkBoundary(num1Changed);
|
||||||
|
checkBoundary(num2Changed);
|
||||||
|
// 重要,这里必须用strip进行修正
|
||||||
|
return times(
|
||||||
|
num1Changed / num2Changed,
|
||||||
|
strip(Math.pow(10, digitLength(num2) - digitLength(num1))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 四舍五入
|
||||||
|
* @export
|
||||||
|
*/
|
||||||
|
export function round(num, ratio) {
|
||||||
|
const base = Math.pow(10, ratio);
|
||||||
|
let result = divide(Math.round(Math.abs(times(num, base))), base);
|
||||||
|
if (num < 0 && result !== 0) {
|
||||||
|
result = times(result, -1);
|
||||||
|
}
|
||||||
|
// 位数不足则补0
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否进行边界检查,默认开启
|
||||||
|
* @param flag 标记开关,true 为开启,false 为关闭,默认为 true
|
||||||
|
* @export
|
||||||
|
*/
|
||||||
|
export function enableBoundaryChecking(flag = true) {
|
||||||
|
_boundaryCheckingState = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
times,
|
||||||
|
plus,
|
||||||
|
minus,
|
||||||
|
divide,
|
||||||
|
round,
|
||||||
|
enableBoundaryChecking,
|
||||||
|
};
|
||||||
708
sheep/helper/index.js
Normal file
708
sheep/helper/index.js
Normal file
@@ -0,0 +1,708 @@
|
|||||||
|
import test from './test.js';
|
||||||
|
import { round } from './digit.js';
|
||||||
|
/**
|
||||||
|
* @description 如果value小于min,取min;如果value大于max,取max
|
||||||
|
* @param {number} min
|
||||||
|
* @param {number} max
|
||||||
|
* @param {number} value
|
||||||
|
*/
|
||||||
|
function range(min = 0, max = 0, value = 0) {
|
||||||
|
return Math.max(min, Math.min(max, Number(value)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 用于获取用户传递值的px值 如果用户传递了"xxpx"或者"xxrpx",取出其数值部分,如果是"xxxrpx"还需要用过uni.upx2px进行转换
|
||||||
|
* @param {number|string} value 用户传递值的px值
|
||||||
|
* @param {boolean} unit
|
||||||
|
* @returns {number|string}
|
||||||
|
*/
|
||||||
|
export function getPx(value, unit = false) {
|
||||||
|
if (test.number(value)) {
|
||||||
|
return unit ? `${value}px` : Number(value);
|
||||||
|
}
|
||||||
|
// 如果带有rpx,先取出其数值部分,再转为px值
|
||||||
|
if (/(rpx|upx)$/.test(value)) {
|
||||||
|
return unit ? `${uni.upx2px(parseInt(value))}px` : Number(uni.upx2px(parseInt(value)));
|
||||||
|
}
|
||||||
|
return unit ? `${parseInt(value)}px` : parseInt(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 进行延时,以达到可以简写代码的目的
|
||||||
|
* @param {number} value 堵塞时间 单位ms 毫秒
|
||||||
|
* @returns {Promise} 返回promise
|
||||||
|
*/
|
||||||
|
export function sleep(value = 30) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve();
|
||||||
|
}, value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @description 运行期判断平台
|
||||||
|
* @returns {string} 返回所在平台(小写)
|
||||||
|
* @link 运行期判断平台 https://uniapp.dcloud.io/frame?id=判断平台
|
||||||
|
*/
|
||||||
|
export function os() {
|
||||||
|
return uni.getSystemInfoSync().platform.toLowerCase();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @description 获取系统信息同步接口
|
||||||
|
* @link 获取系统信息同步接口 https://uniapp.dcloud.io/api/system/info?id=getsysteminfosync
|
||||||
|
*/
|
||||||
|
export function sys() {
|
||||||
|
return uni.getSystemInfoSync();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 取一个区间数
|
||||||
|
* @param {Number} min 最小值
|
||||||
|
* @param {Number} max 最大值
|
||||||
|
*/
|
||||||
|
function random(min, max) {
|
||||||
|
if (min >= 0 && max > 0 && max >= min) {
|
||||||
|
const gab = max - min + 1;
|
||||||
|
return Math.floor(Math.random() * gab + min);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Number} len uuid的长度
|
||||||
|
* @param {Boolean} firstU 将返回的首字母置为"u"
|
||||||
|
* @param {Nubmer} radix 生成uuid的基数(意味着返回的字符串都是这个基数),2-二进制,8-八进制,10-十进制,16-十六进制
|
||||||
|
*/
|
||||||
|
export function guid(len = 32, firstU = true, radix = null) {
|
||||||
|
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
|
||||||
|
const uuid = [];
|
||||||
|
radix = radix || chars.length;
|
||||||
|
|
||||||
|
if (len) {
|
||||||
|
// 如果指定uuid长度,只是取随机的字符,0|x为位运算,能去掉x的小数位,返回整数位
|
||||||
|
for (let i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
|
||||||
|
} else {
|
||||||
|
let r;
|
||||||
|
// rfc4122标准要求返回的uuid中,某些位为固定的字符
|
||||||
|
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
|
||||||
|
uuid[14] = '4';
|
||||||
|
|
||||||
|
for (let i = 0; i < 36; i++) {
|
||||||
|
if (!uuid[i]) {
|
||||||
|
r = 0 | (Math.random() * 16);
|
||||||
|
uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 移除第一个字符,并用u替代,因为第一个字符为数值时,该guuid不能用作id或者class
|
||||||
|
if (firstU) {
|
||||||
|
uuid.shift();
|
||||||
|
return `u${uuid.join('')}`;
|
||||||
|
}
|
||||||
|
return uuid.join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 获取父组件的参数,因为支付宝小程序不支持provide/inject的写法
|
||||||
|
this.$parent在非H5中,可以准确获取到父组件,但是在H5中,需要多次this.$parent.$parent.xxx
|
||||||
|
这里默认值等于undefined有它的含义,因为最顶层元素(组件)的$parent就是undefined,意味着不传name
|
||||||
|
值(默认为undefined),就是查找最顶层的$parent
|
||||||
|
* @param {string|undefined} name 父组件的参数名
|
||||||
|
*/
|
||||||
|
export function $parent(name = undefined) {
|
||||||
|
let parent = this.$parent;
|
||||||
|
// 通过while历遍,这里主要是为了H5需要多层解析的问题
|
||||||
|
while (parent) {
|
||||||
|
// 父组件
|
||||||
|
if (parent.$options && parent.$options.name !== name) {
|
||||||
|
// 如果组件的name不相等,继续上一级寻找
|
||||||
|
parent = parent.$parent;
|
||||||
|
} else {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 样式转换
|
||||||
|
* 对象转字符串,或者字符串转对象
|
||||||
|
* @param {object | string} customStyle 需要转换的目标
|
||||||
|
* @param {String} target 转换的目的,object-转为对象,string-转为字符串
|
||||||
|
* @returns {object|string}
|
||||||
|
*/
|
||||||
|
export function addStyle(customStyle, target = 'object') {
|
||||||
|
// 字符串转字符串,对象转对象情形,直接返回
|
||||||
|
if (
|
||||||
|
test.empty(customStyle) ||
|
||||||
|
(typeof customStyle === 'object' && target === 'object') ||
|
||||||
|
(target === 'string' && typeof customStyle === 'string')
|
||||||
|
) {
|
||||||
|
return customStyle;
|
||||||
|
}
|
||||||
|
// 字符串转对象
|
||||||
|
if (target === 'object') {
|
||||||
|
// 去除字符串样式中的两端空格(中间的空格不能去掉,比如padding: 20px 0如果去掉了就错了),空格是无用的
|
||||||
|
customStyle = trim(customStyle);
|
||||||
|
// 根据";"将字符串转为数组形式
|
||||||
|
const styleArray = customStyle.split(';');
|
||||||
|
const style = {};
|
||||||
|
// 历遍数组,拼接成对象
|
||||||
|
for (let i = 0; i < styleArray.length; i++) {
|
||||||
|
// 'font-size:20px;color:red;',如此最后字符串有";"的话,会导致styleArray最后一个元素为空字符串,这里需要过滤
|
||||||
|
if (styleArray[i]) {
|
||||||
|
const item = styleArray[i].split(':');
|
||||||
|
style[trim(item[0])] = trim(item[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
// 这里为对象转字符串形式
|
||||||
|
let string = '';
|
||||||
|
for (const i in customStyle) {
|
||||||
|
// 驼峰转为中划线的形式,否则css内联样式,无法识别驼峰样式属性名
|
||||||
|
const key = i.replace(/([A-Z])/g, '-$1').toLowerCase();
|
||||||
|
string += `${key}:${customStyle[i]};`;
|
||||||
|
}
|
||||||
|
// 去除两端空格
|
||||||
|
return trim(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 添加单位,如果有rpx,upx,%,px等单位结尾或者值为auto,直接返回,否则加上px单位结尾
|
||||||
|
* @param {string|number} value 需要添加单位的值
|
||||||
|
* @param {string} unit 添加的单位名 比如px
|
||||||
|
*/
|
||||||
|
export function addUnit(value = 'auto', unit = 'px') {
|
||||||
|
value = String(value);
|
||||||
|
return test.number(value) ? `${value}${unit}` : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 深度克隆
|
||||||
|
* @param {object} obj 需要深度克隆的对象
|
||||||
|
* @returns {*} 克隆后的对象或者原值(不是对象)
|
||||||
|
*/
|
||||||
|
function deepClone(obj) {
|
||||||
|
// 对常见的“非”值,直接返回原来值
|
||||||
|
if ([null, undefined, NaN, false].includes(obj)) return obj;
|
||||||
|
if (typeof obj !== 'object' && typeof obj !== 'function') {
|
||||||
|
// 原始类型直接返回
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
const o = test.array(obj) ? [] : {};
|
||||||
|
for (const i in obj) {
|
||||||
|
if (obj.hasOwnProperty(i)) {
|
||||||
|
o[i] = typeof obj[i] === 'object' ? deepClone(obj[i]) : obj[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description JS对象深度合并
|
||||||
|
* @param {object} target 需要拷贝的对象
|
||||||
|
* @param {object} source 拷贝的来源对象
|
||||||
|
* @returns {object|boolean} 深度合并后的对象或者false(入参有不是对象)
|
||||||
|
*/
|
||||||
|
export function deepMerge(target = {}, source = {}) {
|
||||||
|
target = deepClone(target);
|
||||||
|
if (typeof target !== 'object' || typeof source !== 'object') return false;
|
||||||
|
for (const prop in source) {
|
||||||
|
if (!source.hasOwnProperty(prop)) continue;
|
||||||
|
if (prop in target) {
|
||||||
|
if (typeof target[prop] !== 'object') {
|
||||||
|
target[prop] = source[prop];
|
||||||
|
} else if (typeof source[prop] !== 'object') {
|
||||||
|
target[prop] = source[prop];
|
||||||
|
} else if (target[prop].concat && source[prop].concat) {
|
||||||
|
target[prop] = target[prop].concat(source[prop]);
|
||||||
|
} else {
|
||||||
|
target[prop] = deepMerge(target[prop], source[prop]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
target[prop] = source[prop];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description error提示
|
||||||
|
* @param {*} err 错误内容
|
||||||
|
*/
|
||||||
|
function error(err) {
|
||||||
|
// 开发环境才提示,生产环境不会提示
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.error(`SheepJS:${err}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 打乱数组
|
||||||
|
* @param {array} array 需要打乱的数组
|
||||||
|
* @returns {array} 打乱后的数组
|
||||||
|
*/
|
||||||
|
function randomArray(array = []) {
|
||||||
|
// 原理是sort排序,Math.random()产生0<= x < 1之间的数,会导致x-0.05大于或者小于0
|
||||||
|
return array.sort(() => Math.random() - 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
// padStart 的 polyfill,因为某些机型或情况,还无法支持es7的padStart,比如电脑版的微信小程序
|
||||||
|
// 所以这里做一个兼容polyfill的兼容处理
|
||||||
|
if (!String.prototype.padStart) {
|
||||||
|
// 为了方便表示这里 fillString 用了ES6 的默认参数,不影响理解
|
||||||
|
String.prototype.padStart = function (maxLength, fillString = ' ') {
|
||||||
|
if (Object.prototype.toString.call(fillString) !== '[object String]') {
|
||||||
|
throw new TypeError('fillString must be String');
|
||||||
|
}
|
||||||
|
const str = this;
|
||||||
|
// 返回 String(str) 这里是为了使返回的值是字符串字面量,在控制台中更符合直觉
|
||||||
|
if (str.length >= maxLength) return String(str);
|
||||||
|
|
||||||
|
const fillLength = maxLength - str.length;
|
||||||
|
let times = Math.ceil(fillLength / fillString.length);
|
||||||
|
while ((times >>= 1)) {
|
||||||
|
fillString += fillString;
|
||||||
|
if (times === 1) {
|
||||||
|
fillString += fillString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fillString.slice(0, fillLength) + str;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 格式化时间
|
||||||
|
* @param {String|Number} dateTime 需要格式化的时间戳
|
||||||
|
* @param {String} fmt 格式化规则 yyyy:mm:dd|yyyy:mm|yyyy年mm月dd日|yyyy年mm月dd日 hh时MM分等,可自定义组合 默认yyyy-mm-dd
|
||||||
|
* @returns {string} 返回格式化后的字符串
|
||||||
|
*/
|
||||||
|
function timeFormat(dateTime = null, formatStr = 'yyyy-mm-dd') {
|
||||||
|
let date;
|
||||||
|
// 若传入时间为假值,则取当前时间
|
||||||
|
if (!dateTime) {
|
||||||
|
date = new Date();
|
||||||
|
}
|
||||||
|
// 若为unix秒时间戳,则转为毫秒时间戳(逻辑有点奇怪,但不敢改,以保证历史兼容)
|
||||||
|
else if (/^\d{10}$/.test(dateTime?.toString().trim())) {
|
||||||
|
date = new Date(dateTime * 1000);
|
||||||
|
}
|
||||||
|
// 若用户传入字符串格式时间戳,new Date无法解析,需做兼容
|
||||||
|
else if (typeof dateTime === 'string' && /^\d+$/.test(dateTime.trim())) {
|
||||||
|
date = new Date(Number(dateTime));
|
||||||
|
}
|
||||||
|
// 其他都认为符合 RFC 2822 规范
|
||||||
|
else {
|
||||||
|
// 处理平台性差异,在Safari/Webkit中,new Date仅支持/作为分割符的字符串时间
|
||||||
|
date = new Date(typeof dateTime === 'string' ? dateTime.replace(/-/g, '/') : dateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeSource = {
|
||||||
|
y: date.getFullYear().toString(), // 年
|
||||||
|
m: (date.getMonth() + 1).toString().padStart(2, '0'), // 月
|
||||||
|
d: date.getDate().toString().padStart(2, '0'), // 日
|
||||||
|
h: date.getHours().toString().padStart(2, '0'), // 时
|
||||||
|
M: date.getMinutes().toString().padStart(2, '0'), // 分
|
||||||
|
s: date.getSeconds().toString().padStart(2, '0'), // 秒
|
||||||
|
// 有其他格式化字符需求可以继续添加,必须转化成字符串
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const key in timeSource) {
|
||||||
|
const [ret] = new RegExp(`${key}+`).exec(formatStr) || [];
|
||||||
|
if (ret) {
|
||||||
|
// 年可能只需展示两位
|
||||||
|
const beginIndex = key === 'y' && ret.length === 2 ? 2 : 0;
|
||||||
|
formatStr = formatStr.replace(ret, timeSource[key].slice(beginIndex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 时间戳转为多久之前
|
||||||
|
* @param {String|Number} timestamp 时间戳
|
||||||
|
* @param {String|Boolean} format
|
||||||
|
* 格式化规则如果为时间格式字符串,超出一定时间范围,返回固定的时间格式;
|
||||||
|
* 如果为布尔值false,无论什么时间,都返回多久以前的格式
|
||||||
|
* @returns {string} 转化后的内容
|
||||||
|
*/
|
||||||
|
function timeFrom(timestamp = null, format = 'yyyy-mm-dd') {
|
||||||
|
if (timestamp == null) timestamp = Number(new Date());
|
||||||
|
timestamp = parseInt(timestamp);
|
||||||
|
// 判断用户输入的时间戳是秒还是毫秒,一般前端js获取的时间戳是毫秒(13位),后端传过来的为秒(10位)
|
||||||
|
if (timestamp.toString().length == 10) timestamp *= 1000;
|
||||||
|
let timer = new Date().getTime() - timestamp;
|
||||||
|
timer = parseInt(timer / 1000);
|
||||||
|
// 如果小于5分钟,则返回"刚刚",其他以此类推
|
||||||
|
let tips = '';
|
||||||
|
switch (true) {
|
||||||
|
case timer < 300:
|
||||||
|
tips = '刚刚';
|
||||||
|
break;
|
||||||
|
case timer >= 300 && timer < 3600:
|
||||||
|
tips = `${parseInt(timer / 60)}分钟前`;
|
||||||
|
break;
|
||||||
|
case timer >= 3600 && timer < 86400:
|
||||||
|
tips = `${parseInt(timer / 3600)}小时前`;
|
||||||
|
break;
|
||||||
|
case timer >= 86400 && timer < 2592000:
|
||||||
|
tips = `${parseInt(timer / 86400)}天前`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// 如果format为false,则无论什么时间戳,都显示xx之前
|
||||||
|
if (format === false) {
|
||||||
|
if (timer >= 2592000 && timer < 365 * 86400) {
|
||||||
|
tips = `${parseInt(timer / (86400 * 30))}个月前`;
|
||||||
|
} else {
|
||||||
|
tips = `${parseInt(timer / (86400 * 365))}年前`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tips = timeFormat(timestamp, format);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tips;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 去除空格
|
||||||
|
* @param String str 需要去除空格的字符串
|
||||||
|
* @param String pos both(左右)|left|right|all 默认both
|
||||||
|
*/
|
||||||
|
function trim(str, pos = 'both') {
|
||||||
|
str = String(str);
|
||||||
|
if (pos == 'both') {
|
||||||
|
return str.replace(/^\s+|\s+$/g, '');
|
||||||
|
}
|
||||||
|
if (pos == 'left') {
|
||||||
|
return str.replace(/^\s*/, '');
|
||||||
|
}
|
||||||
|
if (pos == 'right') {
|
||||||
|
return str.replace(/(\s*$)/g, '');
|
||||||
|
}
|
||||||
|
if (pos == 'all') {
|
||||||
|
return str.replace(/\s+/g, '');
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 对象转url参数
|
||||||
|
* @param {object} data,对象
|
||||||
|
* @param {Boolean} isPrefix,是否自动加上"?"
|
||||||
|
* @param {string} arrayFormat 规则 indices|brackets|repeat|comma
|
||||||
|
*/
|
||||||
|
function queryParams(data = {}, isPrefix = true, arrayFormat = 'brackets') {
|
||||||
|
const prefix = isPrefix ? '?' : '';
|
||||||
|
const _result = [];
|
||||||
|
if (['indices', 'brackets', 'repeat', 'comma'].indexOf(arrayFormat) == -1)
|
||||||
|
arrayFormat = 'brackets';
|
||||||
|
for (const key in data) {
|
||||||
|
const value = data[key];
|
||||||
|
// 去掉为空的参数
|
||||||
|
if (['', undefined, null].indexOf(value) >= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 如果值为数组,另行处理
|
||||||
|
if (value.constructor === Array) {
|
||||||
|
// e.g. {ids: [1, 2, 3]}
|
||||||
|
switch (arrayFormat) {
|
||||||
|
case 'indices':
|
||||||
|
// 结果: ids[0]=1&ids[1]=2&ids[2]=3
|
||||||
|
for (let i = 0; i < value.length; i++) {
|
||||||
|
_result.push(`${key}[${i}]=${value[i]}`);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'brackets':
|
||||||
|
// 结果: ids[]=1&ids[]=2&ids[]=3
|
||||||
|
value.forEach((_value) => {
|
||||||
|
_result.push(`${key}[]=${_value}`);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'repeat':
|
||||||
|
// 结果: ids=1&ids=2&ids=3
|
||||||
|
value.forEach((_value) => {
|
||||||
|
_result.push(`${key}=${_value}`);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'comma':
|
||||||
|
// 结果: ids=1,2,3
|
||||||
|
let commaStr = '';
|
||||||
|
value.forEach((_value) => {
|
||||||
|
commaStr += (commaStr ? ',' : '') + _value;
|
||||||
|
});
|
||||||
|
_result.push(`${key}=${commaStr}`);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
value.forEach((_value) => {
|
||||||
|
_result.push(`${key}[]=${_value}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_result.push(`${key}=${value}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _result.length ? prefix + _result.join('&') : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示消息提示框
|
||||||
|
* @param {String} title 提示的内容,长度与 icon 取值有关。
|
||||||
|
* @param {Number} duration 提示的延迟时间,单位毫秒,默认:2000
|
||||||
|
*/
|
||||||
|
function toast(title, duration = 2000) {
|
||||||
|
uni.showToast({
|
||||||
|
title: String(title),
|
||||||
|
icon: 'none',
|
||||||
|
duration,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 根据主题type值,获取对应的图标
|
||||||
|
* @param {String} type 主题名称,primary|info|error|warning|success
|
||||||
|
* @param {boolean} fill 是否使用fill填充实体的图标
|
||||||
|
*/
|
||||||
|
function type2icon(type = 'success', fill = false) {
|
||||||
|
// 如果非预置值,默认为success
|
||||||
|
if (['primary', 'info', 'error', 'warning', 'success'].indexOf(type) == -1) type = 'success';
|
||||||
|
let iconName = '';
|
||||||
|
// 目前(2019-12-12),info和primary使用同一个图标
|
||||||
|
switch (type) {
|
||||||
|
case 'primary':
|
||||||
|
iconName = 'info-circle';
|
||||||
|
break;
|
||||||
|
case 'info':
|
||||||
|
iconName = 'info-circle';
|
||||||
|
break;
|
||||||
|
case 'error':
|
||||||
|
iconName = 'close-circle';
|
||||||
|
break;
|
||||||
|
case 'warning':
|
||||||
|
iconName = 'error-circle';
|
||||||
|
break;
|
||||||
|
case 'success':
|
||||||
|
iconName = 'checkmark-circle';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
iconName = 'checkmark-circle';
|
||||||
|
}
|
||||||
|
// 是否是实体类型,加上-fill,在icon组件库中,实体的类名是后面加-fill的
|
||||||
|
if (fill) iconName += '-fill';
|
||||||
|
return iconName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 数字格式化
|
||||||
|
* @param {number|string} number 要格式化的数字
|
||||||
|
* @param {number} decimals 保留几位小数
|
||||||
|
* @param {string} decimalPoint 小数点符号
|
||||||
|
* @param {string} thousandsSeparator 千分位符号
|
||||||
|
* @returns {string} 格式化后的数字
|
||||||
|
*/
|
||||||
|
function priceFormat(number, decimals = 0, decimalPoint = '.', thousandsSeparator = ',') {
|
||||||
|
number = `${number}`.replace(/[^0-9+-Ee.]/g, '');
|
||||||
|
const n = !isFinite(+number) ? 0 : +number;
|
||||||
|
const prec = !isFinite(+decimals) ? 0 : Math.abs(decimals);
|
||||||
|
const sep = typeof thousandsSeparator === 'undefined' ? ',' : thousandsSeparator;
|
||||||
|
const dec = typeof decimalPoint === 'undefined' ? '.' : decimalPoint;
|
||||||
|
let s = '';
|
||||||
|
|
||||||
|
s = (prec ? round(n, prec) + '' : `${Math.round(n)}`).split('.');
|
||||||
|
const re = /(-?\d+)(\d{3})/;
|
||||||
|
while (re.test(s[0])) {
|
||||||
|
s[0] = s[0].replace(re, `$1${sep}$2`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((s[1] || '').length < prec) {
|
||||||
|
s[1] = s[1] || '';
|
||||||
|
s[1] += new Array(prec - s[1].length + 1).join('0');
|
||||||
|
}
|
||||||
|
return s.join(dec);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 获取duration值
|
||||||
|
* 如果带有ms或者s直接返回,如果大于一定值,认为是ms单位,小于一定值,认为是s单位
|
||||||
|
* 比如以30位阈值,那么300大于30,可以理解为用户想要的是300ms,而不是想花300s去执行一个动画
|
||||||
|
* @param {String|number} value 比如: "1s"|"100ms"|1|100
|
||||||
|
* @param {boolean} unit 提示: 如果是false 默认返回number
|
||||||
|
* @return {string|number}
|
||||||
|
*/
|
||||||
|
function getDuration(value, unit = true) {
|
||||||
|
const valueNum = parseInt(value);
|
||||||
|
if (unit) {
|
||||||
|
if (/s$/.test(value)) return value;
|
||||||
|
return value > 30 ? `${value}ms` : `${value}s`;
|
||||||
|
}
|
||||||
|
if (/ms$/.test(value)) return valueNum;
|
||||||
|
if (/s$/.test(value)) return valueNum > 30 ? valueNum : valueNum * 1000;
|
||||||
|
return valueNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 日期的月或日补零操作
|
||||||
|
* @param {String} value 需要补零的值
|
||||||
|
*/
|
||||||
|
function padZero(value) {
|
||||||
|
return `00${value}`.slice(-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 获取某个对象下的属性,用于通过类似'a.b.c'的形式去获取一个对象的的属性的形式
|
||||||
|
* @param {object} obj 对象
|
||||||
|
* @param {string} key 需要获取的属性字段
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
function getProperty(obj, key) {
|
||||||
|
if (!obj) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (typeof key !== 'string' || key === '') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
if (key.indexOf('.') !== -1) {
|
||||||
|
const keys = key.split('.');
|
||||||
|
let firstObj = obj[keys[0]] || {};
|
||||||
|
|
||||||
|
for (let i = 1; i < keys.length; i++) {
|
||||||
|
if (firstObj) {
|
||||||
|
firstObj = firstObj[keys[i]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return firstObj;
|
||||||
|
}
|
||||||
|
return obj[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 设置对象的属性值,如果'a.b.c'的形式进行设置
|
||||||
|
* @param {object} obj 对象
|
||||||
|
* @param {string} key 需要设置的属性
|
||||||
|
* @param {string} value 设置的值
|
||||||
|
*/
|
||||||
|
function setProperty(obj, key, value) {
|
||||||
|
if (!obj) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 递归赋值
|
||||||
|
const inFn = function (_obj, keys, v) {
|
||||||
|
// 最后一个属性key
|
||||||
|
if (keys.length === 1) {
|
||||||
|
_obj[keys[0]] = v;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 0~length-1个key
|
||||||
|
while (keys.length > 1) {
|
||||||
|
const k = keys[0];
|
||||||
|
if (!_obj[k] || typeof _obj[k] !== 'object') {
|
||||||
|
_obj[k] = {};
|
||||||
|
}
|
||||||
|
const key = keys.shift();
|
||||||
|
// 自调用判断是否存在属性,不存在则自动创建对象
|
||||||
|
inFn(_obj[k], keys, v);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof key !== 'string' || key === '') {
|
||||||
|
} else if (key.indexOf('.') !== -1) {
|
||||||
|
// 支持多层级赋值操作
|
||||||
|
const keys = key.split('.');
|
||||||
|
inFn(obj, keys, value);
|
||||||
|
} else {
|
||||||
|
obj[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 获取当前页面路径
|
||||||
|
*/
|
||||||
|
function page() {
|
||||||
|
const pages = getCurrentPages();
|
||||||
|
// 某些特殊情况下(比如页面进行redirectTo时的一些时机),pages可能为空数组
|
||||||
|
return `/${pages[pages.length - 1]?.route || ''}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 获取当前路由栈实例数组
|
||||||
|
*/
|
||||||
|
function pages() {
|
||||||
|
const pages = getCurrentPages();
|
||||||
|
return pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取H5-真实根地址 兼容hash+history模式
|
||||||
|
*/
|
||||||
|
export function getRootUrl() {
|
||||||
|
let url = '';
|
||||||
|
// #ifdef H5
|
||||||
|
url = location.origin + '/';
|
||||||
|
|
||||||
|
if (location.hash !== '') {
|
||||||
|
url += '#/';
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* copyText 多端复制文本
|
||||||
|
*/
|
||||||
|
export function copyText(text) {
|
||||||
|
// #ifndef H5
|
||||||
|
uni.setClipboardData({
|
||||||
|
data: text,
|
||||||
|
success: function () {
|
||||||
|
toast('复制成功!');
|
||||||
|
},
|
||||||
|
fail: function () {
|
||||||
|
toast('复制失败!');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// #endif
|
||||||
|
// #ifdef H5
|
||||||
|
var createInput = document.createElement('textarea');
|
||||||
|
createInput.value = text;
|
||||||
|
document.body.appendChild(createInput);
|
||||||
|
createInput.select();
|
||||||
|
document.execCommand('Copy');
|
||||||
|
createInput.className = 'createInput';
|
||||||
|
createInput.style.display = 'none';
|
||||||
|
toast('复制成功');
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
range,
|
||||||
|
getPx,
|
||||||
|
sleep,
|
||||||
|
os,
|
||||||
|
sys,
|
||||||
|
random,
|
||||||
|
guid,
|
||||||
|
$parent,
|
||||||
|
addStyle,
|
||||||
|
addUnit,
|
||||||
|
deepClone,
|
||||||
|
deepMerge,
|
||||||
|
error,
|
||||||
|
randomArray,
|
||||||
|
timeFormat,
|
||||||
|
timeFrom,
|
||||||
|
trim,
|
||||||
|
queryParams,
|
||||||
|
toast,
|
||||||
|
type2icon,
|
||||||
|
priceFormat,
|
||||||
|
getDuration,
|
||||||
|
padZero,
|
||||||
|
getProperty,
|
||||||
|
setProperty,
|
||||||
|
page,
|
||||||
|
pages,
|
||||||
|
test,
|
||||||
|
getRootUrl,
|
||||||
|
copyText,
|
||||||
|
};
|
||||||
285
sheep/helper/test.js
Normal file
285
sheep/helper/test.js
Normal file
@@ -0,0 +1,285 @@
|
|||||||
|
/**
|
||||||
|
* 验证电子邮箱格式
|
||||||
|
*/
|
||||||
|
function email(value) {
|
||||||
|
return /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证手机格式
|
||||||
|
*/
|
||||||
|
function mobile(value) {
|
||||||
|
return /^1[23456789]\d{9}$/.test(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证URL格式
|
||||||
|
*/
|
||||||
|
function url(value) {
|
||||||
|
return /^((https|http|ftp|rtsp|mms):\/\/)(([0-9a-zA-Z_!~*'().&=+$%-]+: )?[0-9a-zA-Z_!~*'().&=+$%-]+@)?(([0-9]{1,3}.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z].[a-zA-Z]{2,6})(:[0-9]{1,4})?((\/?)|(\/[0-9a-zA-Z_!~*'().;?:@&=+$,%#-]+)+\/?)$/.test(
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证日期格式
|
||||||
|
*/
|
||||||
|
function date(value) {
|
||||||
|
if (!value) return false;
|
||||||
|
// 判断是否数值或者字符串数值(意味着为时间戳),转为数值,否则new Date无法识别字符串时间戳
|
||||||
|
if (number(value)) value = +value;
|
||||||
|
return !/Invalid|NaN/.test(new Date(value).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证ISO类型的日期格式
|
||||||
|
*/
|
||||||
|
function dateISO(value) {
|
||||||
|
return /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证十进制数字
|
||||||
|
*/
|
||||||
|
function number(value) {
|
||||||
|
return /^[\+-]?(\d+\.?\d*|\.\d+|\d\.\d+e\+\d+)$/.test(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证字符串
|
||||||
|
*/
|
||||||
|
function string(value) {
|
||||||
|
return typeof value === 'string';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证整数
|
||||||
|
*/
|
||||||
|
function digits(value) {
|
||||||
|
return /^\d+$/.test(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证身份证号码
|
||||||
|
*/
|
||||||
|
function idCard(value) {
|
||||||
|
return /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否车牌号
|
||||||
|
*/
|
||||||
|
function carNo(value) {
|
||||||
|
// 新能源车牌
|
||||||
|
const xreg =
|
||||||
|
/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DF]$)|([DF][A-HJ-NP-Z0-9][0-9]{4}$))/;
|
||||||
|
// 旧车牌
|
||||||
|
const creg =
|
||||||
|
/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
|
||||||
|
if (value.length === 7) {
|
||||||
|
return creg.test(value);
|
||||||
|
}
|
||||||
|
if (value.length === 8) {
|
||||||
|
return xreg.test(value);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 金额,只允许2位小数
|
||||||
|
*/
|
||||||
|
function amount(value) {
|
||||||
|
// 金额,只允许保留两位小数
|
||||||
|
return /^[1-9]\d*(,\d{3})*(\.\d{1,2})?$|^0\.\d{1,2}$/.test(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 中文
|
||||||
|
*/
|
||||||
|
function chinese(value) {
|
||||||
|
const reg = /^[\u4e00-\u9fa5]+$/gi;
|
||||||
|
return reg.test(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 只能输入字母
|
||||||
|
*/
|
||||||
|
function letter(value) {
|
||||||
|
return /^[a-zA-Z]*$/.test(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 只能是字母或者数字
|
||||||
|
*/
|
||||||
|
function enOrNum(value) {
|
||||||
|
// 英文或者数字
|
||||||
|
const reg = /^[0-9a-zA-Z]*$/g;
|
||||||
|
return reg.test(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证是否包含某个值
|
||||||
|
*/
|
||||||
|
function contains(value, param) {
|
||||||
|
return value.indexOf(param) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证一个值范围[min, max]
|
||||||
|
*/
|
||||||
|
function range(value, param) {
|
||||||
|
return value >= param[0] && value <= param[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证一个长度范围[min, max]
|
||||||
|
*/
|
||||||
|
function rangeLength(value, param) {
|
||||||
|
return value.length >= param[0] && value.length <= param[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否固定电话
|
||||||
|
*/
|
||||||
|
function landline(value) {
|
||||||
|
const reg = /^\d{3,4}-\d{7,8}(-\d{3,4})?$/;
|
||||||
|
return reg.test(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否为空
|
||||||
|
*/
|
||||||
|
function empty(value) {
|
||||||
|
switch (typeof value) {
|
||||||
|
case 'undefined':
|
||||||
|
return true;
|
||||||
|
case 'string':
|
||||||
|
if (value.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '').length == 0) return true;
|
||||||
|
break;
|
||||||
|
case 'boolean':
|
||||||
|
if (!value) return true;
|
||||||
|
break;
|
||||||
|
case 'number':
|
||||||
|
if (value === 0 || isNaN(value)) return true;
|
||||||
|
break;
|
||||||
|
case 'object':
|
||||||
|
if (value === null || value.length === 0) return true;
|
||||||
|
for (const i in value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否json字符串
|
||||||
|
*/
|
||||||
|
function jsonString(value) {
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
try {
|
||||||
|
const obj = JSON.parse(value);
|
||||||
|
if (typeof obj === 'object' && obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否数组
|
||||||
|
*/
|
||||||
|
function array(value) {
|
||||||
|
if (typeof Array.isArray === 'function') {
|
||||||
|
return Array.isArray(value);
|
||||||
|
}
|
||||||
|
return Object.prototype.toString.call(value) === '[object Array]';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否对象
|
||||||
|
*/
|
||||||
|
function object(value) {
|
||||||
|
return Object.prototype.toString.call(value) === '[object Object]';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否短信验证码
|
||||||
|
*/
|
||||||
|
function code(value, len = 6) {
|
||||||
|
return new RegExp(`^\\d{${len}}$`).test(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否函数方法
|
||||||
|
* @param {Object} value
|
||||||
|
*/
|
||||||
|
function func(value) {
|
||||||
|
return typeof value === 'function';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否promise对象
|
||||||
|
* @param {Object} value
|
||||||
|
*/
|
||||||
|
function promise(value) {
|
||||||
|
return object(value) && func(value.then) && func(value.catch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 是否图片格式
|
||||||
|
* @param {Object} value
|
||||||
|
*/
|
||||||
|
function image(value) {
|
||||||
|
const newValue = value.split('?')[0];
|
||||||
|
const IMAGE_REGEXP = /\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg)/i;
|
||||||
|
return IMAGE_REGEXP.test(newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否视频格式
|
||||||
|
* @param {Object} value
|
||||||
|
*/
|
||||||
|
function video(value) {
|
||||||
|
const VIDEO_REGEXP = /\.(mp4|mpg|mpeg|dat|asf|avi|rm|rmvb|mov|wmv|flv|mkv|m3u8)/i;
|
||||||
|
return VIDEO_REGEXP.test(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为正则对象
|
||||||
|
* @param {Object}
|
||||||
|
* @return {Boolean}
|
||||||
|
*/
|
||||||
|
function regExp(o) {
|
||||||
|
return o && Object.prototype.toString.call(o) === '[object RegExp]';
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
email,
|
||||||
|
mobile,
|
||||||
|
url,
|
||||||
|
date,
|
||||||
|
dateISO,
|
||||||
|
number,
|
||||||
|
digits,
|
||||||
|
idCard,
|
||||||
|
carNo,
|
||||||
|
amount,
|
||||||
|
chinese,
|
||||||
|
letter,
|
||||||
|
enOrNum,
|
||||||
|
contains,
|
||||||
|
range,
|
||||||
|
rangeLength,
|
||||||
|
empty,
|
||||||
|
isEmpty: empty,
|
||||||
|
isNumber: number,
|
||||||
|
jsonString,
|
||||||
|
landline,
|
||||||
|
object,
|
||||||
|
array,
|
||||||
|
code,
|
||||||
|
};
|
||||||
31
sheep/helper/throttle.js
Normal file
31
sheep/helper/throttle.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
let timer;
|
||||||
|
let flag;
|
||||||
|
/**
|
||||||
|
* 节流原理:在一定时间内,只能触发一次
|
||||||
|
*
|
||||||
|
* @param {Function} func 要执行的回调函数
|
||||||
|
* @param {Number} wait 延时的时间
|
||||||
|
* @param {Boolean} immediate 是否立即执行
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
function throttle(func, wait = 500, immediate = true) {
|
||||||
|
if (immediate) {
|
||||||
|
if (!flag) {
|
||||||
|
flag = true;
|
||||||
|
// 如果是立即执行,则在wait毫秒内开始时执行
|
||||||
|
typeof func === 'function' && func();
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
flag = false;
|
||||||
|
}, wait);
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
} else if (!flag) {
|
||||||
|
flag = true;
|
||||||
|
// 如果是非立即执行,则在wait毫秒内的结束处执行
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
flag = false;
|
||||||
|
typeof func === 'function' && func();
|
||||||
|
}, wait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default throttle;
|
||||||
67
sheep/helper/tools.js
Normal file
67
sheep/helper/tools.js
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import router from '@/sheep/router';
|
||||||
|
export default {
|
||||||
|
/**
|
||||||
|
* 打电话
|
||||||
|
* @param {String<Number>} phoneNumber - 数字字符串
|
||||||
|
*/
|
||||||
|
callPhone(phoneNumber = '') {
|
||||||
|
let num = phoneNumber.toString();
|
||||||
|
uni.makePhoneCall({
|
||||||
|
phoneNumber: num,
|
||||||
|
fail(err) {
|
||||||
|
console.log('makePhoneCall出错', err);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信头像
|
||||||
|
* @param {String} url -图片地址
|
||||||
|
*/
|
||||||
|
checkMPUrl(url) {
|
||||||
|
// #ifdef MP
|
||||||
|
if (
|
||||||
|
url.substring(0, 4) === 'http' &&
|
||||||
|
url.substring(0, 5) !== 'https' &&
|
||||||
|
url.substring(0, 12) !== 'http://store' &&
|
||||||
|
url.substring(0, 10) !== 'http://tmp' &&
|
||||||
|
url.substring(0, 10) !== 'http://usr'
|
||||||
|
) {
|
||||||
|
url = 'https' + url.substring(4, url.length);
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
return url;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getUuid 生成唯一id
|
||||||
|
*/
|
||||||
|
getUuid(len = 32, firstU = true, radix = null) {
|
||||||
|
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
|
||||||
|
const uuid = [];
|
||||||
|
radix = radix || chars.length;
|
||||||
|
|
||||||
|
if (len) {
|
||||||
|
// 如果指定uuid长度,只是取随机的字符,0|x为位运算,能去掉x的小数位,返回整数位
|
||||||
|
for (let i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
|
||||||
|
} else {
|
||||||
|
let r;
|
||||||
|
// rfc4122标准要求返回的uuid中,某些位为固定的字符
|
||||||
|
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
|
||||||
|
uuid[14] = '4';
|
||||||
|
|
||||||
|
for (let i = 0; i < 36; i++) {
|
||||||
|
if (!uuid[i]) {
|
||||||
|
r = 0 | (Math.random() * 16);
|
||||||
|
uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 移除第一个字符,并用u替代,因为第一个字符为数值时,该guuid不能用作id或者class
|
||||||
|
if (firstU) {
|
||||||
|
uuid.shift();
|
||||||
|
return `u${uuid.join('')}`;
|
||||||
|
}
|
||||||
|
return uuid.join('');
|
||||||
|
},
|
||||||
|
};
|
||||||
172
sheep/helper/utils.js
Normal file
172
sheep/helper/utils.js
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
export function isArray(value) {
|
||||||
|
if (typeof Array.isArray === 'function') {
|
||||||
|
return Array.isArray(value);
|
||||||
|
} else {
|
||||||
|
return Object.prototype.toString.call(value) === '[object Array]';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isObject(value) {
|
||||||
|
return Object.prototype.toString.call(value) === '[object Object]';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isNumber(value) {
|
||||||
|
return !isNaN(Number(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isFunction(value) {
|
||||||
|
return typeof value == 'function';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isString(value) {
|
||||||
|
return typeof value == 'string';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isEmpty(value) {
|
||||||
|
if (value === '' || value === undefined || value === null){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isArray(value)) {
|
||||||
|
return value.length === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isObject(value)) {
|
||||||
|
return Object.keys(value).length === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isBoolean(value) {
|
||||||
|
return typeof value === 'boolean';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function last(data) {
|
||||||
|
if (isArray(data) || isString(data)) {
|
||||||
|
return data[data.length - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function cloneDeep(obj) {
|
||||||
|
const d = isArray(obj) ? [...obj] : {};
|
||||||
|
|
||||||
|
if (isObject(obj)) {
|
||||||
|
for (const key in obj) {
|
||||||
|
if (obj[key]) {
|
||||||
|
if (obj[key] && typeof obj[key] === 'object') {
|
||||||
|
d[key] = cloneDeep(obj[key]);
|
||||||
|
} else {
|
||||||
|
d[key] = obj[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clone(obj) {
|
||||||
|
return Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deepMerge(a, b) {
|
||||||
|
let k;
|
||||||
|
for (k in b) {
|
||||||
|
a[k] = a[k] && a[k].toString() === '[object Object]' ? deepMerge(a[k], b[k]) : (a[k] = b[k]);
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function contains(parent, node) {
|
||||||
|
while (node && (node = node.parentNode)) if (node === parent) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function orderBy(list, key) {
|
||||||
|
return list.sort((a, b) => a[key] - b[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deepTree(list) {
|
||||||
|
const newList = [];
|
||||||
|
const map = {};
|
||||||
|
|
||||||
|
list.forEach((e) => (map[e.id] = e));
|
||||||
|
|
||||||
|
list.forEach((e) => {
|
||||||
|
const parent = map[e.parentId];
|
||||||
|
|
||||||
|
if (parent) {
|
||||||
|
(parent.children || (parent.children = [])).push(e);
|
||||||
|
} else {
|
||||||
|
newList.push(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const fn = (list) => {
|
||||||
|
list.map((e) => {
|
||||||
|
if (e.children instanceof Array) {
|
||||||
|
e.children = orderBy(e.children, 'orderNum');
|
||||||
|
|
||||||
|
fn(e.children);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
fn(newList);
|
||||||
|
|
||||||
|
return orderBy(newList, 'orderNum');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function revDeepTree(list = []) {
|
||||||
|
const d = [];
|
||||||
|
let id = 0;
|
||||||
|
|
||||||
|
const deep = (list, parentId) => {
|
||||||
|
list.forEach((e) => {
|
||||||
|
if (!e.id) {
|
||||||
|
e.id = id++;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.parentId = parentId;
|
||||||
|
|
||||||
|
d.push(e);
|
||||||
|
|
||||||
|
if (e.children && isArray(e.children)) {
|
||||||
|
deep(e.children, e.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
deep(list || [], null);
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function basename(path) {
|
||||||
|
let index = path.lastIndexOf('/');
|
||||||
|
index = index > -1 ? index : path.lastIndexOf('\\');
|
||||||
|
if (index < 0) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
return path.substring(index + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isWxBrowser() {
|
||||||
|
const ua = navigator.userAgent.toLowerCase();
|
||||||
|
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 如果value小于min,取min;如果value大于max,取max
|
||||||
|
* @param {number} min
|
||||||
|
* @param {number} max
|
||||||
|
* @param {number} value
|
||||||
|
*/
|
||||||
|
export function range(min = 0, max = 0, value = 0) {
|
||||||
|
return Math.max(min, Math.min(max, Number(value)));
|
||||||
|
}
|
||||||
0
sheep/hooks/useApp.js
Normal file
0
sheep/hooks/useApp.js
Normal file
522
sheep/hooks/useGoods.js
Normal file
522
sheep/hooks/useGoods.js
Normal file
@@ -0,0 +1,522 @@
|
|||||||
|
import { ref } from 'vue';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import $url from '@/sheep/url';
|
||||||
|
import { formatDate } from '@/sheep/util';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化销量
|
||||||
|
* @param {'exact' | string} type 格式类型:exact=精确值,其它=大致数量
|
||||||
|
* @param {number} num 销量
|
||||||
|
* @return {string} 格式化后的销量字符串
|
||||||
|
*/
|
||||||
|
export function formatSales(type, num) {
|
||||||
|
let prefix = type !== 'exact' && num < 10 ? '销量:' : '已售:';
|
||||||
|
return formatNum(prefix, type, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化兑换量
|
||||||
|
* @param {'exact' | string} type 格式类型:exact=精确值,其它=大致数量
|
||||||
|
* @param {number} num 销量
|
||||||
|
* @return {string} 格式化后的销量字符串
|
||||||
|
*/
|
||||||
|
export function formatExchange(type, num) {
|
||||||
|
return formatNum('已兑换', type, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化库存
|
||||||
|
* @param {'exact' | any} type 格式类型:exact=精确值,其它=大致数量
|
||||||
|
* @param {number} num 销量
|
||||||
|
* @return {string} 格式化后的销量字符串
|
||||||
|
*/
|
||||||
|
export function formatStock(type, num) {
|
||||||
|
return formatNum('库存', type, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化数字
|
||||||
|
* @param {string} prefix 前缀
|
||||||
|
* @param {'exact' | string} type 格式类型:exact=精确值,其它=大致数量
|
||||||
|
* @param {number} num 销量
|
||||||
|
* @return {string} 格式化后的销量字符串
|
||||||
|
*/
|
||||||
|
export function formatNum(prefix, type, num) {
|
||||||
|
num = num || 0;
|
||||||
|
// 情况一:精确数值
|
||||||
|
if (type === 'exact') {
|
||||||
|
return prefix + num;
|
||||||
|
}
|
||||||
|
// 情况二:小于等于 10
|
||||||
|
if (num < 10) {
|
||||||
|
return `${prefix}≤10`;
|
||||||
|
}
|
||||||
|
// 情况三:大于 10,除第一位外,其它位都显示为0
|
||||||
|
// 例如:100 - 199 显示为 100+
|
||||||
|
// 9000 - 9999 显示为 9000+
|
||||||
|
const numStr = num.toString();
|
||||||
|
const first = numStr[0];
|
||||||
|
const other = '0'.repeat(numStr.length - 1);
|
||||||
|
return `${prefix}${first}${other}+`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化价格
|
||||||
|
export function formatPrice(e) {
|
||||||
|
return e.length === 1 ? e[0] : e.join('~');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 视频格式后缀列表
|
||||||
|
const VIDEO_SUFFIX_LIST = ['.avi', '.mp4'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换商品轮播的链接列表:根据链接的后缀,判断是视频链接还是图片链接
|
||||||
|
*
|
||||||
|
* @param {string[]} urlList 链接列表
|
||||||
|
* @return {{src: string, type: 'video' | 'image' }[]} 转换后的链接列表
|
||||||
|
*/
|
||||||
|
export function formatGoodsSwiper(urlList) {
|
||||||
|
return (
|
||||||
|
urlList
|
||||||
|
?.filter((url) => url)
|
||||||
|
.map((url, key) => {
|
||||||
|
const isVideo = VIDEO_SUFFIX_LIST.some((suffix) => url.includes(suffix));
|
||||||
|
const type = isVideo ? 'video' : 'image';
|
||||||
|
const src = $url.cdn(url);
|
||||||
|
return {
|
||||||
|
type,
|
||||||
|
src,
|
||||||
|
};
|
||||||
|
}) || []
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化订单状态的颜色
|
||||||
|
*
|
||||||
|
* @param order 订单
|
||||||
|
* @return {string} 颜色的 class 名称
|
||||||
|
*/
|
||||||
|
export function formatOrderColor(order) {
|
||||||
|
if (order.status === 0) {
|
||||||
|
return 'info-color';
|
||||||
|
}
|
||||||
|
// if (order.status === 10 || order.status === 20 || (order.status === 30 && !order.commentStatus)) {
|
||||||
|
// return 'warning-color';
|
||||||
|
// }
|
||||||
|
// if (order.status === 30 && order.commentStatus) {
|
||||||
|
// return 'success-color';
|
||||||
|
// }
|
||||||
|
if (order.status === 10 || order.status === 20) {
|
||||||
|
return 'warning-color';
|
||||||
|
}
|
||||||
|
if (order.status === 30) {
|
||||||
|
return 'success-color';
|
||||||
|
}
|
||||||
|
return 'danger-color';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化订单状态
|
||||||
|
*
|
||||||
|
* @param order 订单
|
||||||
|
*/
|
||||||
|
export function formatOrderStatus(order) {
|
||||||
|
if (order.status === 0) {
|
||||||
|
return '待付款';
|
||||||
|
}
|
||||||
|
if (order.status === 10 && (order.deliveryType === 1 || order.deliveryType === 3)) {
|
||||||
|
return '待发货';
|
||||||
|
}
|
||||||
|
if (order.status === 11 && (order.deliveryType === 1 || order.deliveryType === 3)) {
|
||||||
|
return '部分发货';
|
||||||
|
}
|
||||||
|
if (order.status === 10 && order.deliveryType === 2) {
|
||||||
|
return '待核销';
|
||||||
|
}
|
||||||
|
if (order.status === 20) {
|
||||||
|
return '待收货';
|
||||||
|
}
|
||||||
|
// if (order.status === 30 && !order.commentStatus) {
|
||||||
|
// return '待评价';
|
||||||
|
// }
|
||||||
|
// if (order.status === 30 && order.commentStatus) {
|
||||||
|
// return '已完成';
|
||||||
|
// }
|
||||||
|
if (order.status === 30) {
|
||||||
|
return '已完成';
|
||||||
|
}
|
||||||
|
if (order.status === 35) {
|
||||||
|
return '取消中';
|
||||||
|
}
|
||||||
|
return '已取消';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化订单状态的描述
|
||||||
|
*
|
||||||
|
* @param order 订单
|
||||||
|
*/
|
||||||
|
export function formatOrderStatusDescription(order) {
|
||||||
|
if (order.status === 0) {
|
||||||
|
return `请在 ${formatDate(order.payExpireTime)} 前完成支付`;
|
||||||
|
}
|
||||||
|
if (order.status === 10) {
|
||||||
|
return '商家未发货,请耐心等待';
|
||||||
|
}
|
||||||
|
if (order.status === 20) {
|
||||||
|
return '商家已发货,请耐心等待';
|
||||||
|
}
|
||||||
|
if (order.status === 30 && !order.commentStatus) {
|
||||||
|
return '已收货,快去评价一下吧';
|
||||||
|
}
|
||||||
|
if (order.status === 30 && order.commentStatus) {
|
||||||
|
return '交易完成,感谢您的支持';
|
||||||
|
}
|
||||||
|
return '交易关闭';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理订单的 button 操作按钮数组
|
||||||
|
*
|
||||||
|
* @param order 订单
|
||||||
|
*/
|
||||||
|
export function handleOrderButtons(order) {
|
||||||
|
order.buttons = [];
|
||||||
|
if (order.type === 3) {
|
||||||
|
// 查看拼团
|
||||||
|
order.buttons.push('combination');
|
||||||
|
}
|
||||||
|
if (order.status === 10 || order.status === 11 || order.status === 20) {
|
||||||
|
// 取消订单,若该订单状态为"待支付"、"待发货"、"部分发货"、"待收货",可取消订单
|
||||||
|
order.buttons.push('cancel');
|
||||||
|
}
|
||||||
|
if (order.status === 20) {
|
||||||
|
// 确认收货
|
||||||
|
order.buttons.push('confirm');
|
||||||
|
}
|
||||||
|
if (order.logisticsId > 0) {
|
||||||
|
// 查看物流
|
||||||
|
order.buttons.push('express');
|
||||||
|
}
|
||||||
|
if (order.status === 0) {
|
||||||
|
// 取消订单 / 发起支付
|
||||||
|
order.buttons.push('cancel');
|
||||||
|
order.buttons.push('pay');
|
||||||
|
}
|
||||||
|
if (order.status === 30 && !order.commentStatus) {
|
||||||
|
// 发起评价
|
||||||
|
order.buttons.push('comment');
|
||||||
|
}
|
||||||
|
if (order.status === 40) {
|
||||||
|
// 删除订单
|
||||||
|
order.buttons.push('delete');
|
||||||
|
}
|
||||||
|
if (order.status === 35) {
|
||||||
|
// 撤回取消
|
||||||
|
order.buttons.push('withdraw');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化售后状态
|
||||||
|
*
|
||||||
|
* @param afterSale 售后
|
||||||
|
*/
|
||||||
|
export function formatAfterSaleStatus(afterSale) {
|
||||||
|
if (afterSale.status === 10) {
|
||||||
|
return '申请售后';
|
||||||
|
}
|
||||||
|
if (afterSale.status === 20) {
|
||||||
|
return '商品待退货';
|
||||||
|
}
|
||||||
|
if (afterSale.status === 30) {
|
||||||
|
return '商家待收货';
|
||||||
|
}
|
||||||
|
if (afterSale.status === 40) {
|
||||||
|
return '等待退款';
|
||||||
|
}
|
||||||
|
if (afterSale.status === 50) {
|
||||||
|
return '退款成功';
|
||||||
|
}
|
||||||
|
if (afterSale.status === 61) {
|
||||||
|
return '买家取消';
|
||||||
|
}
|
||||||
|
if (afterSale.status === 62) {
|
||||||
|
return '商家拒绝';
|
||||||
|
}
|
||||||
|
if (afterSale.status === 63) {
|
||||||
|
return '商家拒收货';
|
||||||
|
}
|
||||||
|
return '未知状态';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化售后状态的描述
|
||||||
|
*
|
||||||
|
* @param afterSale 售后
|
||||||
|
*/
|
||||||
|
export function formatAfterSaleStatusDescription(afterSale) {
|
||||||
|
if (afterSale.status === 10) {
|
||||||
|
return '退款申请待商家处理';
|
||||||
|
}
|
||||||
|
if (afterSale.status === 20) {
|
||||||
|
return '请退货并填写物流信息';
|
||||||
|
}
|
||||||
|
if (afterSale.status === 30) {
|
||||||
|
return '退货退款申请待商家处理';
|
||||||
|
}
|
||||||
|
if (afterSale.status === 40) {
|
||||||
|
return '等待退款';
|
||||||
|
}
|
||||||
|
if (afterSale.status === 50) {
|
||||||
|
return '退款成功';
|
||||||
|
}
|
||||||
|
if (afterSale.status === 61) {
|
||||||
|
return '退款关闭';
|
||||||
|
}
|
||||||
|
if (afterSale.status === 62) {
|
||||||
|
return `商家不同意退款申请,拒绝原因:${afterSale.auditReason}`;
|
||||||
|
}
|
||||||
|
if (afterSale.status === 63) {
|
||||||
|
return `商家拒绝收货,不同意退款,拒绝原因:${afterSale.auditReason}`;
|
||||||
|
}
|
||||||
|
return '未知状态';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理售后的 button 操作按钮数组
|
||||||
|
*
|
||||||
|
* @param afterSale 售后
|
||||||
|
*/
|
||||||
|
export function handleAfterSaleButtons(afterSale) {
|
||||||
|
afterSale.buttons = [];
|
||||||
|
if ([10, 20, 30].includes(afterSale.status)) {
|
||||||
|
// 取消订单
|
||||||
|
afterSale.buttons.push('cancel');
|
||||||
|
}
|
||||||
|
if (afterSale.status === 20) {
|
||||||
|
// 退货信息
|
||||||
|
afterSale.buttons.push('delivery');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 倒计时
|
||||||
|
* @param toTime 截止时间
|
||||||
|
* @param fromTime 起始时间,默认当前时间
|
||||||
|
* @return {{s: string, ms: number, h: string, m: string}} 持续时间
|
||||||
|
*/
|
||||||
|
export function useDurationTime(toTime, fromTime = '') {
|
||||||
|
toTime = getDayjsTime(toTime);
|
||||||
|
if (fromTime === '') {
|
||||||
|
fromTime = dayjs();
|
||||||
|
}
|
||||||
|
let duration = ref(toTime - fromTime);
|
||||||
|
if (duration.value > 0) {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (duration.value > 0) {
|
||||||
|
duration.value -= 1000;
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
let durationTime = dayjs.duration(duration.value);
|
||||||
|
return {
|
||||||
|
h: (durationTime.months() * 30 * 24 + durationTime.days() * 24 + durationTime.hours())
|
||||||
|
.toString()
|
||||||
|
.padStart(2, '0'),
|
||||||
|
m: durationTime.minutes().toString().padStart(2, '0'),
|
||||||
|
s: durationTime.seconds().toString().padStart(2, '0'),
|
||||||
|
ms: durationTime.$ms,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换为 Dayjs
|
||||||
|
* @param {any} time 时间
|
||||||
|
* @return {dayjs.Dayjs}
|
||||||
|
*/
|
||||||
|
function getDayjsTime(time) {
|
||||||
|
time = time.toString();
|
||||||
|
if (time.indexOf('-') > 0) {
|
||||||
|
// 'date'
|
||||||
|
return dayjs(time);
|
||||||
|
}
|
||||||
|
if (time.length > 10) {
|
||||||
|
// 'timestamp'
|
||||||
|
return dayjs(parseInt(time));
|
||||||
|
}
|
||||||
|
if (time.length === 10) {
|
||||||
|
// 'unixTime'
|
||||||
|
return dayjs.unix(parseInt(time));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将分转成元
|
||||||
|
*
|
||||||
|
* @param price 分,例如说 100 分
|
||||||
|
* @returns {string} 元,例如说 1.00 元
|
||||||
|
*/
|
||||||
|
export function fen2yuan(price) {
|
||||||
|
return (price / 100.0).toFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将分转成元
|
||||||
|
*
|
||||||
|
* 如果没有小数点,则不展示小数点部分
|
||||||
|
*
|
||||||
|
* @param price 分,例如说 100 分
|
||||||
|
* @returns {string} 元,例如说 1 元
|
||||||
|
*/
|
||||||
|
export function fen2yuanSimple(price) {
|
||||||
|
return fen2yuan(price).replace(/\.?0+$/, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将折扣百分比转化为“打x者”的 x 部分
|
||||||
|
*
|
||||||
|
* @param discountPercent
|
||||||
|
*/
|
||||||
|
export function formatDiscountPercent(discountPercent) {
|
||||||
|
return (discountPercent / 10.0).toFixed(1).replace(/\.?0+$/, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从商品 SKU 数组中,转换出商品属性的数组
|
||||||
|
*
|
||||||
|
* 类似结构:[{
|
||||||
|
* id: // 属性的编号
|
||||||
|
* name: // 属性的名字
|
||||||
|
* values: [{
|
||||||
|
* id: // 属性值的编号
|
||||||
|
* name: // 属性值的名字
|
||||||
|
* }]
|
||||||
|
* }]
|
||||||
|
*
|
||||||
|
* @param skus 商品 SKU 数组
|
||||||
|
*/
|
||||||
|
export function convertProductPropertyList(skus) {
|
||||||
|
let result = [];
|
||||||
|
for (const sku of skus) {
|
||||||
|
if (!sku.properties) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (const property of sku.properties) {
|
||||||
|
// ① 先处理属性
|
||||||
|
let resultProperty = result.find((item) => item.id === property.propertyId);
|
||||||
|
if (!resultProperty) {
|
||||||
|
resultProperty = {
|
||||||
|
id: property.propertyId,
|
||||||
|
name: property.propertyName,
|
||||||
|
values: [],
|
||||||
|
};
|
||||||
|
result.push(resultProperty);
|
||||||
|
}
|
||||||
|
// ② 再处理属性值
|
||||||
|
let resultValue = resultProperty.values.find((item) => item.id === property.valueId);
|
||||||
|
if (!resultValue) {
|
||||||
|
resultProperty.values.push({
|
||||||
|
id: property.valueId,
|
||||||
|
name: property.valueName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function appendSettlementProduct(spus, settlementInfos) {
|
||||||
|
if (!settlementInfos || settlementInfos.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const spu of spus) {
|
||||||
|
const settlementInfo = settlementInfos.find((info) => info.spuId === spu.id);
|
||||||
|
if (!settlementInfo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 选择价格最小的 SKU 设置到 SPU 上
|
||||||
|
const settlementSku = settlementInfo.skus
|
||||||
|
.filter((sku) => sku.promotionPrice > 0)
|
||||||
|
.reduce((prev, curr) => (prev.promotionPrice < curr.promotionPrice ? prev : curr), []);
|
||||||
|
if (settlementSku) {
|
||||||
|
spu.promotionType = settlementSku.promotionType;
|
||||||
|
spu.promotionPrice = settlementSku.promotionPrice;
|
||||||
|
}
|
||||||
|
// 设置【满减送】活动
|
||||||
|
if (settlementInfo.rewardActivity) {
|
||||||
|
spu.rewardActivity = settlementInfo.rewardActivity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获得满减送活动的规则描述(group)
|
||||||
|
export function getRewardActivityRuleGroupDescriptions(activity) {
|
||||||
|
if (!activity || !activity.rules || activity.rules.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const result = [
|
||||||
|
{ name: '满减', values: [] },
|
||||||
|
{ name: '赠品', values: [] },
|
||||||
|
{ name: '包邮', values: [] },
|
||||||
|
];
|
||||||
|
activity.rules.forEach((rule) => {
|
||||||
|
const conditionTypeStr =
|
||||||
|
activity.conditionType === 10 ? `满 ${fen2yuanSimple(rule.limit)} 元` : `满 ${rule.limit} 件`;
|
||||||
|
// 满减
|
||||||
|
if (rule.limit) {
|
||||||
|
result[0].values.push(`${conditionTypeStr} 减 ${fen2yuanSimple(rule.discountPrice)} 元`);
|
||||||
|
}
|
||||||
|
// 赠品
|
||||||
|
if (rule.point || (rule.giveCouponTemplateCounts && rule.giveCouponTemplateCounts.length > 0)) {
|
||||||
|
let tips = [];
|
||||||
|
if (rule.point) {
|
||||||
|
tips.push(`送 ${rule.point} 积分`);
|
||||||
|
}
|
||||||
|
if (rule.giveCouponTemplateCounts && rule.giveCouponTemplateCounts.length > 0) {
|
||||||
|
tips.push(`送 ${rule.giveCouponTemplateCounts.length} 张优惠券`);
|
||||||
|
}
|
||||||
|
result[1].values.push(`${conditionTypeStr} ${tips.join('、')}`);
|
||||||
|
}
|
||||||
|
// 包邮
|
||||||
|
if (rule.freeDelivery) {
|
||||||
|
result[2].values.push(`${conditionTypeStr} 包邮`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 移除 values 为空的元素
|
||||||
|
result.forEach((item) => {
|
||||||
|
if (item.values.length === 0) {
|
||||||
|
result.splice(result.indexOf(item), 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获得满减送活动的规则描述(item)
|
||||||
|
export function getRewardActivityRuleItemDescriptions(activity) {
|
||||||
|
if (!activity || !activity.rules || activity.rules.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const result = [];
|
||||||
|
activity.rules.forEach((rule) => {
|
||||||
|
const conditionTypeStr =
|
||||||
|
activity.conditionType === 10 ? `满${fen2yuanSimple(rule.limit)}元` : `满${rule.limit}件`;
|
||||||
|
// 满减
|
||||||
|
if (rule.limit) {
|
||||||
|
result.push(`${conditionTypeStr}减${fen2yuanSimple(rule.discountPrice)}元`);
|
||||||
|
}
|
||||||
|
// 赠品
|
||||||
|
if (rule.point) {
|
||||||
|
result.push(`${conditionTypeStr}送${rule.point}积分`);
|
||||||
|
}
|
||||||
|
if (rule.giveCouponTemplateCounts && rule.giveCouponTemplateCounts.length > 0) {
|
||||||
|
result.push(`${conditionTypeStr}送${rule.giveCouponTemplateCounts.length}张优惠券`);
|
||||||
|
}
|
||||||
|
// 包邮
|
||||||
|
if (rule.freeDelivery) {
|
||||||
|
result.push(`${conditionTypeStr}包邮`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
141
sheep/hooks/useModal.js
Normal file
141
sheep/hooks/useModal.js
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
import $store from '@/sheep/store';
|
||||||
|
import $helper from '@/sheep/helper';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import test from '@/sheep/helper/test.js';
|
||||||
|
import AuthUtil from '@/sheep/api/member/auth';
|
||||||
|
|
||||||
|
// 打开授权弹框
|
||||||
|
export function showAuthModal(type = 'accountLogin') {
|
||||||
|
const modal = $store('modal');
|
||||||
|
if (modal.auth !== '') {
|
||||||
|
// 注意:延迟修改,保证下面的 closeAuthModal 先执行掉
|
||||||
|
setTimeout(() => {
|
||||||
|
modal.$patch((state) => {
|
||||||
|
state.auth = type;
|
||||||
|
});
|
||||||
|
}, 500);
|
||||||
|
closeAuthModal();
|
||||||
|
} else {
|
||||||
|
modal.$patch((state) => {
|
||||||
|
state.auth = type;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭授权弹框
|
||||||
|
export function closeAuthModal() {
|
||||||
|
$store('modal').$patch((state) => {
|
||||||
|
state.auth = '';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打开分享弹框
|
||||||
|
export function showShareModal() {
|
||||||
|
$store('modal').$patch((state) => {
|
||||||
|
state.share = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭分享弹框
|
||||||
|
export function closeShareModal() {
|
||||||
|
$store('modal').$patch((state) => {
|
||||||
|
state.share = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打开快捷菜单
|
||||||
|
export function showMenuTools() {
|
||||||
|
$store('modal').$patch((state) => {
|
||||||
|
state.menu = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭快捷菜单
|
||||||
|
export function closeMenuTools() {
|
||||||
|
$store('modal').$patch((state) => {
|
||||||
|
state.menu = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送短信验证码 60秒
|
||||||
|
export function getSmsCode(event, mobile) {
|
||||||
|
const modalStore = $store('modal');
|
||||||
|
const lastSendTimer = modalStore.lastTimer[event];
|
||||||
|
if (typeof lastSendTimer === 'undefined') {
|
||||||
|
$helper.toast('短信发送事件错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const duration = dayjs().unix() - lastSendTimer;
|
||||||
|
const canSend = duration >= 60;
|
||||||
|
if (!canSend) {
|
||||||
|
$helper.toast('请稍后再试');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 只有 mobile 非空时才校验。因为部分场景(修改密码),不需要输入手机
|
||||||
|
if (mobile && !test.mobile(mobile)) {
|
||||||
|
$helper.toast('手机号码格式不正确');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送验证码 + 更新上次发送验证码时间
|
||||||
|
let scene = -1;
|
||||||
|
switch (event) {
|
||||||
|
case 'resetPassword':
|
||||||
|
scene = 4;
|
||||||
|
break;
|
||||||
|
case 'changePassword':
|
||||||
|
scene = 3;
|
||||||
|
break;
|
||||||
|
case 'changeMobile':
|
||||||
|
scene = 2;
|
||||||
|
break;
|
||||||
|
case 'smsLogin':
|
||||||
|
scene = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
AuthUtil.sendSmsCode(mobile, scene).then((res) => {
|
||||||
|
if (res.code === 0) {
|
||||||
|
modalStore.$patch((state) => {
|
||||||
|
state.lastTimer[event] = dayjs().unix();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取短信验证码倒计时 -- 60秒
|
||||||
|
export function getSmsTimer(event, mobile = '') {
|
||||||
|
const modalStore = $store('modal');
|
||||||
|
const lastSendTimer = modalStore.lastTimer[event];
|
||||||
|
|
||||||
|
if (typeof lastSendTimer === 'undefined') {
|
||||||
|
$helper.toast('短信发送事件错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const duration = ref(dayjs().unix() - lastSendTimer - 60);
|
||||||
|
const canSend = duration.value >= 0;
|
||||||
|
|
||||||
|
if (canSend) {
|
||||||
|
return '获取验证码';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!canSend) {
|
||||||
|
setTimeout(() => {
|
||||||
|
duration.value++;
|
||||||
|
}, 1000);
|
||||||
|
return -duration.value.toString() + ' 秒';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 记录广告弹框历史
|
||||||
|
export function saveAdvHistory(adv) {
|
||||||
|
const modal = $store('modal');
|
||||||
|
|
||||||
|
modal.$patch((state) => {
|
||||||
|
if (!state.advHistory.includes(adv.imgUrl)) {
|
||||||
|
state.advHistory.push(adv.imgUrl);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
150
sheep/hooks/useWebSocket.js
Normal file
150
sheep/hooks/useWebSocket.js
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
import { onBeforeUnmount, reactive, ref } from 'vue';
|
||||||
|
import { baseUrl, websocketPath } from '@/sheep/config';
|
||||||
|
import { copyValueToTarget } from '@/sheep/util';
|
||||||
|
import { getRefreshToken } from '@/sheep/request';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebSocket 创建 hook
|
||||||
|
* @param opt 连接配置
|
||||||
|
* @return {{options: *}}
|
||||||
|
*/
|
||||||
|
export function useWebSocket(opt) {
|
||||||
|
const options = reactive({
|
||||||
|
url: (baseUrl + websocketPath).replace('http', 'ws') + '?token=' + getRefreshToken(), // ws 地址
|
||||||
|
isReconnecting: false, // 正在重新连接
|
||||||
|
reconnectInterval: 3000, // 重连间隔,单位毫秒
|
||||||
|
heartBeatInterval: 5000, // 心跳间隔,单位毫秒
|
||||||
|
pingTimeoutDuration: 1000, // 超过这个时间,后端没有返回pong,则判定后端断线了。
|
||||||
|
heartBeatTimer: null, // 心跳计时器
|
||||||
|
destroy: false, // 是否销毁
|
||||||
|
pingTimeout: null, // 心跳检测定时器
|
||||||
|
reconnectTimeout: null, // 重连定时器ID的属性
|
||||||
|
onConnected: () => {}, // 连接成功时触发
|
||||||
|
onClosed: () => {}, // 连接关闭时触发
|
||||||
|
onMessage: (data) => {}, // 收到消息
|
||||||
|
});
|
||||||
|
const SocketTask = ref(null); // SocketTask 由 uni.connectSocket() 接口创建
|
||||||
|
|
||||||
|
const initEventListeners = () => {
|
||||||
|
// 监听 WebSocket 连接打开事件
|
||||||
|
SocketTask.value.onOpen(() => {
|
||||||
|
console.log('WebSocket 连接成功');
|
||||||
|
// 连接成功时触发
|
||||||
|
options.onConnected();
|
||||||
|
// 开启心跳检查
|
||||||
|
startHeartBeat();
|
||||||
|
});
|
||||||
|
// 监听 WebSocket 接受到服务器的消息事件
|
||||||
|
SocketTask.value.onMessage((res) => {
|
||||||
|
try {
|
||||||
|
if (res.data === 'pong') {
|
||||||
|
// 收到心跳重置心跳超时检查
|
||||||
|
resetPingTimeout();
|
||||||
|
} else {
|
||||||
|
options.onMessage(JSON.parse(res.data));
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 监听 WebSocket 连接关闭事件
|
||||||
|
SocketTask.value.onClose((event) => {
|
||||||
|
// 情况一:实例销毁
|
||||||
|
if (options.destroy) {
|
||||||
|
options.onClosed();
|
||||||
|
} else {
|
||||||
|
// 情况二:连接失败重连
|
||||||
|
// 停止心跳检查
|
||||||
|
stopHeartBeat();
|
||||||
|
// 重连
|
||||||
|
reconnect();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 发送消息
|
||||||
|
const sendMessage = (message) => {
|
||||||
|
if (SocketTask.value && !options.destroy) {
|
||||||
|
SocketTask.value.send({ data: message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// 开始心跳检查
|
||||||
|
const startHeartBeat = () => {
|
||||||
|
options.heartBeatTimer = setInterval(() => {
|
||||||
|
sendMessage('ping');
|
||||||
|
options.pingTimeout = setTimeout(() => {
|
||||||
|
// 如果在超时时间内没有收到 pong,则认为连接断开
|
||||||
|
reconnect();
|
||||||
|
}, options.pingTimeoutDuration);
|
||||||
|
}, options.heartBeatInterval);
|
||||||
|
};
|
||||||
|
// 停止心跳检查
|
||||||
|
const stopHeartBeat = () => {
|
||||||
|
clearInterval(options.heartBeatTimer);
|
||||||
|
resetPingTimeout();
|
||||||
|
};
|
||||||
|
|
||||||
|
// WebSocket 重连
|
||||||
|
const reconnect = () => {
|
||||||
|
if (options.destroy || !SocketTask.value) {
|
||||||
|
// 如果WebSocket已被销毁或尚未完全关闭,不进行重连
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重连中
|
||||||
|
options.isReconnecting = true;
|
||||||
|
|
||||||
|
// 清除现有的重连标志,以避免多次重连
|
||||||
|
if (options.reconnectTimeout) {
|
||||||
|
clearTimeout(options.reconnectTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置重连延迟
|
||||||
|
options.reconnectTimeout = setTimeout(() => {
|
||||||
|
// 检查组件是否仍在运行和WebSocket是否关闭
|
||||||
|
if (!options.destroy) {
|
||||||
|
// 重置重连标志
|
||||||
|
options.isReconnecting = false;
|
||||||
|
// 初始化新的WebSocket连接
|
||||||
|
initSocket();
|
||||||
|
}
|
||||||
|
}, options.reconnectInterval);
|
||||||
|
};
|
||||||
|
|
||||||
|
const resetPingTimeout = () => {
|
||||||
|
if (options.pingTimeout) {
|
||||||
|
clearTimeout(options.pingTimeout);
|
||||||
|
options.pingTimeout = null; // 清除超时ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const close = () => {
|
||||||
|
options.destroy = true;
|
||||||
|
stopHeartBeat();
|
||||||
|
if (options.reconnectTimeout) {
|
||||||
|
clearTimeout(options.reconnectTimeout);
|
||||||
|
}
|
||||||
|
if (SocketTask.value) {
|
||||||
|
SocketTask.value.close();
|
||||||
|
SocketTask.value = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const initSocket = () => {
|
||||||
|
options.destroy = false;
|
||||||
|
copyValueToTarget(options, opt);
|
||||||
|
SocketTask.value = uni.connectSocket({
|
||||||
|
url: options.url,
|
||||||
|
complete: () => {},
|
||||||
|
success: () => {},
|
||||||
|
});
|
||||||
|
initEventListeners();
|
||||||
|
};
|
||||||
|
|
||||||
|
initSocket();
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
close();
|
||||||
|
});
|
||||||
|
return { options };
|
||||||
|
}
|
||||||
52
sheep/index.js
Normal file
52
sheep/index.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import $url from '@/sheep/url';
|
||||||
|
import $router from '@/sheep/router';
|
||||||
|
import $platform from '@/sheep/platform';
|
||||||
|
import $helper from '@/sheep/helper';
|
||||||
|
import zIndex from '@/sheep/config/zIndex.js';
|
||||||
|
import $store from '@/sheep/store';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||||
|
import duration from 'dayjs/plugin/duration';
|
||||||
|
import 'dayjs/locale/zh-cn';
|
||||||
|
|
||||||
|
dayjs.locale('zh-cn');
|
||||||
|
dayjs.extend(relativeTime);
|
||||||
|
dayjs.extend(duration);
|
||||||
|
|
||||||
|
const sheep = {
|
||||||
|
$store,
|
||||||
|
$url,
|
||||||
|
$router,
|
||||||
|
$platform,
|
||||||
|
$helper,
|
||||||
|
$zIndex: zIndex,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 加载Shopro底层依赖
|
||||||
|
export async function ShoproInit() {
|
||||||
|
// 应用初始化
|
||||||
|
await $store('app').init();
|
||||||
|
|
||||||
|
// 平台初始化加载(各平台provider提供不同的加载流程)
|
||||||
|
$platform.load();
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
ShoproDebug();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开发模式
|
||||||
|
function ShoproDebug() {
|
||||||
|
// 开发环境引入vconsole调试
|
||||||
|
// #ifdef H5
|
||||||
|
// import("vconsole").then(vconsole => {
|
||||||
|
// new vconsole.default();
|
||||||
|
// });
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// TODO 芋艿:可以打印路由
|
||||||
|
// 同步前端页面到后端
|
||||||
|
// console.log(ROUTES)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default sheep;
|
||||||
32
sheep/libs/mplive-manifest-plugin.js
Normal file
32
sheep/libs/mplive-manifest-plugin.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const manifestPath = process.env.UNI_INPUT_DIR + '/manifest.json';
|
||||||
|
|
||||||
|
let Manifest = fs.readFileSync(manifestPath, {
|
||||||
|
encoding: 'utf-8'
|
||||||
|
});
|
||||||
|
|
||||||
|
function mpliveMainfestPlugin(isOpen) {
|
||||||
|
if (process.env.UNI_PLATFORM !== 'mp-weixin') return;
|
||||||
|
|
||||||
|
const manifestData = JSON.parse(Manifest)
|
||||||
|
|
||||||
|
if (isOpen === '0') {
|
||||||
|
delete manifestData['mp-weixin'].plugins['live-player-plugin'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isOpen === '1') {
|
||||||
|
manifestData['mp-weixin'].plugins['live-player-plugin'] = {
|
||||||
|
"version": "1.3.5",
|
||||||
|
"provider": "wx2b03c6e691cd7370"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Manifest = JSON.stringify(manifestData, null, 2)
|
||||||
|
|
||||||
|
fs.writeFileSync(manifestPath, Manifest, {
|
||||||
|
"flag": "w"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default mpliveMainfestPlugin
|
||||||
246
sheep/libs/permission.js
Normal file
246
sheep/libs/permission.js
Normal file
@@ -0,0 +1,246 @@
|
|||||||
|
/// null = 未请求,1 = 已允许,0 = 拒绝|受限, 2 = 系统未开启
|
||||||
|
|
||||||
|
var isIOS;
|
||||||
|
|
||||||
|
function album() {
|
||||||
|
var result = 0;
|
||||||
|
var PHPhotoLibrary = plus.ios.import('PHPhotoLibrary');
|
||||||
|
var authStatus = PHPhotoLibrary.authorizationStatus();
|
||||||
|
if (authStatus === 0) {
|
||||||
|
result = null;
|
||||||
|
} else if (authStatus == 3) {
|
||||||
|
result = 1;
|
||||||
|
} else {
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
plus.ios.deleteObject(PHPhotoLibrary);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function camera() {
|
||||||
|
var result = 0;
|
||||||
|
var AVCaptureDevice = plus.ios.import('AVCaptureDevice');
|
||||||
|
var authStatus = AVCaptureDevice.authorizationStatusForMediaType('vide');
|
||||||
|
if (authStatus === 0) {
|
||||||
|
result = null;
|
||||||
|
} else if (authStatus == 3) {
|
||||||
|
result = 1;
|
||||||
|
} else {
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
plus.ios.deleteObject(AVCaptureDevice);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function location() {
|
||||||
|
var result = 0;
|
||||||
|
var cllocationManger = plus.ios.import('CLLocationManager');
|
||||||
|
var enable = cllocationManger.locationServicesEnabled();
|
||||||
|
var status = cllocationManger.authorizationStatus();
|
||||||
|
if (!enable) {
|
||||||
|
result = 2;
|
||||||
|
} else if (status === 0) {
|
||||||
|
result = null;
|
||||||
|
} else if (status === 3 || status === 4) {
|
||||||
|
result = 1;
|
||||||
|
} else {
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
plus.ios.deleteObject(cllocationManger);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function push() {
|
||||||
|
var result = 0;
|
||||||
|
var UIApplication = plus.ios.import('UIApplication');
|
||||||
|
var app = UIApplication.sharedApplication();
|
||||||
|
var enabledTypes = 0;
|
||||||
|
if (app.currentUserNotificationSettings) {
|
||||||
|
var settings = app.currentUserNotificationSettings();
|
||||||
|
enabledTypes = settings.plusGetAttribute('types');
|
||||||
|
if (enabledTypes == 0) {
|
||||||
|
result = 0;
|
||||||
|
console.log('推送权限没有开启');
|
||||||
|
} else {
|
||||||
|
result = 1;
|
||||||
|
console.log('已经开启推送功能!');
|
||||||
|
}
|
||||||
|
plus.ios.deleteObject(settings);
|
||||||
|
} else {
|
||||||
|
enabledTypes = app.enabledRemoteNotificationTypes();
|
||||||
|
if (enabledTypes == 0) {
|
||||||
|
result = 3;
|
||||||
|
console.log('推送权限没有开启!');
|
||||||
|
} else {
|
||||||
|
result = 4;
|
||||||
|
console.log('已经开启推送功能!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
plus.ios.deleteObject(app);
|
||||||
|
plus.ios.deleteObject(UIApplication);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function contact() {
|
||||||
|
var result = 0;
|
||||||
|
var CNContactStore = plus.ios.import('CNContactStore');
|
||||||
|
var cnAuthStatus = CNContactStore.authorizationStatusForEntityType(0);
|
||||||
|
if (cnAuthStatus === 0) {
|
||||||
|
result = null;
|
||||||
|
} else if (cnAuthStatus == 3) {
|
||||||
|
result = 1;
|
||||||
|
} else {
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
plus.ios.deleteObject(CNContactStore);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function record() {
|
||||||
|
var result = null;
|
||||||
|
var avaudiosession = plus.ios.import('AVAudioSession');
|
||||||
|
var avaudio = avaudiosession.sharedInstance();
|
||||||
|
var status = avaudio.recordPermission();
|
||||||
|
console.log('permissionStatus:' + status);
|
||||||
|
if (status === 1970168948) {
|
||||||
|
result = null;
|
||||||
|
} else if (status === 1735552628) {
|
||||||
|
result = 1;
|
||||||
|
} else {
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
plus.ios.deleteObject(avaudiosession);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function calendar() {
|
||||||
|
var result = null;
|
||||||
|
var EKEventStore = plus.ios.import('EKEventStore');
|
||||||
|
var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(0);
|
||||||
|
if (ekAuthStatus == 3) {
|
||||||
|
result = 1;
|
||||||
|
console.log('日历权限已经开启');
|
||||||
|
} else {
|
||||||
|
console.log('日历权限没有开启');
|
||||||
|
}
|
||||||
|
plus.ios.deleteObject(EKEventStore);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function memo() {
|
||||||
|
var result = null;
|
||||||
|
var EKEventStore = plus.ios.import('EKEventStore');
|
||||||
|
var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(1);
|
||||||
|
if (ekAuthStatus == 3) {
|
||||||
|
result = 1;
|
||||||
|
console.log('备忘录权限已经开启');
|
||||||
|
} else {
|
||||||
|
console.log('备忘录权限没有开启');
|
||||||
|
}
|
||||||
|
plus.ios.deleteObject(EKEventStore);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestIOS(permissionID) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
switch (permissionID) {
|
||||||
|
case 'push':
|
||||||
|
resolve(push());
|
||||||
|
break;
|
||||||
|
case 'location':
|
||||||
|
resolve(location());
|
||||||
|
break;
|
||||||
|
case 'record':
|
||||||
|
resolve(record());
|
||||||
|
break;
|
||||||
|
case 'camera':
|
||||||
|
resolve(camera());
|
||||||
|
break;
|
||||||
|
case 'album':
|
||||||
|
resolve(album());
|
||||||
|
break;
|
||||||
|
case 'contact':
|
||||||
|
resolve(contact());
|
||||||
|
break;
|
||||||
|
case 'calendar':
|
||||||
|
resolve(calendar());
|
||||||
|
break;
|
||||||
|
case 'memo':
|
||||||
|
resolve(memo());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
resolve(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestAndroid(permissionID) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
plus.android.requestPermissions(
|
||||||
|
[permissionID],
|
||||||
|
function (resultObj) {
|
||||||
|
var result = 0;
|
||||||
|
for (var i = 0; i < resultObj.granted.length; i++) {
|
||||||
|
var grantedPermission = resultObj.granted[i];
|
||||||
|
console.log('已获取的权限:' + grantedPermission);
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < resultObj.deniedPresent.length; i++) {
|
||||||
|
var deniedPresentPermission = resultObj.deniedPresent[i];
|
||||||
|
console.log('拒绝本次申请的权限:' + deniedPresentPermission);
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < resultObj.deniedAlways.length; i++) {
|
||||||
|
var deniedAlwaysPermission = resultObj.deniedAlways[i];
|
||||||
|
console.log('永久拒绝申请的权限:' + deniedAlwaysPermission);
|
||||||
|
result = -1;
|
||||||
|
}
|
||||||
|
resolve(result);
|
||||||
|
},
|
||||||
|
function (error) {
|
||||||
|
console.log('result error: ' + error.message);
|
||||||
|
resolve({
|
||||||
|
code: error.code,
|
||||||
|
message: error.message,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function gotoAppPermissionSetting() {
|
||||||
|
if (permission.isIOS) {
|
||||||
|
var UIApplication = plus.ios.import('UIApplication');
|
||||||
|
var application2 = UIApplication.sharedApplication();
|
||||||
|
var NSURL2 = plus.ios.import('NSURL');
|
||||||
|
var setting2 = NSURL2.URLWithString('app-settings:');
|
||||||
|
application2.openURL(setting2);
|
||||||
|
plus.ios.deleteObject(setting2);
|
||||||
|
plus.ios.deleteObject(NSURL2);
|
||||||
|
plus.ios.deleteObject(application2);
|
||||||
|
} else {
|
||||||
|
var Intent = plus.android.importClass('android.content.Intent');
|
||||||
|
var Settings = plus.android.importClass('android.provider.Settings');
|
||||||
|
var Uri = plus.android.importClass('android.net.Uri');
|
||||||
|
var mainActivity = plus.android.runtimeMainActivity();
|
||||||
|
var intent = new Intent();
|
||||||
|
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||||
|
var uri = Uri.fromParts('package', mainActivity.getPackageName(), null);
|
||||||
|
intent.setData(uri);
|
||||||
|
mainActivity.startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const permission = {
|
||||||
|
get isIOS() {
|
||||||
|
return typeof isIOS === 'boolean'
|
||||||
|
? isIOS
|
||||||
|
: (isIOS = uni.getSystemInfoSync().platform === 'ios');
|
||||||
|
},
|
||||||
|
requestIOS: requestIOS,
|
||||||
|
requestAndroid: requestAndroid,
|
||||||
|
gotoAppSetting: gotoAppPermissionSetting,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default permission;
|
||||||
184
sheep/libs/sdk-h5-weixin.js
Normal file
184
sheep/libs/sdk-h5-weixin.js
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
/**
|
||||||
|
* 本模块封装微信浏览器下的一些方法。
|
||||||
|
* 更多微信网页开发sdk方法,详见:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html
|
||||||
|
* 有 the permission value is offline verifying 报错请参考 @see https://segmentfault.com/a/1190000042289419 解决
|
||||||
|
*/
|
||||||
|
|
||||||
|
import jweixin from 'weixin-js-sdk';
|
||||||
|
import $helper from '@/sheep/helper';
|
||||||
|
import AuthUtil from '@/sheep/api/member/auth';
|
||||||
|
|
||||||
|
let configSuccess = false;
|
||||||
|
|
||||||
|
export default {
|
||||||
|
// 判断是否在微信中
|
||||||
|
isWechat() {
|
||||||
|
const ua = window.navigator.userAgent.toLowerCase();
|
||||||
|
// noinspection EqualityComparisonWithCoercionJS
|
||||||
|
return ua.match(/micromessenger/i) == 'micromessenger';
|
||||||
|
},
|
||||||
|
|
||||||
|
isReady(api) {
|
||||||
|
jweixin.ready(api);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 初始化 JSSDK
|
||||||
|
async init(callback) {
|
||||||
|
if (!this.isWechat()) {
|
||||||
|
$helper.toast('请使用微信网页浏览器打开');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用后端接口,获得 JSSDK 初始化所需的签名
|
||||||
|
const url = location.href.split('#')[0];
|
||||||
|
const { code, data } = await AuthUtil.createWeixinMpJsapiSignature(url);
|
||||||
|
if (code === 0) {
|
||||||
|
jweixin.config({
|
||||||
|
debug: false,
|
||||||
|
appId: data.appId,
|
||||||
|
timestamp: data.timestamp,
|
||||||
|
nonceStr: data.nonceStr,
|
||||||
|
signature: data.signature,
|
||||||
|
jsApiList: ['chooseWXPay', 'openLocation', 'getLocation','updateTimelineShareData','scanQRCode'], // TODO 芋艿:后续可以设置更多权限;
|
||||||
|
openTagList: data.openTagList
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 监听结果
|
||||||
|
configSuccess = true;
|
||||||
|
jweixin.error((err) => {
|
||||||
|
configSuccess = false;
|
||||||
|
console.error('微信 JSSDK 初始化失败', err);
|
||||||
|
// $helper.toast('微信JSSDK:' + err.errMsg);
|
||||||
|
});
|
||||||
|
jweixin.ready(() => {
|
||||||
|
if (configSuccess) {
|
||||||
|
console.log('微信 JSSDK 初始化成功');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 回调
|
||||||
|
if (callback) {
|
||||||
|
callback(data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
//在需要定位页面调用 TODO 芋艿:未测试
|
||||||
|
getLocation(callback) {
|
||||||
|
this.isReady(() => {
|
||||||
|
jweixin.getLocation({
|
||||||
|
type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
|
||||||
|
success: function (res) {
|
||||||
|
callback(res);
|
||||||
|
},
|
||||||
|
fail: function (res) {
|
||||||
|
console.log('%c微信H5sdk,getLocation失败:', 'color:green;background:yellow');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取微信收货地址
|
||||||
|
openAddress(callback) {
|
||||||
|
this.isReady(() => {
|
||||||
|
jweixin.openAddress({
|
||||||
|
success: function (res) {
|
||||||
|
callback.success && callback.success(res);
|
||||||
|
},
|
||||||
|
fail: function (err) {
|
||||||
|
callback.error && callback.error(err);
|
||||||
|
console.log('%c微信H5sdk,openAddress失败:', 'color:green;background:yellow');
|
||||||
|
},
|
||||||
|
complete: function (res) {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 微信扫码 TODO 芋艿:未测试
|
||||||
|
scanQRCode(callback) {
|
||||||
|
this.isReady(() => {
|
||||||
|
jweixin.scanQRCode({
|
||||||
|
needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
|
||||||
|
scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
|
||||||
|
success: function (res) {
|
||||||
|
callback(res);
|
||||||
|
},
|
||||||
|
fail: function (res) {
|
||||||
|
console.log('%c微信H5sdk,scanQRCode失败:', 'color:green;background:yellow');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 更新微信分享信息 TODO 芋艿:未测试
|
||||||
|
updateShareInfo(data, callback = null) {
|
||||||
|
this.isReady(() => {
|
||||||
|
const shareData = {
|
||||||
|
title: data.title,
|
||||||
|
desc: data.desc,
|
||||||
|
link: data.link,
|
||||||
|
imgUrl: data.image,
|
||||||
|
success: function (res) {
|
||||||
|
if (callback) {
|
||||||
|
callback(res);
|
||||||
|
}
|
||||||
|
// 分享后的一些操作,比如分享统计等等
|
||||||
|
},
|
||||||
|
cancel: function (res) {},
|
||||||
|
};
|
||||||
|
|
||||||
|
// 新版 分享聊天api
|
||||||
|
jweixin.updateAppMessageShareData(shareData);
|
||||||
|
// 新版 分享到朋友圈api
|
||||||
|
jweixin.updateTimelineShareData(shareData);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 打开坐标位置 TODO 芋艿:未测试
|
||||||
|
openLocation(data, callback) {
|
||||||
|
this.isReady(() => {
|
||||||
|
jweixin.openLocation({
|
||||||
|
...data,
|
||||||
|
success: function (res) {
|
||||||
|
console.log(res);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 选择图片 TODO 芋艿:未测试
|
||||||
|
chooseImage(callback) {
|
||||||
|
this.isReady(() => {
|
||||||
|
jweixin.chooseImage({
|
||||||
|
count: 1,
|
||||||
|
sizeType: ['compressed'],
|
||||||
|
sourceType: ['album'],
|
||||||
|
success: function (rs) {
|
||||||
|
callback(rs);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 微信支付
|
||||||
|
wxpay(data, callback) {
|
||||||
|
this.isReady(() => {
|
||||||
|
jweixin.chooseWXPay({
|
||||||
|
timestamp: data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
|
||||||
|
nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位
|
||||||
|
package: data.packageValue, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
|
||||||
|
signType: data.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
|
||||||
|
paySign: data.paySign, // 支付签名
|
||||||
|
success: function (res) {
|
||||||
|
callback.success && callback.success(res);
|
||||||
|
},
|
||||||
|
fail: function (err) {
|
||||||
|
callback.fail && callback.fail(err);
|
||||||
|
},
|
||||||
|
cancel: function (err) {
|
||||||
|
callback.cancel && callback.cancel(err);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
175
sheep/platform/index.js
Normal file
175
sheep/platform/index.js
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
/**
|
||||||
|
* Shopro 第三方平台功能聚合
|
||||||
|
* @version 1.0.3
|
||||||
|
* @author lidongtony
|
||||||
|
* @param {String} name - 厂商+平台名称
|
||||||
|
* @param {String} provider - 厂商
|
||||||
|
* @param {String} platform - 平台名称
|
||||||
|
* @param {String} os - 系统型号
|
||||||
|
* @param {Object} device - 设备信息
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { isEmpty } from 'lodash-es';
|
||||||
|
// #ifdef H5
|
||||||
|
import { isWxBrowser } from '@/sheep/helper/utils';
|
||||||
|
// #endif
|
||||||
|
import wechat from './provider/wechat/index.js';
|
||||||
|
import apple from './provider/apple';
|
||||||
|
import share from './share';
|
||||||
|
import Pay from './pay';
|
||||||
|
|
||||||
|
const device = uni.getSystemInfoSync();
|
||||||
|
|
||||||
|
const os = device.platform;
|
||||||
|
|
||||||
|
let name = '';
|
||||||
|
let provider = '';
|
||||||
|
let platform = '';
|
||||||
|
let isWechatInstalled = true;
|
||||||
|
|
||||||
|
// #ifdef H5
|
||||||
|
if (isWxBrowser()) {
|
||||||
|
name = 'WechatOfficialAccount';
|
||||||
|
provider = 'wechat';
|
||||||
|
platform = 'officialAccount';
|
||||||
|
} else {
|
||||||
|
name = 'H5';
|
||||||
|
platform = 'h5';
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
name = 'App';
|
||||||
|
platform = 'openPlatform';
|
||||||
|
// 检查微信客户端是否安装,否则AppleStore会因此拒绝上架
|
||||||
|
if (os === 'ios') {
|
||||||
|
isWechatInstalled = plus.ios.import('WXApi').isWXAppInstalled();
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
name = 'WechatMiniProgram';
|
||||||
|
platform = 'miniProgram';
|
||||||
|
provider = 'wechat';
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
if (isEmpty(name)) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '暂不支持该平台',
|
||||||
|
icon: 'none',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载当前平台前置行为
|
||||||
|
const load = () => {
|
||||||
|
if (provider === 'wechat') {
|
||||||
|
wechat.load();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 使用厂商独占sdk name = 'wechat' | 'alipay' | 'apple'
|
||||||
|
const useProvider = (_provider = '') => {
|
||||||
|
if (_provider === '') _provider = provider;
|
||||||
|
if (_provider === 'wechat') return wechat;
|
||||||
|
if (_provider === 'apple') return apple;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 支付服务转发
|
||||||
|
const pay = (payment, orderType, orderSN) => {
|
||||||
|
return new Pay(payment, orderType, orderSN);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查更新 (只检查小程序和App)
|
||||||
|
* @param {Boolean} silence - 静默检查
|
||||||
|
*/
|
||||||
|
const checkUpdate = (silence = false) => {
|
||||||
|
let canUpdate;
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
useProvider().checkUpdate(silence);
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
// TODO: 热更新
|
||||||
|
// #endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查网络
|
||||||
|
* @param {Boolean} silence - 静默检查
|
||||||
|
*/
|
||||||
|
async function checkNetwork() {
|
||||||
|
const networkStatus = await uni.getNetworkType();
|
||||||
|
if (networkStatus.networkType == 'none') {
|
||||||
|
return Promise.resolve(false);
|
||||||
|
}
|
||||||
|
return Promise.resolve(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取小程序胶囊信息
|
||||||
|
const getCapsule = () => {
|
||||||
|
// #ifdef MP
|
||||||
|
let capsule = uni.getMenuButtonBoundingClientRect();
|
||||||
|
if (!capsule) {
|
||||||
|
capsule = {
|
||||||
|
bottom: 56,
|
||||||
|
height: 32,
|
||||||
|
left: 278,
|
||||||
|
right: 365,
|
||||||
|
top: 24,
|
||||||
|
width: 87,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return capsule;
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifndef MP
|
||||||
|
return {
|
||||||
|
bottom: 56,
|
||||||
|
height: 32,
|
||||||
|
left: 278,
|
||||||
|
right: 365,
|
||||||
|
top: 24,
|
||||||
|
width: 87,
|
||||||
|
};
|
||||||
|
// #endif
|
||||||
|
};
|
||||||
|
|
||||||
|
const capsule = getCapsule();
|
||||||
|
|
||||||
|
// 标题栏高度
|
||||||
|
const getNavBar = () => {
|
||||||
|
return device.statusBarHeight + 44;
|
||||||
|
};
|
||||||
|
const navbar = getNavBar();
|
||||||
|
|
||||||
|
function getLandingPage() {
|
||||||
|
let page = '';
|
||||||
|
// #ifdef H5
|
||||||
|
page = location.href.split('?')[0];
|
||||||
|
// #endif
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置ios+公众号网页落地页 解决微信sdk签名问题
|
||||||
|
const landingPage = getLandingPage();
|
||||||
|
|
||||||
|
const _platform = {
|
||||||
|
name,
|
||||||
|
device,
|
||||||
|
os,
|
||||||
|
provider,
|
||||||
|
platform,
|
||||||
|
useProvider,
|
||||||
|
checkUpdate,
|
||||||
|
checkNetwork,
|
||||||
|
pay,
|
||||||
|
share,
|
||||||
|
load,
|
||||||
|
capsule,
|
||||||
|
navbar,
|
||||||
|
landingPage,
|
||||||
|
isWechatInstalled,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default _platform;
|
||||||
396
sheep/platform/pay.js
Normal file
396
sheep/platform/pay.js
Normal file
@@ -0,0 +1,396 @@
|
|||||||
|
import sheep from '@/sheep';
|
||||||
|
// #ifdef H5
|
||||||
|
import $wxsdk from '@/sheep/libs/sdk-h5-weixin';
|
||||||
|
// #endif
|
||||||
|
import { getRootUrl } from '@/sheep/helper';
|
||||||
|
import PayOrderApi from '@/sheep/api/pay/order';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付
|
||||||
|
*
|
||||||
|
* @param {String} payment = ['wechat','alipay','wallet','mock'] - 支付方式
|
||||||
|
* @param {String} orderType = ['goods','recharge','groupon'] - 订单类型
|
||||||
|
* @param {String} id - 订单号
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default class SheepPay {
|
||||||
|
constructor(payment, orderType, id) {
|
||||||
|
this.payment = payment;
|
||||||
|
this.id = id;
|
||||||
|
this.orderType = orderType;
|
||||||
|
this.payAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
payAction() {
|
||||||
|
const payAction = {
|
||||||
|
WechatOfficialAccount: {
|
||||||
|
wechat: () => {
|
||||||
|
this.wechatOfficialAccountPay();
|
||||||
|
},
|
||||||
|
alipay: () => {
|
||||||
|
this.redirectPay(); // 现在公众号可以直接跳转支付宝页面
|
||||||
|
},
|
||||||
|
wallet: () => {
|
||||||
|
this.walletPay();
|
||||||
|
},
|
||||||
|
mock: () => {
|
||||||
|
this.mockPay();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
WechatMiniProgram: {
|
||||||
|
wechat: () => {
|
||||||
|
this.wechatMiniProgramPay();
|
||||||
|
},
|
||||||
|
alipay: () => {
|
||||||
|
this.copyPayLink();
|
||||||
|
},
|
||||||
|
wallet: () => {
|
||||||
|
this.walletPay();
|
||||||
|
},
|
||||||
|
mock: () => {
|
||||||
|
this.mockPay();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
App: {
|
||||||
|
wechat: () => {
|
||||||
|
this.wechatAppPay();
|
||||||
|
},
|
||||||
|
alipay: () => {
|
||||||
|
this.alipay();
|
||||||
|
},
|
||||||
|
wallet: () => {
|
||||||
|
this.walletPay();
|
||||||
|
},
|
||||||
|
mock: () => {
|
||||||
|
this.mockPay();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
H5: {
|
||||||
|
wechat: () => {
|
||||||
|
this.wechatWapPay();
|
||||||
|
},
|
||||||
|
alipay: () => {
|
||||||
|
this.redirectPay();
|
||||||
|
},
|
||||||
|
wallet: () => {
|
||||||
|
this.walletPay();
|
||||||
|
},
|
||||||
|
mock: () => {
|
||||||
|
this.mockPay();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return payAction[sheep.$platform.name][this.payment]();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 预支付
|
||||||
|
prepay(channel) {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
// const openid = await sheep.$platform.useProvider('wechat').getOpenid();
|
||||||
|
let data = {
|
||||||
|
id: this.id,
|
||||||
|
channelCode: channel,
|
||||||
|
channelExtras: {
|
||||||
|
openid: uni.getStorageSync('openid')
|
||||||
|
},
|
||||||
|
};
|
||||||
|
// 特殊逻辑:微信公众号、小程序支付时,必须传入 openid
|
||||||
|
if (['wx_pub', 'wx_lite'].includes(channel)) {
|
||||||
|
const openid = await sheep.$platform.useProvider('wechat').getOpenid();
|
||||||
|
// 如果获取不到 openid,微信无法发起支付,此时需要引导
|
||||||
|
if (!openid) {
|
||||||
|
this.bindWeixin();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// data.channelExtras.openid = openid;
|
||||||
|
data.channelExtras.openid = uni.getStorageSync('openid');
|
||||||
|
}
|
||||||
|
// 发起预支付 API 调用
|
||||||
|
PayOrderApi.submitOrder(data).then((res) => {
|
||||||
|
// 成功时
|
||||||
|
res.code === 0 && resolve(res);
|
||||||
|
// 失败时
|
||||||
|
if (res.code !== 0 && res.msg.indexOf('无效的openid') >= 0) {
|
||||||
|
// 特殊逻辑:微信公众号、小程序支付时,必须传入 openid 不正确的情况
|
||||||
|
if (
|
||||||
|
res.msg.indexOf('无效的openid') >= 0 || // 获取的 openid 不正确时,或者随便输入了个 openid
|
||||||
|
res.msg.indexOf('下单账号与支付账号不一致') >= 0
|
||||||
|
) {
|
||||||
|
// https://developers.weixin.qq.com/community/develop/doc/00008c53c347804beec82aed051c00
|
||||||
|
this.bindWeixin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// #ifdef H5
|
||||||
|
// 微信公众号 JSSDK 支付
|
||||||
|
async wechatOfficialAccountPay() {
|
||||||
|
let { code, data } = await this.prepay('wx_pub');
|
||||||
|
if (code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const payConfig = JSON.parse(data.displayContent);
|
||||||
|
$wxsdk.wxpay(payConfig, {
|
||||||
|
success: () => {
|
||||||
|
this.payResult('success');
|
||||||
|
},
|
||||||
|
cancel: () => {
|
||||||
|
sheep.$helper.toast('支付已手动取消');
|
||||||
|
},
|
||||||
|
fail: (error) => {
|
||||||
|
if (error.errMsg.indexOf('chooseWXPay:没有此SDK或暂不支持此SDK模拟') >= 0) {
|
||||||
|
sheep.$helper.toast(
|
||||||
|
'发起微信支付失败,原因:可能是微信开发者工具不支持,建议使用微信打开网页后支付',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.payResult('fail');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 浏览器微信 H5 支付 TODO 芋艿:待接入(注意:H5 支付是给普通浏览器,不是微信公众号的支付,绝大多数人用不到,可以忽略)
|
||||||
|
async wechatWapPay() {
|
||||||
|
const { error, data } = await this.prepay();
|
||||||
|
if (error === 0) {
|
||||||
|
const redirect_url = `${getRootUrl()}pages/pay/result?id=${this.id}&payment=${
|
||||||
|
this.payment
|
||||||
|
}&orderType=${this.orderType}`;
|
||||||
|
location.href = `${data.pay_data.h5_url}&redirect_url=${encodeURIComponent(redirect_url)}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 支付链接(支付宝 wap 支付)
|
||||||
|
async redirectPay() {
|
||||||
|
let { code, data } = await this.prepay('alipay_wap');
|
||||||
|
if (code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
location.href = data.displayContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// 微信小程序支付
|
||||||
|
async wechatMiniProgramPay() {
|
||||||
|
// let that = this;
|
||||||
|
let { code, data } = await this.prepay('tonglian_wxlite');
|
||||||
|
if (code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 调用微信小程序支付
|
||||||
|
const displayContent = JSON.parse(data.displayContent);
|
||||||
|
// console.log("支付参数:", displayContent);
|
||||||
|
const payConfig = displayContent?.body?.wxAppModel;
|
||||||
|
console.log("支付参数:", payConfig);
|
||||||
|
uni.requestPayment({
|
||||||
|
// provider: 'wxpay',
|
||||||
|
// timeStamp: payConfig.timeStamp,
|
||||||
|
// timeStamp: payConfig.timestamp,
|
||||||
|
// nonceStr: payConfig.nonceStr,
|
||||||
|
// package: payConfig.packageValue,
|
||||||
|
// package: payConfig.prePayId,
|
||||||
|
// signType: payConfig.signType,
|
||||||
|
// paySign: payConfig.sign,
|
||||||
|
// paySign: payConfig.paySign,
|
||||||
|
success: (res) => {
|
||||||
|
this.payResult('success');
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.log("err23333",err)
|
||||||
|
if (err.errMsg === 'requestPayment:fail cancel') {
|
||||||
|
sheep.$helper.toast('支付已手动取消');
|
||||||
|
} else {
|
||||||
|
this.payResult('fail');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//测试通联支付代码
|
||||||
|
// const payConfig = JSON.parse(data.displayContent);
|
||||||
|
// const version = wx.getAppBaseInfo().SDKVersion;
|
||||||
|
// const accountInfo = wx.getAccountInfoSync();
|
||||||
|
// console.log('小程序版本号', accountInfo.miniProgram.version);
|
||||||
|
// const params = payConfig?.body?.cashierModel?.extraData;
|
||||||
|
|
||||||
|
// if (params) {
|
||||||
|
// uni.navigateToMiniProgram({
|
||||||
|
// appId: 'wxef277996acc166c3',
|
||||||
|
// extraData: params
|
||||||
|
// });
|
||||||
|
// }else {
|
||||||
|
// sheep.$helper.toast('获取支付参数失败');
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 余额支付
|
||||||
|
async walletPay() {
|
||||||
|
const { code } = await this.prepay('wallet');
|
||||||
|
code === 0 && this.payResult('success');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 模拟支付
|
||||||
|
async mockPay() {
|
||||||
|
const { code } = await this.prepay('mock');
|
||||||
|
code === 0 && this.payResult('success');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 支付宝复制链接支付(通过支付宝 wap 支付实现)
|
||||||
|
async copyPayLink() {
|
||||||
|
let { code, data } = await this.prepay('alipay_wap');
|
||||||
|
if (code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 引入 showModal 点击确认:复制链接;
|
||||||
|
uni.showModal({
|
||||||
|
title: '支付宝支付',
|
||||||
|
content: '复制链接到外部浏览器',
|
||||||
|
confirmText: '复制链接',
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
sheep.$helper.copyText(data.displayContent);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 支付宝支付(App) TODO 芋艿:待接入【暂时没打包 app,所以没接入,一般人用不到】
|
||||||
|
async alipay() {
|
||||||
|
let that = this;
|
||||||
|
const { error, data } = await this.prepay();
|
||||||
|
if (error === 0) {
|
||||||
|
uni.requestPayment({
|
||||||
|
provider: 'alipay',
|
||||||
|
orderInfo: data.pay_data, //支付宝订单数据
|
||||||
|
success: (res) => {
|
||||||
|
that.payResult('success');
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
if (err.errMsg === 'requestPayment:fail [paymentAlipay:62001]user cancel') {
|
||||||
|
sheep.$helper.toast('支付已手动取消');
|
||||||
|
} else {
|
||||||
|
that.payResult('fail');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 微信支付(App) TODO 芋艿:待接入:待接入【暂时没打包 app,所以没接入,一般人用不到】
|
||||||
|
async wechatAppPay() {
|
||||||
|
let that = this;
|
||||||
|
let { error, data } = await this.prepay();
|
||||||
|
if (error === 0) {
|
||||||
|
uni.requestPayment({
|
||||||
|
provider: 'wxpay',
|
||||||
|
orderInfo: data.pay_data, //微信订单数据(官方说是string。实测为object)
|
||||||
|
success: (res) => {
|
||||||
|
that.payResult('success');
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
err.errMsg !== 'requestPayment:fail cancel' && that.payResult('fail');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 支付结果跳转,success:成功,fail:失败
|
||||||
|
payResult(resultType) {
|
||||||
|
goPayResult(this.id, this.orderType, resultType);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 引导绑定微信
|
||||||
|
bindWeixin() {
|
||||||
|
uni.showModal({
|
||||||
|
title: '微信支付',
|
||||||
|
content: '请先绑定微信再使用微信支付',
|
||||||
|
success: function (res) {
|
||||||
|
if (res.confirm) {
|
||||||
|
sheep.$platform.useProvider('wechat').bind();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPayMethods(channels) {
|
||||||
|
const payMethods = [
|
||||||
|
// {
|
||||||
|
// icon: '/static/img/shop/pay/wechat.png',
|
||||||
|
// title: '微信支付',
|
||||||
|
// value: 'wechat',
|
||||||
|
// disabled: true,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// icon: '/static/img/shop/pay/alipay.png',
|
||||||
|
// title: '支付宝支付',
|
||||||
|
// value: 'alipay',
|
||||||
|
// disabled: true,
|
||||||
|
// },
|
||||||
|
{
|
||||||
|
icon: '/static/img/shop/pay/wallet.png',
|
||||||
|
title: '额度支付',
|
||||||
|
value: 'wallet',
|
||||||
|
disabled: true,
|
||||||
|
},
|
||||||
|
// {
|
||||||
|
// icon: '/static/img/shop/pay/apple.png',
|
||||||
|
// title: 'Apple Pay',
|
||||||
|
// value: 'apple',
|
||||||
|
// disabled: true,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// icon: '/static/img/shop/pay/wallet.png',
|
||||||
|
// title: '模拟支付',
|
||||||
|
// value: 'mock',
|
||||||
|
// disabled: true,
|
||||||
|
// },
|
||||||
|
];
|
||||||
|
const platform = sheep.$platform.name;
|
||||||
|
|
||||||
|
// 1. 处理【微信支付】
|
||||||
|
// const wechatMethod = payMethods[0];
|
||||||
|
// if (
|
||||||
|
// (platform === 'WechatOfficialAccount' && channels.includes('wx_pub')) ||
|
||||||
|
// (platform === 'WechatMiniProgram' && channels.includes('tonglian_wxlite')) ||
|
||||||
|
// (platform === 'App' && channels.includes('wx_app'))
|
||||||
|
// ) {
|
||||||
|
// wechatMethod.disabled = false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 2. 处理【支付宝支付】
|
||||||
|
// const alipayMethod = payMethods[1];
|
||||||
|
// if (
|
||||||
|
// (platform === 'H5' && channels.includes('alipay_wap')) ||
|
||||||
|
// (platform === 'WechatOfficialAccount' && channels.includes('alipay_wap')) ||
|
||||||
|
// (platform === 'WechatMiniProgram' && channels.includes('alipay_wap')) ||
|
||||||
|
// (platform === 'App' && channels.includes('alipay_app'))
|
||||||
|
// ) {
|
||||||
|
// alipayMethod.disabled = false;
|
||||||
|
// }
|
||||||
|
// 3. 处理【余额支付】
|
||||||
|
const walletMethod = payMethods[0];
|
||||||
|
// const walletMethod = payMethods[1];
|
||||||
|
if (channels.includes('wallet')) {
|
||||||
|
walletMethod.disabled = false;
|
||||||
|
}
|
||||||
|
// 4. 处理【苹果支付】TODO 芋艿:未来接入
|
||||||
|
// 5. 处理【模拟支付】
|
||||||
|
// const mockMethod = payMethods[4];
|
||||||
|
// if (channels.includes('mock')) {
|
||||||
|
// mockMethod.disabled = false;
|
||||||
|
// }
|
||||||
|
return payMethods;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 支付结果跳转,success:成功,fail:失败
|
||||||
|
export function goPayResult(id, orderType, resultType) {
|
||||||
|
sheep.$router.redirect('/pages/pay/result', {
|
||||||
|
id,
|
||||||
|
orderType,
|
||||||
|
payState: resultType,
|
||||||
|
});
|
||||||
|
}
|
||||||
36
sheep/platform/provider/apple/app.js
Normal file
36
sheep/platform/provider/apple/app.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// import third from '@/sheep/api/third';
|
||||||
|
// TODO 芋艿:等后面搞 App 再弄
|
||||||
|
|
||||||
|
const login = () => {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
const loginRes = await uni.login({
|
||||||
|
provider: 'apple',
|
||||||
|
success: () => {
|
||||||
|
uni.getUserInfo({
|
||||||
|
provider: 'apple',
|
||||||
|
success: async (res) => {
|
||||||
|
if (res.errMsg === 'getUserInfo:ok') {
|
||||||
|
const payload = res.userInfo;
|
||||||
|
const { error } = await third.apple.login({
|
||||||
|
payload,
|
||||||
|
shareInfo: uni.getStorageSync('shareLog') || {},
|
||||||
|
});
|
||||||
|
if (error === 0) {
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
resolve(false);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
login,
|
||||||
|
};
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user