<template>
<view class="camera__page">
<!-- 相机组件 -->
<!-- #ifdef MP-WEIXIN -->
<camera :device-position="position" class="common__camrea" flash="on" @error="errorCamrea" />
<!-- #endif -->
<!-- #ifdef APP-PLUS -->
<live-pusher id="camera" class="common__camrea" mode="FHD" audio-quality="16KHz" :aspect="aspect" :muted="true"
:beauty="9" :whiteness="9" :enable-mic="false" @error="liveError" :device-position="position" />
<!-- #endif -->
<!-- 底部操作区域 -->
<view class="camera__foot">
<!-- 返回 -->
<view class="camrea__foot-back common" @click.stop="onClickBack">
<image class="icon" src="@/static/camera/back.png" />
<text class="text">返回</text>
</view>
<!-- 拍照 -->
<view class="camera__foot-snapshot" @click.stop="takePhoto">
<image class="take-icon" src="@/static/camera/snapshot.png" />
</view>
<!-- 翻转相机 -->
<view class="camera__foot-switch common" @click.stop="onClickSwitch(position)">
<image class="icon" src="@/static/camera/switchCamera.png" />
<text class="text">翻转</text>
</view>
</view>
</view>
</template>
<script setup lang="ts" name="CameraTake">
import { ref, getCurrentInstance, onMounted, computed } from 'vue'
import { onReady } from '@dcloudio/uni-app'
const instance = getCurrentInstance()?.proxy // 能够获取到全局上下文对象
const position = ref<string>('back') // front: 前置摄像头 back: 后置摄像头
const context = ref(null) // 直播推流实例
const aspect = ref<string>('9:16') // 直播推流实例
// #ifdef APP-PLUS
onReady(() => {
context.value = uni.createLivePusherContext("camera", instance)
context.value && context.value.startPreview({
success(data) {
console.log('开启摄像头预览', data)
}
})
})
// #endif
// 返回
function onClickBack() {
uni.$router.back()
}
// 拍照
function takePhoto() {
// #ifdef MP-WEIXIN
const ctx = uni.createCameraContext();
ctx.takePhoto({
quality: 'high',
success(res) {
console.log(res, 'res')
}
})
// #endif
// #ifdef APP-PLUS
uni.vibrateShort()
context.value && context.value.snapshot({
success(res) {
console.log(res, 'res')
}
})
// #endif
}
// 切换前后摄像头
function onClickSwitch(type = 'back') {
// #ifdef MP-WEIXIN
position.value = type === 'front' ? 'back' : 'front'
// #endif
// #ifdef APP-PLUS
context.value && context.value.switchCamera()
// #endif
}
// 微信摄像头错误
function errorCamrea(error : any) {
uni.showModal({
title: "温馨提示",
content: "摄像头调用失败(请确认是否已经授权使用摄像头)",
success: (res) => {
if (res["confirm"]) {
uni.openSetting({
success: ({ authSetting }) => {
if (authSetting['scope.camera']) {
uni.showToast({
title: '摄像头打开成功,请重新进入',
type: 'success',
duration: 4000,
success() {
onClickBack()
}
})
}
}
})
}
}
})
}
// 直播推流错误
function liveError(error : any) {
console.log('error', error)
}
</script>
<style scoped lang="scss">
.camera__page {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
background-color: #000000;
justify-content: flex-end;
.common__camrea {
width: 100%;
height: 0;
flex-grow: 1;
}
.camera__foot {
width: 750rpx;
height: 196rpx;
flex-shrink: 0;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
background-color: #FFF;
padding-bottom: 30rpx;
.common {
width: 108rpx;
height: 88rpx;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin: 0 75rpx;
.icon {
width: 48rpx;
height: 48rpx;
}
.text {
color: #070F23;
font-size: 24rpx;
}
}
&-snapshot {
width: 0;
height: 100%;
flex-grow: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
.take-icon {
width: 112rpx;
height: 112rpx;
}
}
}
}
</style>
- 发布:2023-05-23 15:00
- 更新:2023-05-24 17:34
- 阅读:348
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: windows 10
手机系统: Android
手机系统版本号: Android 12
手机厂商: 小米
手机机型: Redmi k40s
页面类型: nvue
vue版本: vue3
打包方式: 云端
项目创建方式: CLI
CLI版本号: 3.0.0-3071120230427001
示例代码:
操作步骤:
新建项目
新建项目
预期结果:
编译通过
编译通过
实际结果:
直接编译出错
直接编译出错
bug描述:
测试不管是Hbuilder项目还是cli项目只要是vue3版本的nuve编译到APP都报错
X [ERROR] No matching export in "dist/dev/.nvue/pagesB/camera/index.js" for import "default"
14:53:56.852 <stdin>:1:7:
14:53:56.854 1 │ import App from './pagesB/camera/index.js'
14:53:56.908 ╵ ~~~
14:53:56.911 [plugin:uni:app-nvue-esbuild] Build failed with 1 error:
14:53:56.912 <stdin>:1:7: ERROR: No matching export in "dist/dev/.nvue/pagesB/camera/index.js" for import "default"
Diligent_UI - 【插件开发】【专治疑难杂症】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=193663(微信搜索飘逸科技UI小程序直接体验)】【骗子请绕道】问题咨询请加QQ群:120594820,代表作灵感实用工具小程序
找import App的位置
Diligent_UI - 【插件开发】【专治疑难杂症】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=193663(微信搜索飘逸科技UI小程序直接体验)】【骗子请绕道】问题咨询请加QQ群:120594820,代表作灵感实用工具小程序
h5和小程序走的都是vue文件,当然没有问题
Diligent_UI - 【插件开发】【专治疑难杂症】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=193663(微信搜索飘逸科技UI小程序直接体验)】【骗子请绕道】问题咨询请加QQ群:120594820,代表作灵感实用工具小程序
我的群友之前遇到过一样的问题,改了个文件名就好了
2***@qq.com (作者)
就只在main.ts中使用过
2023-05-23 15:27