This commit is contained in:
2025-08-19 14:35:12 +08:00
parent 3f2fa0a8a3
commit 7a91647105
30 changed files with 2282 additions and 1085 deletions

View File

@@ -1,409 +1,467 @@
<template>
<view class="home-container">
<!-- 顶部Banner区域包含所有顶部内容 -->
<view class="home-header">
<swiper class="banner-swiper" :current="current" @change="onBannerChange" :autoplay="true" :interval="3000" :circular="true">
<swiper-item v-for="(item, idx) in banners" :key="idx">
<image :src="item.img" class="banner-bg-img" mode="aspectFill" />
</swiper-item>
</swiper>
<!-- 自定义指示器 -->
<view class="banner-indicator">
<view v-for="(item, idx) in banners" :key="idx" :class="['banner-dot', current === idx ? 'active' : '']"></view>
</view>
<view class="home-top">
<image class="icon3" src="/static/ic_tq.png" />
<text class="weather">21-36</text>
<view class="search-bar">
<image src="/static/ic_search.png" class="search-icon-img" />
<input class="search-input" placeholder="搜索" />
</view>
<view class="top-icons">
<image class="icon1" src="/static/ic_scan.png" />
<image class="icon2" src="/static/ic_msg.png" />
</view>
</view>
</view>
<!-- 白色圆角虚线面板 -->
<view class="main-panel">
<!-- 九宫格功能区 -->
<view class="grid-area">
<view class="grid-item" v-for="(item, idx) in gridList" :key="idx">
<image :src="item.icon" class="grid-icon" />
<text class="grid-text">{{ item.text }}</text>
</view>
</view>
<!-- 滚动资讯条 -->
<view class="news-bar">
<text class="news-label">头条</text>
<scroll-view scroll-x class="news-scroll">
<text v-for="(item, idx) in newsList" :key="idx" class="news-item">{{ item }}</text>
</scroll-view>
<text class="news-arrow"></text>
</view>
<!-- 热门活动区 -->
<view class="hot-section">
<view class="hot-title-row">
<text class="hot-title">热门活动</text>
<text class="hot-more">全部热门活动 ></text>
</view>
<view class="hot-list">
<view class="hot-card" v-for="(item, idx) in hotList" :key="idx">
<image :src="item.img" class="hot-img" mode="aspectFill" />
<view class="hot-info">
<text class="hot-tag">#热门活动</text>
<text class="hot-desc">{{ item.title }}</text>
<view class="hot-meta">
<text class="hot-date">{{ item.date }}</text>
<text class="hot-status">进行中</text>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
name: 'Home',
data() {
return {
banners: [{
img: 'https://picsum.photos/750/300?random=1'
},
{
img: 'https://picsum.photos/750/300?random=2'
}
],
current: 0,
gridList: [{
icon: 'https://picsum.photos/80/80?random=3',
text: '报事报修'
},
{
icon: 'https://picsum.photos/80/80?random=4',
text: '停车缴费'
},
{
icon: 'https://picsum.photos/80/80?random=5',
text: '生活服务'
},
{
icon: 'https://picsum.photos/80/80?random=6',
text: '服务中心'
},
{
icon: 'https://picsum.photos/80/80?random=7',
text: '会议预约'
},
{
icon: 'https://picsum.photos/80/80?random=8',
text: '工单管理'
},
{
icon: 'https://picsum.photos/80/80?random=9',
text: '访客管理'
},
{
icon: 'https://picsum.photos/80/80?random=10',
text: '敬请期待'
}
],
newsList: [
'数智南川|最新资讯1',
'数智南川|最新资讯2',
'数智南川|最新资讯3'
],
hotList: [{
img: 'https://picsum.photos/700/280?random=13',
title: '世界骑行日 低碳出行 让城市更美好',
date: '2025-07-03'
},
{
img: 'https://picsum.photos/700/280?random=14',
title: '仲夏之夜低碳出行·绿色生活让城市更美好',
date: '2025-07-03'
}
]
}
},
methods: {
onBannerChange(e) {
this.current = e.detail.current;
}
}
}
</script>
<style scoped>
.home-container {
display: flex;
flex-direction: column;
height: 100vh;
background: #f8f8f8;
padding-bottom: 40rpx;
}
.home-header {
position: relative;
height: 446rpx;
width: 100vw;
margin-bottom: -40rpx;
flex-shrink: 0;
}
.banner-swiper {
width: 100vw;
height: 446rpx;
position: absolute;
left: 0;
top: 0;
z-index: 0;
}
.banner-bg-img {
width: 100vw;
height: 446rpx;
object-fit: cover;
}
.banner-indicator {
position: absolute;
left: 0;
bottom: 64rpx;
width: 100vw;
display: flex;
justify-content: center;
z-index: 2;
}
.banner-dot {
width: 14rpx;
height: 14rpx;
border-radius: 50%;
background: rgba(255,255,255,0.6);
margin: 0 8rpx;
transition: background 0.2s;
}
.banner-dot.active {
background: #3B7BFF;
}
.home-top {
position: relative;
z-index: 3;
display: flex;
align-items: center;
color: #fff;
padding: 80rpx 20rpx 0 20rpx;
}
.weather {
font-size: 24rpx;
margin-left: 10rpx;
margin-right: 16rpx;
}
.search-bar {
flex: 1;
display: flex;
align-items: center;
background: rgba(255, 255, 255, 0.3);
border-radius: 30rpx;
padding: 0 20rpx;
height: 56rpx;
margin-right: 16rpx;
}
.search-input::placeholder {
color: #f0f0f0;
}
.search-icon-img {
width: 28rpx;
height: 28rpx;
margin-right: 8rpx;
}
.search-input {
border: none;
background: transparent;
font-size: 26rpx;
flex: 1;
color: #fff;
}
.top-icons {
display: flex;
align-items: center;
}
.icon1 {
width: 33rpx;
height: 33rpx;
margin-left: 19rpx;
}
.icon2 {
width: 38rpx;
height: 38rpx;
margin-left: 23rpx;
}
.icon3 {
width: 40rpx;
height: 40rpx;
}
.main-panel {
flex: 1;
overflow-y: auto;
background: #fff;
border-radius: 20rpx;
position: relative;
z-index: 10;
padding: 20rpx;
}
.grid-area {
display: flex;
flex-wrap: wrap;
padding: 20rpx 0 10rpx 0;
}
.grid-item {
width: 20%;
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 20rpx;
}
.grid-icon {
width: 80rpx;
height: 80rpx;
margin-bottom: 8rpx;
}
.grid-text {
font-size: 24rpx;
color: #1D1D1D;
}
.news-bar {
display: flex;
align-items: center;
padding: 10rpx 0;
border-top: 1rpx solid #f5f5f5;
margin-top: 10rpx;
}
.news-label {
color: #FF6A00;
font-size: 28rpx;
font-weight: bold;
margin-right: 16rpx;
border: 1rpx solid #FF6A00;
border-radius: 4rpx;
padding: 2rpx 6rpx;
}
.news-scroll {
flex: 1;
white-space: nowrap;
}
.news-item {
display: inline-block;
margin-right: 30rpx;
color: #666;
font-size: 24rpx;
}
.news-arrow {
color: #999;
font-size: 32rpx;
}
.hot-section {
margin-top: 20rpx;
}
.hot-title-row {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20rpx;
}
.hot-title {
font-size: 32rpx;
font-weight: bold;
color: #222;
position: relative;
padding-left: 16rpx;
}
.hot-title::before {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 6rpx;
height: 30rpx;
background: #3B7BFF;
border-radius: 3rpx;
}
.hot-more {
font-size: 24rpx;
color: #999;
}
.hot-list {
display: flex;
flex-direction: column;
gap: 20rpx;
}
.hot-card {
background: #fff;
border-radius: 20rpx;
overflow: hidden;
display: flex;
flex-direction: column;
border: 1rpx solid #f0f0f0;
}
.hot-img {
width: 100%;
height: 280rpx;
object-fit: cover;
}
.hot-info {
padding: 16rpx 20rpx 20rpx 20rpx;
}
.hot-tag {
color: #3B7BFF;
font-size: 22rpx;
margin-bottom: 6rpx;
display: block;
}
.hot-desc {
font-size: 28rpx;
color: #222;
margin-bottom: 10rpx;
display: block;
font-weight: 500;
}
.hot-meta {
display: flex;
justify-content: space-between;
align-items: center;
}
.hot-date {
color: #999;
font-size: 22rpx;
}
.hot-status {
color: #fff;
background: #3B7BFF;
font-size: 22rpx;
border-radius: 8rpx;
padding: 4rpx 12rpx;
}
<template>
<view class="home-container">
<!-- 顶部Banner区域包含所有顶部内容 -->
<view class="home-header">
<swiper class="banner-swiper" :current="current" @change="onBannerChange" :autoplay="true" :interval="3000"
:circular="true">
<swiper-item v-for="(item, idx) in banners" :key="idx">
<image :src="item.img" class="banner-bg-img" mode="aspectFill" />
</swiper-item>
</swiper>
<!-- 自定义指示器 -->
<view class="banner-indicator">
<view v-for="(item, idx) in banners" :key="idx"
:class="['banner-dot', current === idx ? 'active' : '']"></view>
</view>
<view class="home-top">
<image class="icon3" src="/static/ic_tq.png" />
<text class="weather">21-36</text>
<view class="search-bar">
<image src="/static/ic_search.png" class="search-icon-img" />
<input class="search-input" placeholder="搜索" />
</view>
<view class="top-icons">
<image class="icon1" src="/static/ic_scan.png" @click="goToScan" />
<image class="icon2" src="/static/ic_msg.png" />
</view>
</view>
</view>
<!-- 白色圆角虚线面板 -->
<view class="main-panel">
<!-- 九宫格功能区 -->
<view class="grid-area">
<view class="grid-item" v-for="(item, idx) in gridList" :key="idx" @click="handleItemClick(item.url)">
<image :src="item.icon" class="grid-icon" />
<text class="grid-text">{{ item.text }}</text>
</view>
</view>
<!-- 滚动资讯条 -->
<view class="news-bar">
<text class="news-label">头条</text>
<scroll-view scroll-x class="news-scroll">
<text v-for="(item, idx) in newsList" :key="idx" class="news-item">{{ item }}</text>
</scroll-view>
<text class="news-arrow"></text>
</view>
<!-- 热门活动区 -->
<view class="hot-section">
<view class="hot-title-row">
<text class="hot-title">热门活动</text>
<text class="hot-more">全部热门活动 ></text>
</view>
<view class="hot-list">
<view class="hot-card" v-for="(item, idx) in hotList" :key="idx">
<image :src="item.img" class="hot-img" mode="aspectFill" />
<view class="hot-info">
<text class="hot-tag">#热门活动</text>
<text class="hot-desc">{{ item.title }}</text>
<view class="hot-meta">
<text class="hot-date">{{ item.date }}</text>
<text class="hot-status">进行中</text>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
name: 'Home',
data() {
return {
banners: [{
img: '/static/aaa_banner1.png'
}
// ,
// {
// img: 'https://picsum.photos/750/300?random=2'
// }
],
current: 0,
gridList: [{
icon: '/static/aaa_bsbx.png',
text: '报事报修',
url:'/pages/sys/user/myRepair/myRepair'
},
{
icon: '/static/aaa_tcjf.png',
text: '停车缴费',
url:'/pages/sys/user/myPayment/myPayment'
},
{
icon: '/static/aaa_shfw.png',
text: '生活服务'
},
{
icon: '/static/aaa_fwzx.png',
text: '服务中心',
url:'/pages/sys/user/serviceCenter/serviceCenter'
},
{
icon: '/static/aaa_hyyy.png',
text: '会议预约',
url:'/pages/sys/workbench/meet/meet'
},
{
icon: '/static/aaa_gdgl.png',
text: '工单管理',
url:'/pages/sys/workbench/order/order'
},
{
icon: '/static/aaa_fkgl.png',
text: '访客管理',
url:'/pages/sys/user/myVisitor/myVisitor'
},
{
icon: '/static/aaa_jqqd.png',
text: '敬请期待'
}
],
newsList: [
'数智南川|最新资讯1',
'数智南川|最新资讯2',
'数智南川|最新资讯3'
],
hotList: [{
img: '/static/aaa_hd1.png',
title: '世界骑行日 低碳出行 让城市更美好',
date: '2025-07-03'
},
{
img: '/static/aaa_hd2.png',
title: '仲夏之夜低碳出行·绿色生活让城市更美好',
date: '2025-07-03'
}
]
}
},
methods: {
onBannerChange(e) {
this.current = e.detail.current;
},
// 扫码功能
goToScan() {
uni.scanCode({
success: (res) => {
console.log('扫码成功', res);
uni.showModal({
title: '扫码结果',
content: res.result,
showCancel: true,
confirmText: '确定',
cancelText: '取消',
success: (modalRes) => {
if (modalRes.confirm) {
console.log('用户点击确定');
// 可以在这里处理扫码结果
}
}
});
},
fail: (err) => {
}
});
},
handleItemClick(url) {
uni.navigateTo({
url: url
});
}
}
}
</script>
<style scoped>
.home-container {
display: flex;
flex-direction: column;
height: 100vh;
background: #f8f8f8;
padding-bottom: 40rpx;
}
.home-header {
position: relative;
height: 446rpx;
width: 100vw;
margin-bottom: -40rpx;
flex-shrink: 0;
}
.banner-swiper {
width: 100vw;
height: 446rpx;
position: absolute;
left: 0;
top: 0;
z-index: 0;
}
.banner-bg-img {
width: 100vw;
height: 446rpx;
object-fit: cover;
}
.banner-indicator {
position: absolute;
left: 0;
bottom: 64rpx;
width: 100vw;
display: flex;
justify-content: center;
z-index: 2;
}
.banner-dot {
width: 14rpx;
height: 14rpx;
border-radius: 50%;
background: rgba(255, 255, 255, 0.6);
margin: 0 8rpx;
transition: background 0.2s;
}
.banner-dot.active {
background: #3B7BFF;
}
.home-top {
position: relative;
z-index: 3;
display: flex;
align-items: center;
color: #fff;
padding: 80rpx 20rpx 0 20rpx;
}
.weather {
font-size: 24rpx;
margin-left: 10rpx;
margin-right: 16rpx;
}
.search-bar {
flex: 1;
display: flex;
align-items: center;
background: rgba(255, 255, 255, 0.3);
border-radius: 30rpx;
padding: 0 20rpx;
height: 56rpx;
margin-right: 16rpx;
}
.search-input::placeholder {
color: #FFFFFF;
opacity: 1;
}
.search-icon-img {
width: 28rpx;
height: 28rpx;
margin-right: 8rpx;
}
.search-input {
border: none;
background: transparent;
font-size: 26rpx;
flex: 1;
color: #fff;
}
.top-icons {
display: flex;
align-items: center;
}
.icon1 {
width: 33rpx;
height: 33rpx;
margin-left: 19rpx;
}
.icon2 {
width: 38rpx;
height: 38rpx;
margin-left: 23rpx;
}
.icon3 {
width: 40rpx;
height: 40rpx;
}
.main-panel {
flex: 1;
overflow-y: auto;
background: #fff;
border-radius: 20rpx;
position: relative;
z-index: 10;
padding: 20rpx;
}
.grid-area {
display: flex;
flex-wrap: wrap;
padding: 20rpx 0 10rpx 0;
margin-top: 10rpx;
}
.grid-item {
width: 20%;
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 30rpx;
}
.grid-icon {
width: 50rpx;
height: 50rpx;
margin-bottom: 8rpx;
}
.grid-text {
font-size: 24rpx;
color: #1D1D1D;
}
.news-bar {
display: flex;
align-items: center;
padding: 10rpx 0;
border-top: 1rpx solid #f5f5f5;
margin-top: 10rpx;
}
.news-label {
color: #FF6A00;
font-size: 28rpx;
font-weight: bold;
margin-right: 16rpx;
border: 1rpx solid #FF6A00;
border-radius: 4rpx;
padding: 2rpx 6rpx;
}
.news-scroll {
flex: 1;
white-space: nowrap;
}
.news-item {
display: inline-block;
margin-right: 30rpx;
color: #666;
font-size: 24rpx;
}
.news-arrow {
color: #999;
font-size: 32rpx;
}
.hot-section {
margin-top: 20rpx;
}
.hot-title-row {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20rpx;
}
.hot-title {
font-size: 32rpx;
font-weight: bold;
color: #222;
position: relative;
padding-left: 16rpx;
}
.hot-title::before {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 6rpx;
height: 30rpx;
background: #3B7BFF;
border-radius: 3rpx;
}
.hot-more {
font-size: 24rpx;
color: #999;
}
.hot-list {
display: flex;
flex-direction: column;
gap: 20rpx;
}
.hot-card {
background: #fff;
border-radius: 20rpx;
overflow: hidden;
display: flex;
flex-direction: column;
border: 1rpx solid #f0f0f0;
}
.hot-img {
width: 100%;
height: 280rpx;
object-fit: cover;
}
.hot-info {
padding: 16rpx 20rpx 20rpx 20rpx;
}
.hot-tag {
color: #3B7BFF;
font-size: 22rpx;
margin-bottom: 6rpx;
display: block;
}
.hot-desc {
font-size: 28rpx;
color: #222;
margin-bottom: 10rpx;
display: block;
font-weight: 500;
}
.hot-meta {
display: flex;
justify-content: space-between;
align-items: center;
}
.hot-date {
color: #999;
font-size: 22rpx;
}
.hot-status {
color: #fff;
background: #3B7BFF;
font-size: 22rpx;
border-radius: 8rpx;
padding: 4rpx 12rpx;
}
</style>

504
pages/sys/home/scan.vue Normal file
View File

@@ -0,0 +1,504 @@
<template>
<view class="scan-container">
<view class="scan-header">
<view class="back-btn" @click="goBack">
<u-icon name="arrow-left" color="#fff" size="20"></u-icon>
</view>
<text class="scan-title">扫码</text>
</view>
<!-- 扫码区域 -->
<view class="scan-content">
<view class="scan-area">
<!-- #ifdef APP-PLUS -->
<view class="scanner" id="scannerId"></view>
<!-- #endif -->
<!-- H5和小程序平台使用通用提示 -->
<!-- #ifndef APP-PLUS -->
<view class="scan-placeholder">
<text class="placeholder-text">点击下方按钮开始扫码</text>
</view>
<!-- #endif -->
<view class="scan-frame">
<view class="corner top-left"></view>
<view class="corner top-right"></view>
<view class="corner bottom-left"></view>
<view class="corner bottom-right"></view>
</view>
</view>
<text class="scan-tip">将二维码/条码放入框内即可自动扫描</text>
</view>
<view class="scan-footer">
<view class="album-btn" @click="selectFromAlbum">
<u-icon name="photo" color="#fff" size="24"></u-icon>
<text class="btn-text">相册</text>
</view>
<view class="scan-btn" @click="startScanCode">
<u-icon name="scan" color="#fff" size="24"></u-icon>
<text class="btn-text">扫码</text>
</view>
<view class="flashlight-btn" @click="toggleFlashlight">
<u-icon :name="flashlightOn ? 'light-fill' : 'light'" color="#fff" size="24"></u-icon>
<text class="btn-text">{{ flashlightOn ? '关闭' : '开启' }}手电筒</text>
</view>
</view>
</view>
</template>
<script>
export default {
name: 'Scan',
data() {
return {
flashlightOn: false,
barcodeObj: null
}
},
methods: {
goBack() {
// 关闭手电筒
if (this.flashlightOn) {
// #ifdef APP-PLUS
plus.device.flashlight(false)
// #endif
}
uni.navigateBack()
},
// 从相册选择二维码
selectFromAlbum() {
// #ifdef APP-PLUS
plus.gallery.pick((e) => {
this.scanImage(e.files[0])
}, (e) => {
console.log('取消选择图片')
}, {
filter: 'none',
multiple: false,
maximum: 1,
system: false
})
// #endif
// H5和小程序平台使用uni.chooseImage
// #ifndef APP-PLUS
uni.chooseImage({
count: 1,
success: (res) => {
// 在H5和小程序平台相册选择后无法直接识别二维码
uni.showToast({
title: '请选择扫码功能直接扫描二维码',
icon: 'none'
})
}
})
// #endif
},
// 扫描图片中的二维码 (仅App)
scanImage(path) {
// #ifdef APP-PLUS
plus.barcode.scan(path, (type, code) => {
this.handleScanResult(type, code)
}, (error) => {
uni.showToast({
title: '未识别到二维码',
icon: 'none'
})
})
// #endif
},
// 打开/关闭手电筒 (仅App)
toggleFlashlight() {
// #ifdef APP-PLUS
this.flashlightOn = !this.flashlightOn
plus.device.flashlight(this.flashlightOn)
// #endif
// #ifndef APP-PLUS
uni.showToast({
title: '该功能仅在App中可用',
icon: 'none'
})
// #endif
},
// 处理扫码结果
handleScanResult(type, code) {
uni.showModal({
title: '扫码结果',
content: code,
showCancel: true,
confirmText: '确定',
cancelText: '取消',
success: (res) => {
if (res.confirm) {
console.log('用户点击确定')
// 可以在这里处理扫码结果,比如跳转页面
// uni.redirectTo({
// url: '/pages/somepage?code=' + code
// })
} else if (res.cancel) {
// 用户取消,继续扫码
// #ifdef APP-PLUS
this.startScan()
// #endif
}
}
})
},
// 开始扫码 (仅App)
startScan() {
// #ifdef APP-PLUS
if (this.barcodeObj) {
this.barcodeObj.start()
}
// #endif
},
// 停止扫码 (仅App)
stopScan() {
// #ifdef APP-PLUS
if (this.barcodeObj) {
this.barcodeObj.cancel()
}
// #endif
},
// 使用uni.scanCode进行扫码 (H5和小程序平台)
startScanCode() {
// #ifndef APP-PLUS
uni.scanCode({
success: (res) => {
this.handleScanResult(res.scanType, res.result)
},
fail: (err) => {
console.log('扫码失败', err)
uni.showToast({
title: '扫码失败,请重试',
icon: 'none'
})
}
})
// #endif
// #ifdef APP-PLUS
// App平台仍然使用原生扫码
this.startScan()
// #endif
},
// 初始化扫码功能 (仅App)
initScanner() {
// #ifdef APP-PLUS
const scanner = plus.barcode.Barcode
this.barcodeObj = new scanner('scannerId',
[scanner.QR, scanner.EAN13, scanner.EAN8, scanner.CODE128],
{
top: '0px',
left: '0px',
width: '100%',
height: '100%',
position: 'static'
}
)
// 设置扫码成功回调
this.barcodeObj.onmarked = (type, result) => {
let code = result
switch(type) {
case scanner.QR:
type = 'QR'
break
case scanner.EAN13:
type = 'EAN13'
break
case scanner.EAN8:
type = 'EAN8'
break
case scanner.CODE128:
type = 'CODE128'
break
default:
type = '其他'
break
}
this.handleScanResult(type, code)
}
// 开始扫码
this.barcodeObj.start()
// #endif
},
// 检查并请求摄像头权限 (仅App)
checkPermission() {
// #ifdef APP-PLUS
return new Promise((resolve, reject) => {
// 判断是否已经授权
plus.android.requestPermissions(['android.permission.CAMERA'],
(resultObj) => {
let result = 0;
for (var i = 0; i < resultObj.granted.length; i++) {
if (resultObj.granted[i] === 'android.permission.CAMERA') {
result = 1
}
}
for (var i = 0; i < resultObj.denied.length; i++) {
if (resultObj.denied[i] === 'android.permission.CAMERA') {
result = 0
}
}
for (var i = 0; i < resultObj.alwaysDenied.length; i++) {
if (resultObj.alwaysDenied[i] === 'android.permission.CAMERA') {
result = -1
}
}
if (result == 1) {
resolve(true)
} else {
resolve(false)
}
},
(error) => {
resolve(false)
}
);
})
// #endif
// #ifndef APP-PLUS
return Promise.resolve(true)
// #endif
}
},
onLoad() {
// #ifdef APP-PLUS
// 页面加载时检查权限并初始化扫码功能
this.checkPermission().then((authorized) => {
if (authorized) {
this.$nextTick(() => {
// 使用定时器确保DOM渲染完成后再初始化扫码组件
setTimeout(() => {
this.initScanner()
}, 100)
})
} else {
uni.showModal({
title: '权限申请',
content: '需要摄像头权限才能使用扫码功能,是否前往设置开启权限?',
success: (res) => {
if (res.confirm) {
// 跳转到系统设置页面
if (plus.os.name === 'Android') {
var Intent = plus.android.importClass("android.content.Intent");
var Settings = plus.android.importClass("android.provider.Settings");
var main = plus.android.runtimeMainActivity();
var intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
var uri = plus.android.invoke("android.net.Uri", "fromParts", "package", main.getPackageName(), null);
intent.setData(uri);
main.startActivity(intent);
} else {
plus.runtime.openURL("app-settings://");
}
} else {
uni.navigateBack()
}
}
})
}
})
// #endif
},
onUnload() {
// 页面卸载时关闭扫码和手电筒
this.stopScan()
if (this.flashlightOn) {
// #ifdef APP-PLUS
plus.device.flashlight(false)
// #endif
}
},
onHide() {
// 页面隐藏时停止扫码
this.stopScan()
},
onShow() {
// 页面显示时重新开始扫码
// #ifdef APP-PLUS
this.$nextTick(() => {
setTimeout(() => {
this.startScan()
}, 100)
})
// #endif
}
}
</script>
<style scoped>
.scan-container {
width: 100%;
height: 100vh;
background: #000;
position: relative;
}
.scan-header {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 80rpx;
padding: 60rpx 30rpx 30rpx;
display: flex;
align-items: center;
z-index: 100;
}
.back-btn {
width: 60rpx;
height: 60rpx;
border-radius: 50%;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
}
.scan-title {
flex: 1;
text-align: center;
color: #fff;
font-size: 36rpx;
margin-right: 60rpx;
}
.scan-content {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding-top: 120rpx;
box-sizing: border-box;
}
.scan-area {
width: 480rpx;
height: 480rpx;
position: relative;
overflow: hidden;
}
/* #ifdef APP-PLUS */
.scanner {
width: 480rpx;
height: 480rpx;
position: absolute;
top: 0;
left: 0;
z-index: 10;
background: transparent;
}
/* #endif */
.scan-placeholder {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: #333;
}
.placeholder-text {
color: #fff;
font-size: 28rpx;
text-align: center;
}
.scan-frame {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 20;
}
.corner {
position: absolute;
width: 40rpx;
height: 40rpx;
border: 4rpx solid #00ff00;
}
.top-left {
top: 0;
left: 0;
border-right: none;
border-bottom: none;
}
.top-right {
top: 0;
right: 0;
border-left: none;
border-bottom: none;
}
.bottom-left {
bottom: 0;
left: 0;
border-right: none;
border-top: none;
}
.bottom-right {
bottom: 0;
right: 0;
border-left: none;
border-top: none;
}
.scan-tip {
color: #fff;
font-size: 28rpx;
margin-top: 60rpx;
}
.scan-footer {
position: absolute;
bottom: 100rpx;
left: 0;
width: 100%;
display: flex;
justify-content: space-around;
z-index: 100;
}
.album-btn, .flashlight-btn, .scan-btn {
display: flex;
flex-direction: column;
align-items: center;
color: #fff;
}
.btn-text {
margin-top: 10rpx;
font-size: 24rpx;
color: #fff;
}
</style>