add coupon page
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
"pages/logs/logs",
|
||||
"pages/history/history",
|
||||
"pages/terms/terms",
|
||||
"pages/privacy/privacy"
|
||||
"pages/privacy/privacy",
|
||||
"pages/coupon/coupon"
|
||||
],
|
||||
"window": {
|
||||
"navigationBarTextStyle": "black",
|
||||
@@ -17,15 +18,6 @@
|
||||
"backgroundColor": "#ffffff",
|
||||
"backgroundTextStyle": "light"
|
||||
},
|
||||
|
||||
"permission": {
|
||||
"scope.camera": {
|
||||
"desc": "需要使用相机拍照识别图片"
|
||||
},
|
||||
"scope.writePhotosAlbum": {
|
||||
"desc": "需要访问相册选择图片"
|
||||
}
|
||||
},
|
||||
"componentFramework": "glass-easel",
|
||||
"sitemapLocation": "sitemap.json",
|
||||
"lazyCodeLoading": "requiredComponents",
|
||||
|
||||
@@ -12,6 +12,7 @@ App<IAppOption>({
|
||||
|
||||
onLaunch() {
|
||||
console.log('小程序启动')
|
||||
wx.cloud.init()
|
||||
|
||||
// 初始化登录状态
|
||||
this.initLoginStatus()
|
||||
|
||||
8
miniprogram/pages/coupon/coupon.json
Normal file
8
miniprogram/pages/coupon/coupon.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"navigationBarTextStyle": "black",
|
||||
"navigationBarBackgroundColor": "#ffffff",
|
||||
"backgroundColor": "#f8f9fa",
|
||||
"backgroundTextStyle": "light",
|
||||
"usingComponents": {},
|
||||
"navigationBarTitleText": "积分"
|
||||
}
|
||||
7
miniprogram/pages/coupon/coupon.ts
Normal file
7
miniprogram/pages/coupon/coupon.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
// coupon.ts
|
||||
Page({
|
||||
data: {},
|
||||
onLoad() {
|
||||
console.log('Coupon page loaded');
|
||||
},
|
||||
});
|
||||
24
miniprogram/pages/coupon/coupon.wxml
Normal file
24
miniprogram/pages/coupon/coupon.wxml
Normal file
@@ -0,0 +1,24 @@
|
||||
<!--coupon.wxml-->
|
||||
<view class="coupon-container">
|
||||
<view class='coupon_box'>
|
||||
<view class='content'>
|
||||
<view class='title'>积分</view>
|
||||
<view class='how_much'>100</view>
|
||||
</view>
|
||||
<view class='btn'> ¥1.00 </view>
|
||||
</view>
|
||||
<view class='coupon_box'>
|
||||
<view class='content'>
|
||||
<view class='title'>积分</view>
|
||||
<view class='how_much'>100</view>
|
||||
</view>
|
||||
<view class='btn'> ¥1.00 </view>
|
||||
</view>
|
||||
<view class='coupon_box'>
|
||||
<view class='content'>
|
||||
<view class='title'>积分</view>
|
||||
<view class='how_much'>100</view>
|
||||
</view>
|
||||
<view class='btn'> ¥1.00 </view>
|
||||
</view>
|
||||
</view>
|
||||
72
miniprogram/pages/coupon/coupon.wxss
Normal file
72
miniprogram/pages/coupon/coupon.wxss
Normal file
@@ -0,0 +1,72 @@
|
||||
/* coupon.less */
|
||||
.coupon-container {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
align-items: flex-start;
|
||||
align-content: start;
|
||||
flex-wrap: wrap;
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.coupon_box{
|
||||
background: linear-gradient(to right, #FF4B2B, #FF416C);
|
||||
width: 40%;
|
||||
border-radius: 12rpx;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
font-family: 'Tahoma', sans-serif;
|
||||
position: relative;
|
||||
margin: 5% 5% 0 5%;
|
||||
}
|
||||
|
||||
.coupon_box::before{
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 200rpx;
|
||||
background: #f5f5f5;
|
||||
width: 20rpx;
|
||||
height: 30rpx;
|
||||
z-index: 1;
|
||||
left: -1rpx;
|
||||
border-radius: 0 30rpx 30rpx 0
|
||||
}
|
||||
|
||||
.coupon_box::after{
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 200rpx;
|
||||
background: #f5f5f5;
|
||||
width: 20rpx;
|
||||
height: 30rpx;
|
||||
z-index: 1;
|
||||
right: -1rpx;
|
||||
border-radius: 30rpx 0 0 30rpx
|
||||
}
|
||||
|
||||
.title{
|
||||
color: rgba(255,255,255,0.75);
|
||||
font-weight: 600;
|
||||
font-size: 32rpx
|
||||
}
|
||||
|
||||
.how_much{
|
||||
font-size: 80rpx;
|
||||
text-shadow: 0 0 20rpx rgba(0,0,0,0.3); text-align: center
|
||||
}
|
||||
|
||||
.content{
|
||||
padding: 4rpx 0 32rpx 0;
|
||||
border-bottom: 4rpx dashed rgba(0,0,0,0.15);
|
||||
position: relative;
|
||||
}
|
||||
.content::before{
|
||||
content: '100';
|
||||
position: absolute;
|
||||
color: rgba(255,255,255,0.15);
|
||||
top: 0%;
|
||||
left: 16rpx;
|
||||
font-size: 144rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
@@ -67,9 +67,11 @@
|
||||
maxcharacter="{{6}}"
|
||||
/>
|
||||
</t-dialog>
|
||||
<navigator url="/pages/coupon/coupon" class="cell-navigator">
|
||||
<t-cell title="积分" hover note="{{points.balance}}">
|
||||
<t-icon slot="left-icon" name="star" size="44rpx"></t-icon>
|
||||
</t-cell>
|
||||
</navigator>
|
||||
<t-cell title="兑换码" hover arrow bindtap="showCouponDialog">
|
||||
<t-icon slot="left-icon" name="coupon" size="44rpx"></t-icon>
|
||||
</t-cell>
|
||||
|
||||
@@ -346,3 +346,17 @@
|
||||
border-radius: 8rpx;
|
||||
margin: 20rpx;
|
||||
}
|
||||
|
||||
/* Navigation cell styles */
|
||||
.cell-navigator {
|
||||
display: block;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.cell-navigator .t-cell {
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.cell-navigator::after {
|
||||
border: none;
|
||||
}
|
||||
|
||||
@@ -4,13 +4,23 @@ import {
|
||||
ILoginResponse,
|
||||
IApiResponse,
|
||||
IRecognitionResponse,
|
||||
ExtendedWordDetail,
|
||||
IAuditHistoryResponse,
|
||||
IUserInfo,
|
||||
IDailySummaryResponse,
|
||||
YdWordDetail
|
||||
} from '../types/app';
|
||||
import { BASE_URL } from './config';
|
||||
import { cloudConfig } from './cloud.config';
|
||||
|
||||
// 添加对 ICloud 命名空间的引用
|
||||
declare namespace ICloud {
|
||||
interface CallContainerResult {
|
||||
data: any;
|
||||
header: Record<string, string>;
|
||||
statusCode: number;
|
||||
errMsg: string;
|
||||
}
|
||||
}
|
||||
|
||||
// 音频缓存映射
|
||||
const audioCache: Map<string, string> = new Map()
|
||||
@@ -235,6 +245,10 @@ class ApiManager {
|
||||
): Promise<IApiResponse<T>> {
|
||||
const maxRetries = 1 // 最多重试1次(首次请求 + 1次重试)
|
||||
|
||||
if (BASE_URL.includes('https://prod')){
|
||||
return this.wx_request<T>(url, method, data, showLoading)
|
||||
}
|
||||
else {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (showLoading && retryCount === 0) {
|
||||
// wx.showLoading({ title: '加载中...' })
|
||||
@@ -357,6 +371,65 @@ class ApiManager {
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 微信云托管请求方法
|
||||
private async wx_request<T>(
|
||||
path: string,
|
||||
method: 'GET' | 'POST' | 'PUT' | 'DELETE' = 'GET',
|
||||
data?: any,
|
||||
showLoading: boolean = true
|
||||
): Promise<ICloud.CallContainerResult> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (showLoading) {
|
||||
wx.showLoading({ title: '加载中...' });
|
||||
}
|
||||
|
||||
console.log('发起微信云托管请求:', {
|
||||
path,
|
||||
method,
|
||||
hasData: !!data
|
||||
});
|
||||
|
||||
wx.cloud.callContainer({
|
||||
config: {
|
||||
env: cloudConfig.env // 使用配置文件中的环境ID
|
||||
},
|
||||
path: path.startsWith('/') ? path : `/${path}`, // 确保路径以 / 开头
|
||||
method,
|
||||
header: {
|
||||
'X-WX-SERVICE': cloudConfig.service // 使用配置文件中的服务名称
|
||||
},
|
||||
data: data || {}, // 确保数据对象不为 undefined
|
||||
success: (res: ICloud.CallContainerResult) => {
|
||||
if (showLoading) {
|
||||
wx.hideLoading();
|
||||
}
|
||||
|
||||
console.log('微信云托管请求响应:', {
|
||||
statusCode: res.statusCode,
|
||||
hasData: !!res.data,
|
||||
success: true
|
||||
});
|
||||
|
||||
// 直接返回响应数据,由调用方处理业务逻辑
|
||||
resolve(res.data);
|
||||
},
|
||||
fail: (error: any) => {
|
||||
if (showLoading) {
|
||||
wx.hideLoading();
|
||||
}
|
||||
|
||||
console.error('微信云托管请求失败:', error);
|
||||
wx.showToast({
|
||||
title: '网络连接失败',
|
||||
icon: 'none'
|
||||
});
|
||||
reject(new Error('网络连接失败: ' + JSON.stringify(error)));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 处理 token 过期
|
||||
private handleTokenExpired() {
|
||||
@@ -1658,3 +1731,13 @@ class ApiManager {
|
||||
const apiManager = new ApiManager()
|
||||
export default apiManager
|
||||
export { ApiManager }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
45
miniprogram/utils/cloud.config.ts
Normal file
45
miniprogram/utils/cloud.config.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
// 微信云托管配置文件
|
||||
// 区分不同环境的配置
|
||||
|
||||
// 环境配置接口
|
||||
export interface CloudConfig {
|
||||
env: string;
|
||||
service: string;
|
||||
}
|
||||
|
||||
// 根据当前环境获取配置
|
||||
// 在微信小程序中,可以通过 wx.getAccountInfoSync() 获取环境信息
|
||||
const accountInfo = wx.getAccountInfoSync();
|
||||
const envVersion = accountInfo.miniProgram.envVersion || 'release'; // develop, trial, release
|
||||
|
||||
// 环境配置映射
|
||||
const envConfigMap: Record<string, CloudConfig> = {
|
||||
// 开发环境
|
||||
develop: {
|
||||
env: 'prod-1g647ekk563f2652', // 开发环境云托管环境ID
|
||||
service: 'prod' // 开发环境服务名称
|
||||
},
|
||||
// 体验版环境
|
||||
trial: {
|
||||
env: 'prod-1g647ekk563f2652', // 体验版云托管环境ID
|
||||
service: 'prod' // 体验版服务名称
|
||||
},
|
||||
// 正式版环境
|
||||
release: {
|
||||
env: 'prod-1g647ekk563f2652', // 正式版云托管环境ID
|
||||
service: 'prod' // 正式版服务名称
|
||||
}
|
||||
};
|
||||
|
||||
// 导出当前环境的配置
|
||||
export const cloudConfig: CloudConfig = envConfigMap[envVersion] || envConfigMap['release'];
|
||||
|
||||
// 如果需要自定义配置,可以覆盖默认配置
|
||||
export function setCloudConfig(config: Partial<CloudConfig>): void {
|
||||
if (config.env !== undefined) {
|
||||
cloudConfig.env = config.env;
|
||||
}
|
||||
if (config.service !== undefined) {
|
||||
cloudConfig.service = config.service;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
// API 基础域名
|
||||
export const BASE_URL = 'https://app.xhzone.cn'
|
||||
// export const BASE_URL = 'https://prod-201510-4-1385696640.sh.run.tcloudbase.com'
|
||||
|
||||
// 文件服务基础路径
|
||||
export const FILE_BASE_URL = `${BASE_URL}/api/v1/file`
|
||||
12
package-lock.json
generated
12
package-lock.json
generated
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "miniprogram-ts-less-quickstart",
|
||||
"version": "1.0.0",
|
||||
"version": "25.9.10",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "miniprogram-ts-less-quickstart",
|
||||
"version": "1.0.0",
|
||||
"version": "25.9.10",
|
||||
"dependencies": {
|
||||
"tdesign-miniprogram": "^1.10.1"
|
||||
"tdesign-miniprogram": "^1.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"miniprogram-api-typings": "^2.8.3-1"
|
||||
@@ -22,9 +22,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/tdesign-miniprogram": {
|
||||
"version": "1.10.1",
|
||||
"resolved": "https://registry.npmjs.org/tdesign-miniprogram/-/tdesign-miniprogram-1.10.1.tgz",
|
||||
"integrity": "sha512-rKM3JYfJGB+R9G/yp6kGVN0Kc0hKqKoQnpoWm7OVrXNsYM0dlJXwTf+WsLkQtgUyfM20taqNaxXD852Bx7IseQ==",
|
||||
"version": "1.11.0",
|
||||
"resolved": "https://registry.npmjs.org/tdesign-miniprogram/-/tdesign-miniprogram-1.11.0.tgz",
|
||||
"integrity": "sha512-1Siv2HVrSVlFiQBQXEjBrCvvsC3NQUsGgiej2RDXOxXHAPH2nynLhJhK+wu+KptzXi5GV+XYr+PHV2Je8vgW3w==",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
"miniprogram-api-typings": "^2.8.3-1"
|
||||
},
|
||||
"dependencies": {
|
||||
"tdesign-miniprogram": "^1.10.1"
|
||||
"tdesign-miniprogram": "^1.11.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,5 +51,5 @@
|
||||
"ignore": [],
|
||||
"include": []
|
||||
},
|
||||
"appid": "wxe739c0e6fb02eda8"
|
||||
"appid": "wxd6917f77eb2723fb"
|
||||
}
|
||||
@@ -18,10 +18,17 @@
|
||||
"checkInvalidKey": true,
|
||||
"ignoreDevUnusedFiles": true
|
||||
},
|
||||
"libVersion": "3.9.3",
|
||||
"libVersion": "2.33.0",
|
||||
"condition": {
|
||||
"miniprogram": {
|
||||
"list": [
|
||||
{
|
||||
"name": "pages/coupon/coupon",
|
||||
"pathName": "pages/coupon/coupon",
|
||||
"query": "",
|
||||
"scene": null,
|
||||
"launchMode": "default"
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"pathName": "pages/result/result",
|
||||
|
||||
29
typings/types/wx/lib.wx.cloud.d.ts
vendored
29
typings/types/wx/lib.wx.cloud.d.ts
vendored
@@ -121,6 +121,12 @@ interface WxCloud {
|
||||
|
||||
CloudID: ICloud.ICloudIDConstructor
|
||||
CDN: ICloud.ICDNConstructor
|
||||
|
||||
// Add callContainer method for WeChat Cloud Hosting
|
||||
callContainer(param: ICloud.CallContainerParam): void
|
||||
callContainer(
|
||||
param: RQ<ICloud.CallContainerParam>
|
||||
): Promise<ICloud.CallContainerResult>
|
||||
}
|
||||
|
||||
declare namespace ICloud {
|
||||
@@ -228,6 +234,29 @@ declare namespace ICloud {
|
||||
(options: string | ArrayBuffer | ICDNFilePathSpec): CDN
|
||||
}
|
||||
// === end ===
|
||||
|
||||
// === API: callContainer ===
|
||||
interface CallContainerResult extends IAPISuccessParam {
|
||||
data: any
|
||||
header: Record<string, string>
|
||||
statusCode: number
|
||||
errMsg: string
|
||||
}
|
||||
|
||||
interface CallContainerParam extends ICloudAPIParam<CallContainerResult> {
|
||||
config?: {
|
||||
env?: string
|
||||
}
|
||||
path: string
|
||||
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'CONNECT'
|
||||
header?: Record<string, string>
|
||||
data?: any
|
||||
dataType?: string
|
||||
responseType?: string
|
||||
timeout?: number
|
||||
}
|
||||
// === end ===
|
||||
|
||||
}
|
||||
|
||||
// === Database ===
|
||||
|
||||
Reference in New Issue
Block a user