Initial commit
This commit is contained in:
21
app.js
Normal file
21
app.js
Normal file
@@ -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
|
||||||
|
}
|
||||||
|
})
|
||||||
13
app.json
Normal file
13
app.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"pages": [
|
||||||
|
"pages/index/index"
|
||||||
|
],
|
||||||
|
"window": {
|
||||||
|
"backgroundTextStyle": "light",
|
||||||
|
"navigationBarBackgroundColor": "#fff",
|
||||||
|
"navigationBarTitleText": "OCR小程序",
|
||||||
|
"navigationBarTextStyle": "black"
|
||||||
|
},
|
||||||
|
"style": "v2",
|
||||||
|
"sitemapLocation": "sitemap.json"
|
||||||
|
}
|
||||||
33
app.wxss
Normal file
33
app.wxss
Normal file
@@ -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);
|
||||||
|
}
|
||||||
146
pages/index/index.js
Normal file
146
pages/index/index.js
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
3
pages/index/index.json
Normal file
3
pages/index/index.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"usingComponents": {}
|
||||||
|
}
|
||||||
33
pages/index/index.wxml
Normal file
33
pages/index/index.wxml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<!-- index.wxml -->
|
||||||
|
<view class="container">
|
||||||
|
<!-- 页面标题 -->
|
||||||
|
<view class="title">OCR识别系统</view>
|
||||||
|
|
||||||
|
<!-- 中间区域 -->
|
||||||
|
<view class="middle-section">
|
||||||
|
<!-- 中间上半部分:扫码按钮 -->
|
||||||
|
<view class="scan-button-container">
|
||||||
|
<view class="speed-mode-switch">
|
||||||
|
<text class="switch-label">加速模式</text>
|
||||||
|
<switch checked="{{speedMode}}" bindchange="toggleSpeedMode" />
|
||||||
|
</view>
|
||||||
|
<view class="scan-button" bindtap="scanCode">
|
||||||
|
<text class="scan-button-text">扫码</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 中间下半部分:图片预览 -->
|
||||||
|
<view class="image-preview-container">
|
||||||
|
<view class="image-preview" wx:if="{{imagePath}}">
|
||||||
|
<image src="{{imagePath}}" mode="aspectFit"></image>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 长形用户认证按钮 -->
|
||||||
|
<view class="auth-button-container">
|
||||||
|
<button class="auth-button" bindtap="userAuth">
|
||||||
|
<text class="auth-button-text">用户认证</text>
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
161
pages/index/index.wxss
Normal file
161
pages/index/index.wxss
Normal file
@@ -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;
|
||||||
|
}
|
||||||
29
project.config.json
Normal file
29
project.config.json
Normal file
@@ -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": {}
|
||||||
|
}
|
||||||
15
project.private.config.json
Normal file
15
project.private.config.json
Normal file
@@ -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"
|
||||||
|
}
|
||||||
7
sitemap.json
Normal file
7
sitemap.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
|
||||||
|
"rules": [{
|
||||||
|
"action": "allow",
|
||||||
|
"page": "*"
|
||||||
|
}]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user