commit 39a9d4b9c4c8d0a27ed5f5bd6f3994e916bb4894 Author: fzw Date: Wed Dec 17 14:21:57 2025 +0800 Initial commit diff --git a/app.js b/app.js new file mode 100644 index 0000000..7aabc9c --- /dev/null +++ b/app.js @@ -0,0 +1,21 @@ +// app.js +App({ + onLaunch: function() { + // 展示本地存储能力 + const logs = wx.getStorageSync('logs') || [] + logs.unshift(Date.now()) + wx.setStorageSync('logs', logs) + + // 登录 + wx.login({ + success: res => { + // 发送 res.code 到后台换取 openId, sessionKey, unionId + console.log('登录code:', res.code) + } + }) + }, + globalData: { + userInfo: null, + openid: null + } +}) \ No newline at end of file diff --git a/app.json b/app.json new file mode 100644 index 0000000..6c1341c --- /dev/null +++ b/app.json @@ -0,0 +1,13 @@ +{ + "pages": [ + "pages/index/index" + ], + "window": { + "backgroundTextStyle": "light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "OCR小程序", + "navigationBarTextStyle": "black" + }, + "style": "v2", + "sitemapLocation": "sitemap.json" +} \ No newline at end of file diff --git a/app.wxss b/app.wxss new file mode 100644 index 0000000..e938281 --- /dev/null +++ b/app.wxss @@ -0,0 +1,33 @@ +/* app.wxss */ +page { + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; + background-color: #f5f5f5; + color: #333; +} + +.container { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + min-height: 100vh; + padding: 20rpx; +} + +/* 通用按钮样式 */ +.btn { + display: flex; + align-items: center; + justify-content: center; + border-radius: 8rpx; + font-size: 32rpx; + font-weight: 500; + cursor: pointer; + transition: all 0.3s ease; + box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1); +} + +.btn:active { + transform: scale(0.98); + box-shadow: 0 1rpx 5rpx rgba(0, 0, 0, 0.1); +} \ No newline at end of file diff --git a/pages/index/index.js b/pages/index/index.js new file mode 100644 index 0000000..215c87c --- /dev/null +++ b/pages/index/index.js @@ -0,0 +1,146 @@ +// index.js +const app = getApp() + +Page({ + data: { + imagePath: '', + speedMode: false + }, + + onLoad: function() { + // 页面加载时执行 + }, + + // 加速模式开关切换事件 + toggleSpeedMode: function(e) { + this.setData({ + speedMode: e.detail.value + }) + }, + + // 扫码按钮点击事件 + scanCode: function() { + wx.chooseImage({ + count: 1, + sizeType: ['original', 'compressed'], + sourceType: ['album', 'camera'], + success: (res) => { + // tempFilePath可以作为img标签的src属性显示图片 + const tempFilePath = res.tempFilePaths[0] + this.setData({ + imagePath: tempFilePath + }) + + // 上传图片到后台 + this.uploadImage(tempFilePath) + }, + fail: (err) => { + console.error('选择图片失败:', err) + wx.showToast({ + title: '选择图片失败', + icon: 'none' + }) + } + }) + }, + + // 上传图片到后台 + uploadImage: function(filePath) { + wx.showLoading({ + title: '上传中...', + }) + + wx.uploadFile({ + url: 'https://227649ip14.51mypc.cn/api/upload', // 替换为你的后台接口地址 + filePath: filePath, + name: 'image', + formData: { + type: this.data.speedMode ? 1 : 0 + }, + header: { + 'content-type': 'multipart/form-data' + }, + success: (res) => { + wx.hideLoading() + wx.showToast({ + title: '上传成功', + icon: 'success' + }) + console.log('上传结果:', res) + }, + fail: (err) => { + wx.hideLoading() + wx.showToast({ + title: '上传失败', + icon: 'none' + }) + console.error('上传失败:', err) + } + }) + }, + + // 用户认证按钮点击事件 + userAuth: function() { + wx.login({ + success: (res) => { + if (res.code) { + // 使用code换取openid + this.getOpenid(res.code) + } else { + console.error('登录失败:', res.errMsg) + wx.showToast({ + title: '登录失败', + icon: 'none' + }) + } + }, + fail: (err) => { + console.error('调用登录接口失败:', err) + wx.showToast({ + title: '登录接口调用失败', + icon: 'none' + }) + } + }) + }, + + // 使用code换取openid + getOpenid: function(code) { + wx.showLoading({ + title: '获取openid中...', + }) + + wx.request({ + url: 'https://227649ip14.51mypc.cn/app/wechat-mini-app/getOpenid', // 替换为你的后台接口地址 + method: 'POST', + data: { + code: code + }, + success: (res) => { + wx.hideLoading() + if (res.data.openid) { + app.globalData.openid = res.data.openid + wx.showToast({ + title: '认证成功', + icon: 'success' + }) + console.log('获取到的openid:', res.data.openid) + } else { + wx.showToast({ + title: '认证失败', + icon: 'none' + }) + console.error('认证失败:', res.data) + } + }, + fail: (err) => { + wx.hideLoading() + wx.showToast({ + title: '网络请求失败', + icon: 'none' + }) + console.error('网络请求失败:', err) + } + }) + } +}) \ No newline at end of file diff --git a/pages/index/index.json b/pages/index/index.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/index/index.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/index/index.wxml b/pages/index/index.wxml new file mode 100644 index 0000000..2ee3795 --- /dev/null +++ b/pages/index/index.wxml @@ -0,0 +1,33 @@ + + + + OCR识别系统 + + + + + + + 加速模式 + + + + 扫码 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pages/index/index.wxss b/pages/index/index.wxss new file mode 100644 index 0000000..a5b03e2 --- /dev/null +++ b/pages/index/index.wxss @@ -0,0 +1,161 @@ +/* index.wxss */ +.container { + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + min-height: 90vh; + padding: 80rpx 40rpx 80rpx 40rpx; + background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); +} + +/* 页面标题 */ +.title { + font-size: 48rpx; + font-weight: 600; + color: white; + text-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1); +} + +/* 中间区域 */ +.middle-section { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + width: 100%; + flex: 0.8; + gap: 40rpx; +} + +/* 扫码按钮容器 */ +.scan-button-container { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + width: 100%; + flex: 0.5; + gap: 30rpx; +} + +/* 加速模式开关容器 */ +.speed-mode-switch { + display: flex; + align-items: center; + gap: 20rpx; + padding: 20rpx; + background: rgba(255, 255, 255, 0.9); + border-radius: 50rpx; + box-shadow: 0 5rpx 20rpx rgba(0, 0, 0, 0.1); +} + +/* 开关标签 */ +.switch-label { + font-size: 28rpx; + font-weight: 500; + color: #667eea; +} + +/* 开关样式 */ +.speed-mode-switch switch { + transform: scale(1.2); +} + +/* 图片预览容器 */ +.image-preview-container { + display: flex; + align-items: center; + justify-content: center; + width: 100%; + flex: 1.5; +} + +/* 圆形扫码按钮 */ +.scan-button { + width: 240rpx; + height: 240rpx; + border-radius: 50%; + background: white; + display: flex; + align-items: center; + justify-content: center; + border: none; + box-shadow: 0 10rpx 40rpx rgba(0, 0, 0, 0.2); + transition: all 0.3s ease; + padding: 0; + margin: 0; + box-sizing: border-box; + cursor: pointer; + user-select: none; +} + +.scan-button:hover { + transform: translateY(-5rpx); + box-shadow: 0 15rpx 50rpx rgba(0, 0, 0, 0.25); +} + +.scan-button:active { + transform: translateY(0) scale(0.95); + box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.2); +} + +.scan-button-text { + font-size: 36rpx; + font-weight: 600; + color: #667eea; +} + +/* 认证按钮容器 */ +.auth-button-container { + width: 100%; + max-width: 700rpx; +} + +/* 长形用户认证按钮 */ +.auth-button { + width: 100%; + height: 100rpx; + border-radius: 50rpx; + background: rgba(255, 255, 255, 0.9); + border: 2rpx solid rgba(255, 255, 255, 0.8); + display: flex; + align-items: center; + justify-content: center; + box-shadow: 0 5rpx 20rpx rgba(0, 0, 0, 0.15); + transition: all 0.3s ease; +} + +.auth-button:hover { + background: white; + transform: translateY(-3rpx); + box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.2); +} + +.auth-button:active { + transform: translateY(0) scale(0.98); + box-shadow: 0 3rpx 15rpx rgba(0, 0, 0, 0.15); +} + +.auth-button-text { + font-size: 32rpx; + font-weight: 500; + color: #667eea; +} + +/* 图片预览 */ +.image-preview { + width: 100%; + max-width: 600rpx; + background: rgba(255, 255, 255, 0.95); + border-radius: 20rpx; + padding: 30rpx; + box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.15); +} + +.image-preview image { + width: 100%; + height: 300rpx; + border-radius: 10rpx; + object-fit: contain; +} \ No newline at end of file diff --git a/project.config.json b/project.config.json new file mode 100644 index 0000000..b74381c --- /dev/null +++ b/project.config.json @@ -0,0 +1,29 @@ +{ + "setting": { + "es6": true, + "postcss": true, + "minified": true, + "uglifyFileName": false, + "enhance": true, + "packNpmRelationList": [], + "babelSetting": { + "ignore": [], + "disablePlugins": [], + "outputPath": "" + }, + "useCompilerPlugins": false, + "minifyWXML": true + }, + "compileType": "miniprogram", + "simulatorPluginLibVersion": {}, + "packOptions": { + "ignore": [], + "include": [] + }, + "appid": "wxeede99f5e2d8bafc", + "editorSetting": { + "tabIndent": "auto", + "tabSize": 2 + }, + "condition": {} +} \ No newline at end of file diff --git a/project.private.config.json b/project.private.config.json new file mode 100644 index 0000000..cb89ae2 --- /dev/null +++ b/project.private.config.json @@ -0,0 +1,15 @@ +{ + "libVersion": "3.12.1", + "projectname": "ocr", + "setting": { + "urlCheck": true, + "coverView": true, + "lazyloadPlaceholderEnable": false, + "skylineRenderEnable": false, + "preloadBackgroundData": false, + "autoAudits": false, + "showShadowRootInWxmlPanel": true, + "compileHotReLoad": true + }, + "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html" +} \ No newline at end of file diff --git a/sitemap.json b/sitemap.json new file mode 100644 index 0000000..27b2b26 --- /dev/null +++ b/sitemap.json @@ -0,0 +1,7 @@ +{ + "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", + "rules": [{ + "action": "allow", + "page": "*" + }] +} \ No newline at end of file