uniapp 文件查找失败:‘pages/video/detail.vue?mpType=page‘

在尝试运行Vue项目到手机模拟器时,可能会遇到'pages/fenlei/home.vue?mpType=page'找不到的问题。这通常是因为误选了纯nvue项目选项。解决方案是检查项目配置,确保未勾选纯nvue选项,取消后重新运行项目,问题通常可以得到解决。

运行到手机模拟器–文件查找失败:‘pages/fenlei/home.vue?mpType=page’ at pages.json:1
出现这种问题原因有可能是勾选了 纯nvue项目了,去掉即可。

<template> <scroll-view scroll-y :refresher-enabled="true" :refresher-triggered="triggered" :refresher-threshold="70" :refresher-background="'#f5f5f5'" :refresher-default-style="'black'" @refresherrefresh="onRefresh" style="height: 100vh;" > <view style="display: flex;flex-direction: column;"> <view class="uni-padding-wrap" :style="{height:`${topHeight}px`,'padding-top':`${statusBarHeight}px`}" style="display: flex;flex-direction: row;align-items: center;width: 100%;"> <uni-icons style="margin-right: 10.12rpx;" type="undo-filled" color="#2979ff" size="30" @click='back'></uni-icons> <view style="display: flex;justify-content: space-between;"> <!-- <uni-segmented-control :current="current" :values="items" :style-type="styleType" :active-color="activeColor" @clickItem="onClickItem" /> --> <view class="seg" v-for="(item,index) in items" @click="onClickItem(index)" style="margin: 0 2px;"> <text v-if="current === index" style="font-size: 15px;color:#2979ff">{{item}}</text> <text v-else style="font-size: 15px;">{{item}}</text> </view> </view> </view> <view class="scroll-view" @scrolltolower="loadMore" :style="{'margin-top':`${listTop}px`}"> <view v-if="searchInfo.status === 8"> <uni-card v-for="(item, index) in tableData" :title="item.goods_sn" :sub-title="item.goods_name" :thumbnail="item.goods_thumb"> <template v-slot:title> <view class="title-box"> <view class="left"> <image style="width: 120rpx;height: 120rpx;" mode="aspectFit" :src="item.goods_thumb" @click="previewImage(item.goods_thumb)"></image> <view class="msg"> <view class="sn">{{item.goods_sn}}</view> <view class="name">{{item.goods_name}}</view> </view> </view> <view class="right"> <image mode="aspectFit" v-if="item.cover_thumb" style="width: 120rpx;height: 120rpx;" :src="item.cover_thumb" @click="previewImage(item.cover_thumb)"></image> <template v-if="item.is_upload === 2"> <uni-icons @tap="previewVideos(item.video_arr)" v-if="item.video_arr &amp;&amp; item.video_arr.length > 0" type="videocam" color="#2979ff" size="30"></uni-icons> </template> <template v-else> <span style="font-size: 12px;">上传中...</span> </template> </view> </view> </template> <view> <scroll-view style="height: 150rpx;" scroll-y="true"> <text class="uni-body">{{item.text}}</text> </scroll-view> </view> <view slot="actions" class="card-actions"> <span style="margin-right: 10rpx;">{{index+1}}</span> <view class="card-actions-item"> <uni-tag class="action-item" @tap="goToShoot(item,index)" :circle="true" text="去拍摄" type="primary" /> <!-- <uni-tag class="action-item" @tap="upCover(item,index)" :circle="true" text="上传封面" type="primary" /> --> <uni-tag class="action-item" @tap="upApprove(item,index)" :circle="true" text="提交" type="primary" /> </view> </view> </uni-card> </view> <view v-if="searchInfo.status === 10"> <uni-card v-for="(item, index) in tableData" :title="item.goods_sn" :sub-title="item.goods_name" :thumbnail="item.goods_thumb"> <template v-slot:title> <view class="title-box"> <view class="left"> <image style="width: 120rpx;height: 120rpx;" mode="aspectFit" :src="item.goods_thumb" @click="previewImage(item.goods_thumb)"></image> <view class="msg"> <view class="sn">{{item.goods_sn}}</view> <view class="name">{{item.goods_name}}</view> </view> </view> <view class="right"> <image mode="aspectFit" v-if="item.cover_thumb" style="width: 120rpx;height: 120rpx;margin-right: 9.06rpx;" :src="item.cover_thumb" @click="previewImage(item.cover_thumb)"></image> <uni-icons @tap="previewVideos(item.video_arr)" v-if="item.video_arr &amp;&amp; item.video_arr.length > 0" type="videocam" color="#2979ff" size="30"></uni-icons> </view> </view> </template> <view> <scroll-view style="height: 150rpx;" scroll-y="true"> <text class="uni-body">{{item.text}}</text> </scroll-view> </view> </uni-card> </view> <view v-if="searchInfo.status === 11"> <uni-card v-for="(item, index) in tableData" :title="item.goods_sn" :sub-title="item.goods_name" :thumbnail="item.goods_thumb"> <template v-slot:title> <view class="title-box"> <view class="left"> <image style="width: 120rpx;height: 120rpx;" mode="aspectFit" :src="item.goods_thumb" @click="previewImage(item.goods_thumb)"></image> <view class="msg"> <view class="sn">{{item.goods_sn}}</view> <view class="name">{{item.goods_name}}</view> </view> </view> <view class="right"> <image mode="aspectFit" v-if="item.cover_thumb" style="width: 120rpx;height: 120rpx;margin-right: 9.06rpx;" :src="item.cover_thumb" @click="previewImage(item.cover_thumb)"></image> <template v-if="item.is_upload === 2"> <uni-icons @tap="previewVideos(item.video_arr)" v-if="item.video_arr &amp;&amp; item.video_arr.length > 0" type="videocam" color="#2979ff" size="30"></uni-icons> </template> <template v-else> <span style="font-size: 12px;">上传中...</span> </template> </view> </view> </template> <view> <scroll-view style="height: 150rpx;" scroll-y="true"> <text class="uni-body">{{item.text}}</text> </scroll-view> </view> <view slot="actions" class="card-actions"> <span style="margin-right: 10rpx;">{{index+1}}</span> <view class="card-actions-item"> <uni-tag class="action-item" @tap="goToShoot(item,index)" :circle="true" text="去拍摄" type="primary" /> <!-- <uni-tag class="action-item" @tap="upCover(item,index)" :circle="true" text="上传封面" type="primary" /> --> <uni-tag class="action-item" @tap="upApprove(item,index)" :circle="true" text="提交" type="primary" /> </view> </view> </uni-card> </view> <view v-if="searchInfo.status === 12"> <uni-card v-for="(item, index) in tableData" :title="item.goods_sn" :sub-title="item.goods_name" :thumbnail="item.goods_thumb"> <template v-slot:title> <view class="title-box"> <view class="left"> <image style="width: 120rpx;height: 120rpx;" mode="aspectFit" :src="item.goods_thumb" @click="previewImage(item.goods_thumb)"></image> <view class="msg"> <view class="sn">{{item.goods_sn}}</view> <view class="name">{{item.goods_name}}</view> </view> </view> <view class="right"> <image mode="aspectFit" v-if="item.cover_thumb" style="width: 120rpx;height: 120rpx;margin-right: 9.06rpx;" :src="item.cover_thumb" @click="previewImage(item.cover_thumb)"></image> <uni-icons @tap="previewVideos(item.video_arr)" v-if="item.video_arr &amp;&amp; item.video_arr.length > 0" type="videocam" color="#2979ff" size="30"></uni-icons> </view> </view> </template> <view> <scroll-view style="height: 150rpx;" scroll-y="true"> <text class="uni-body">{{item.text}}</text> </scroll-view> </view> </uni-card> </view> <view class="no-more"> 没有数据了... </view> </view> </view> </scroll-view> </template> <script> import topHeader from "@/components/topHeader.vue" import { PreFix, TASKMAP } from "@/constant/QuickShot.js"; import { upApi, ph } from "@/api/QuickShot.js" const actionPage = "/pages/QuickShotAction/index" //待拍摄的数据 let tableData = [{ id: "1", goods_thumb: "https://ydlunacommon-cdn.nosdn.127.net/ea119bfe4d8bdc2a56c6b3d94bfe89e0.png", goods_name: "作品测1", goods_sn: "AD232132323", cover_thumb: "https://ydlunacommon-cdn.nosdn.127.net/ea119bfe4d8bdc2a56c6b3d94bfe89e0.png", //封面图 video_path: "", recording_date: "2015-12-13", is_upload: 2, text: "测试文案,测试文案,测试文案,测试文案,测试文案", }, ]; export default { data() { return { census: [], triggered: false, refreshing: false, // 控制下拉刷新显示状态 refreshText: '正在刷新...', // 刷新成功后的提示文本 searchInfo: { status: 8, page_size: 15, current_page: 1 }, tableData: [], // 每页数据量 page_size: 10, // 当前页 current_page: 1, // 数据总量 total: 0, loading: false, items: ["待拍摄(0)", "待审核(0)", "需重拍(0)", "已完成(0)"], styles: [{ value: "button", text: "按钮", checked: true, }, { value: "text", text: "文字", }, ], colors: ["#007aff", "#4cd964", "#dd524d"], current: 0, colorIndex: 0, activeColor: "#007aff", styleType: "button", statusBarHeight: "", topHeight: "", listTop: "", navigationBarHeight: "", haveMore: false, pendingUploadTask: null, showContinueUpload: false }; }, components: { topHeader }, onLoad(options) { this.init(); uni.getSystemInfo({ success: (res) => { this.statusBarHeight = res.statusBarHeight; this.listHeight = res.screenHeight - res.statusBarHeight - 60; this.topHeight = res.statusBarHeight this.listTop = res.statusBarHeight + 40 this.navigationBarHeight = res.navigationBarHeight; }, }); if (options &amp;&amp; options.autoToAudit) { this.current = 1; this.searchInfo.status = 10; this.searchInfo.current_page = 1; this.tableData = []; this.getData(); } setTimeout(() => { this.triggered = true; }, 1000) }, onShow() { const pendingTask = uni.getStorageSync('pendingUploadTask'); if (pendingTask &amp;&amp; pendingTask.videos &amp;&amp; pendingTask.videos.length > 0) { this.pendingUploadTask = pendingTask; this.showContinueUpload = false; // 自动开始上传 this.continueUpload(); } else { this.showContinueUpload = false; } }, onReachBottom() { // this.searchInfo.current_page = 1 // this.tableData = [] console.log('触底') this.searchInfo.current_page += 1 this.getData() }, computed: { showPaiShe() { // 在Vue 2中,计算属性是一个包含getter函数的对象 //this.searchInfo.status = 8; return this.current == 0; }, showShen() { //this.searchInfo.status = 9; return this.current == 1; }, showReapct() { //this.searchInfo.status = 11; return this.current == 2; }, showSuccess() { //this.searchInfo.status = 12; return this.current == 3; }, }, methods: { previewVideos(videoArray) { uni.navigateTo({ url: "/pages/videoPlayer/videosPlayer?urls=" + encodeURIComponent(JSON.stringify(videoArray .map(item => item.video))) }); }, select(e) { console.log('选择文件:', e) }, // 获取上传进度 progress(e) { console.log('上传进度:', e) }, // 上传成功 success(e) { console.log('上传成功') }, // 上传失败 fail(e) { console.log('上传失败:', e) }, previewImage(url) { console.log(url) uni.previewImage({ urls: [url], // 需要预览的图片链接列表 current: url // 当前显示图片的链接 }); }, //返回上一页面 back() { uni.navigateBack({ delta: 1 // 返回的页面层级。默认值为1,表示返回上一个页面。 }); }, upApprove(current) { let param = { task_id: current.id }; this.$uupp.ApiTaskQuickShotSubmit(param).then((res) => { if (res.code !== 0) { uni.showToast({ title: res.msg, icon: 'none', duration: 2000, mask: true, }); return; } uni.showToast({ title: '提交成功', icon: 'success', duration: 2000, mask: true, }); // 提交成功后移除当前项 this.tableData = this.tableData.filter(item => item.id !== current.id); // 重新获取数据确保一致性 setTimeout(() => { this.searchInfo.current_page = 1; this.getData(); }, 500); }); }, // upCover(current) { // let that = this // uni.chooseImage({ // count: 1, // sizeType: ['original', 'compressed'], // sourceType: ['album'], //这要注意,camera掉拍照,album是打开手机相册 // success: (res) => { // const tempFilePaths = res.tempFilePaths; // upApi('quickshot', tempFilePaths[0], (res) => { // console.log(res) // if (res.status &amp;&amp; res.status !== 'ok') { // uni.showToast({ // title: '上传失败', // mask: false, // duration: 1000, // }) // return false // } // uni.$uupp.ApiTaskQuickShotQuery({ // cover: res.data.src, // type: 'cover', // task_id: current.id // }).then((res) => { // console.log(66666) // let resData = res // console.log(res.data, resData) // that.tableData.forEach((item) => { // console.log(ph(resData.data.detail.video_path)) // if (item.id === resData.data.detail.id) { // console.log(resData.data.detail) // item.cover_thumb = resData.data.detail // .cover_path // } // }) // uni.showToast({ // title: "上传成功", // icon: 'success', // 默认为success,可选'none', 'success', 'loading', 'error' // duration: 1000, // 显示时长,默认1500ms // mask: false, // 是否显示透明蒙层,防止触摸穿透,默认false // }); // }) // }) // } // }); // }, upVideo(current) { let that = this console.log('开始上传') uni.chooseVideo({ sourceType: ['album'], compressed: false, success: function(res) { console.log('上传中') const tempFilePath = res.tempFilePath; uni.$uupp.ApiTaskHomeStatus({ id: current.id }).then((res) => { if (res.code !== 0) { uni.showToast({ title: res.msg, mask: false, duration: 1000, }) return false } console.log('更新上传状态') that.tableData.forEach((item) => { if (item.id === current.id) { item.is_upload = 1 } }) uni.showToast({ title: '开始后台上传', mask: false, duration: 1000, }) upApi('quickshot', tempFilePath, (res) => { if (res.status &amp;&amp; res.status !== 'ok') { uni.showToast({ title: '上传失败', mask: false, duration: 1000, }) return false } uni.$uupp.ApiTaskSelfVoiceUpload({ url: res.data.src, type: 'video', task_id: current.id }).then((res) => { console.log(66666) console.log(res.data) let resData = res console.log(resData) that.tableData.forEach((item) => { console.log(ph(resData.data.detail .video_path)) if (item.id === resData.data.detail .id) { item.is_upload = resData.data .detail.is_upload item.video_path = resData.data .detail.video_path } }) }) }) }) } }); }, showVideo() { uni.chooseVideo({ sourceType: ['album'], }) }, loadMore() { console.log('加载更多') this.searchInfo.current_page += 1 this.getData() }, init() { this.searchInfo.token = uni.getStorageSync('token'); this.tableData = [] this.getData(); }, goToShoot(item, index) { console.log('goToShoot被触发') console.log(item, index); console.log(this.searchInfo.status); console.log(`${actionPage}?id=`) console.log(this.searchInfo.status) if (this.searchInfo.status != 10 || this.searchInfo.status != 12) { console.log(666) console.log('item.id:', item.id, typeof item.id); uni.setStorageSync(`${PreFix}${item.id}`, item); console.log(77) uni.navigateTo({ url: `${actionPage}?id=` + item.id, // url:"/pages/virtualAction/virtualAction" }); } }, // goToShoot(item, index) { // console.log('goToShoot被触发') // console.log(item, index); // console.log('item.id:', item.id, typeof item.id); // if (this.searchInfo.status != 10 &amp;&amp; this.searchInfo.status != 12) { // if (item &amp;&amp; item.id) { // uni.setStorageSync(`${PreFix}${item.id}`, item); // uni.redirectTo({ // url: `${actionPage}?id=${item.id}`, // }); // } else { // uni.showToast({ title: '任务ID无效', icon: 'none' }); // } // } // }, // goToShoot(item, index) { // console.log('跳转前页面栈:', getCurrentPages().map(p => p.route)); // uni.navigateTo({ // url: `/pages/QuickShotAction/index?id=${item.id}&amp;_t=${Date.now()}`, // success: () => { // console.log('跳转后页面栈:', getCurrentPages().map(p => p.route)); // }, // fail: (err) => { // console.error('跳转失败:', err); // uni.showToast({ title: '跳转失败', icon: 'none' }); // } // }); // }, onClickItem(currentIndex) { console.log('init onclickItem') this.searchInfo.current_page = 1; if (this.current !== currentIndex) { this.current = currentIndex; switch (this.current) { case 0: this.tableData = [] this.searchInfo.current_page = 1 this.searchInfo.status = 8; break; case 1: this.tableData = [] this.searchInfo.current_page = 1 this.searchInfo.status = 10; break; case 2: this.tableData = [] this.searchInfo.current_page = 1 this.searchInfo.status = 11; break; default: this.tableData = [] this.searchInfo.current_page = 1 this.searchInfo.status = 12; break; } this.getData(); console.log('init'); } let that = this; }, //显示商品编号 // 分页触发 change(e) { this.$refs.table.clearSelection(); this.selectedIndexs.length = 0; this.searchInfo.pageCurrent = e.current; this.getData(); }, // 获取数据 getData() { this.loading = true; console.log('获取数据参数:', this.searchInfo); // 返回 Promise return uni.$uupp.ApiTaskQuickShotQuery(this.searchInfo).then((res) => { if (res.code !== 0) { this.loading = false; this.triggered = false; uni.showToast({ title: res.msg, icon: 'error', duration: 1000, mask: false, }); return Promise.reject(res.msg); // 返回拒绝的 Promise } let data = res?.data?.list ?? []; console.log('原始接口数据:', data); // 数据映射处理 data = data.map((item) => { let pitem = {}; Object.keys(item).forEach((key) => { if (TASKMAP?.[key]) { pitem[TASKMAP[key]] = item[key]; } }); if (pitem.cover_thumb) { pitem.cover_thumb = pitem.cover_thumb.replace(/(https?:\/\/[^/]+)\/\1\//g, '$ 1/'); } return pitem; }); // 更新标签计数 res.data.census.forEach((item) => { if (item.status === 8) this.items[0] = `待拍摄(${item.num})`; if (item.status === 10) this.items[1] = `待审核(${item.num})`; if (item.status === 11) this.items[2] = `需重拍(${item.num})`; if (item.status === 12) this.items[3] = `已完成(${item.num})`; }); // 合并数据时去重 const newData = [...this.tableData, ...data]; const uniqueData = []; const idSet = new Set(); newData.forEach(item => { if (!idSet.has(item.id)) { idSet.add(item.id); uniqueData.push(item); } }); this.tableData = uniqueData; this.total = res?.data?.page?.total ?? 0; this.$forceUpdate(); return Promise.resolve(); // 返回解决的 Promise }).catch((err) => { console.error('获取数据失败:', err); return Promise.reject(err); // 确保错误继续传递 }).finally(() => { this.loading = false; this.triggered = false; }); }, onRefresh() { this.triggered = true; this.searchInfo.current_page = 1; this.tableData = []; // 清空现有数据 this.getData().finally(() => { this.triggered = false; }); }, async continueUpload() { if (!this.pendingUploadTask || !this.pendingUploadTask.videos || this.pendingUploadTask.videos.length === 0) { uni.showToast({ title: '没有待上传的视频', icon: 'none' }); return; } uni.showLoading({ title: '自动上传中...' }); const task = this.pendingUploadTask; try { // 1. 上传所有视频 const uploadedVideos = []; for (let i = 0; i < task.videos.length; i++) { const videoPath = task.videos[i]; if (!videoPath) continue; // 上传视频 const res = await new Promise((resolve, reject) => { upApi('quickshot', videoPath, (r) => { if (r.status &amp;&amp; r.status !== 'ok') reject(r); else resolve(r); }); }); uploadedVideos.push({ video: res.data.src, extra: this.content &amp;&amp; this.content[i] ? this.content[i].extra : '' }); // 删除本地文件 await new Promise((resolve) => { uni.removeSavedFile({ filePath: videoPath, complete: resolve }); }); } // 2. 提交上传信息 await this.$uupp.ApiTaskQuickShotUpload({ videos: uploadedVideos, type: 'video', task_id: task.id }); // 3. 清理本地存储 uni.removeStorageSync('pendingUploadTask'); this.pendingUploadTask = null; this.showContinueUpload = false; // 4. 刷新数据(只执行一次) uni.showToast({ title: '上传成功', icon: 'success' }); await this.refreshDataAfterUpload(task.id); } catch (e) { console.error('上传失败:', e); uni.showToast({ title: '上传失败', icon: 'none' }); } finally { uni.hideLoading(); } }, // 新增方法:上传成功后专门的数据刷新逻辑 async refreshDataAfterUpload(taskId) { this.searchInfo.current_page = 1; this.tableData = []; // 获取新数据 await this.getData(); // 确保数据唯一性 const uniqueData = []; const idSet = new Set(); [...this.tableData].forEach(item => { if (!idSet.has(item.id)) { idSet.add(item.id); uniqueData.push(item); } }); this.tableData = uniqueData; this.$forceUpdate(); } } }; </script> <style> /* #ifndef H5 */ /* page { padding-top: 85px; } */ /* #endif */ .uni-group { display: flex; align-items: center; } .uni-padding-wrap { /* width: 750rpx; */ padding: 0px 30px; /* position: fixed; */ /* top:50; */ z-index: 100; /* height: 200px; */ display: flex; /* justify-content: space-between; */ background-color: #fff; position: fixed; /* border: 1px solid #337ecc; */ } .content { height: 150px; text-align: center; } .content-text { font-size: 14px; color: #666; } .color-tag { width: 25px; height: 25px; } .uni-list { flex: 1; } .uni-list-item { /* #ifndef APP-NVUE */ display: flex; /* #endif */ flex: 1; flex-direction: row; background-color: #ffffff; } .uni-list-item__container { padding: 12px 15px; width: 100%; flex: 1; position: relative; /* #ifndef APP-NVUE */ display: flex; box-sizing: border-box; /* #endif */ flex-direction: row; justify-content: space-between; align-items: center; border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: #eee; } .uni-list-item__content-title { font-size: 14px; } .image-box { width: 100rpx; height: 100rpx; } .button-group { display: flex; flex-direction: column; justify-content: space-between; align-items: center; } .scroll-view { /* height: 100vh; */ /* height: 100%; */ /* padding-bottom: 181.16rpx; */ /* margin-top: 543.48rpx; */ overflow-y: scroll; } .fixed-header { position: fixed; background-color: #fff; /* height: 163.04rpx; */ /* padding-top: 36.23rpx; padding-bottom: 36.23rpx; */ /* 确保元素在最上层 */ /* 其他样式,如背景色、高度等 */ } .uni-container { padding-top: 120px; } .card-actions { display: flex; padding-top: 18.12rpx; padding-bottom: 18.12rpx; align-items: center; justify-content: space-between; } .action-item { margin: 0 9.06rpx; } .title-box { height: 140rpx; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #efefef; } .title-box .left { display: flex; } .title-box .right { display: flex; align-items: center; } .title-box .msg { padding: 18.12upx 0; display: flex; flex-direction: column; justify-content: space-between; } .title-box .name { font-size: 21.74rpx; color: #909399; } .kong { position: fixed; bottom: 0; left: 40%; } .no-more { display: flex; flex-direction: row; justify-content: center; align-items: center; padding: 18.12rpx 0; } .page { padding-top: var(--status-bar-height); /* 适配状态栏高度 */ padding-bottom: var(--safe-area-inset-bottom); /* 适配底部安全区 */ } </style>看不到预览图片,17:05:51.879 $ 1//mxt_video/video/development/quickshot/mcsumzw9KXKzOS6QbEAqvN1vlxuAMrjH.jpeg at pages/Quickshot/Quickshot.vue:350
07-08
<script> /**新分享组件 * shareData:分享所需数据内容 * { * data: 数据详情 必传 * identity: 身份id 默认'' * type: 1=企业 2=商家 默认'' * source: 来源 默认share * } * * type:分享类型,必传,0一元拓客,1视频引流,2裂变红包,3商品管理 9线上线下分销 */ import url_config, { developementMode } from '@/common/config'; import { getImgViewUrl, formatGetUri } from "@/common/util.js"; import permision from "@/common/permission.js"; import posterConfig from './posterConfig.js' export default { name: 'w-share', props: { title: { type: String, default: () => { return '分享到' }, }, shareData: { type: Object, default: () => { return {} }, }, type: { type: [Number, String], default: () => { return 0 }, }, isPoster: { type: Boolean, default: () => { return false }, }, isImage: { type: Boolean, default: () => { return false }, }, imgSrc: { type: String, default: () => { return '' }, }, isStoreGoods: {// 是否是店铺-商品管理-实物商品 type: Boolean, default: true, }, linkId: { type: [Number, String], default: () => { return '' }, }, }, data() { return { show: false, share: { WXSceneSession: {}, WXSceneTimeline: {}, }, page: "", shareLink: '', posterImg: '',// 海报图片 wxCodeImg: '',// 微信小程序码图片 qrcodeImg: '',// 二维码图片 isImg: false, imgType: '',// poster海报,wxCode微信小程序码,qrcode二维码 userData: {}, distributionType: '',// 分销类型, type=9时用 showModal: false, modalType: '', } }, computed: { saveLabel() { let txt = ''; switch (this.imgType) { case 'wxCode': txt = '保存小程序码'; break; case 'qrcode': txt = '保存二维码'; break; } return txt }, notNeiborhood() { // 非邻里团长分销 return this.type*1 === 9 &amp;&amp; ['1', 1].includes(this.distributionType) } }, mounted() { this.getUserData(); }, onHide() { console.log("onHide"); }, methods: { // 用户信息 getUserData() { let _this = this; _this.$api.userIndex({}).then(res => { if (res.data.code == 200) { _this.userData = res.data.data; } else { _this.$toast.msg(res.data.msg) } }).catch(err => { console.log(err) }) }, // 关闭弹窗 handleClose() { this.$emit('close-popup', this.show); // console.log('关闭弹窗'); this.show = false; }, // 显示弹窗 open() { this.show = true; this.$nextTick(() => { if (this.type*1 == 0) {// 一元拓客 this.page = '/pages/merchant/product/product_detail'; this.initShareData(); } else if (this.type*1 == 1) {// 视频引流 this.page = this.isStoreGoods ? '/pages/store/online_goods' : '/pages/oneYuan/detail_video'; this.initShareData(); } else if (this.type*1 == 2) {// 外链 this.page = '/pages/store/goods'; this.initShareData(); } else if (this.type*1 == 3) {// 商品管理 this.page = '/pages/store/goods'; let thumb_url = ''; if (this.shareData.data.theme_image_url) {// 主题图 thumb_url = this.shareData.data.theme_image_url; } else if (this.shareData.data.thumb_url) {// 缩略图 thumb_url = this.shareData.data.thumb_url; } this.shareData.data.thumb_url = thumb_url; this.initShareData(); } else if (this.type*1 == 4) {// 服务项目 this.page = '/pages/shop/details/project'; let thumb_url = ''; if (this.shareData.data.theme_image_url) {// 主题图 thumb_url = this.shareData.data.theme_image_url; } else if (this.shareData.data.thumb_url) {// 缩略图 thumb_url = this.shareData.data.thumb_url; } this.shareData.data.thumb_url = thumb_url; this.initShareData(); } else if (this.type*1 == 5) {// 优惠券 this.page = '/pages/marketing/coupon'; this.initShareDataImage(); } else if (this.type*1 == 6) {// 马上有礼 this.page = '/pages/marketing/codeGifts'; this.initShareDataImage(); } else if (this.type*1 == 7) {// 精品课程 this.page = '/pages/store/curriculum'; let thumb_url = ''; if (this.shareData.data.theme_image_url) {// 主题图 thumb_url = this.shareData.data.theme_image_url; } else if (this.shareData.data.thumb_url) {// 缩略图 thumb_url = this.shareData.data.thumb_url; } this.shareData.data.thumb_url = thumb_url; this.initShareData(); } else if (this.type*1 == 8) {// 店铺 // 店铺装修需求:应用内进店进入公域店铺首页,通过分享进入则进入私域首页 this.page = '/pages/sub-store/private-domain/index'; this.initShareData(); } else if (this.type*1 == 9) {// 精选商品 this.page = '/pages/user/promotion/selected_product'; this.distributionType = this.shareData.distributionType; this.initShareDataImage(); } }) }, // 纯图片分享,优惠券/码上有礼 initShareDataImage() { this.share = { WXSceneSession: {// 分享到微信聊天,小程序卡片类型 type: 2, imageUrl: (this.imgSrc || this.posterImg) }, WXSceneTimeline: {// 分享到微信朋友圈 type: 2, imageUrl: (this.imgSrc || this.posterImg) }, }; this.getLink(); }, // 一元拓客/视频引流/商品管理/服务项目 initShareData() { const imageUrl = uni.getSystemInfoSync().platform === 'ios' ? this.setShareImg((this.shareData.data.thumb_url || this.shareData.data.image_url),100) : this.setShareImg((this.shareData.data.thumb_url || this.shareData.data.image_url)); // ios 朋友圈 图片 大小20KB console.log("this.type", this.type) console.log("imageUrl", imageUrl) this.share = { WXSceneSession: {// 分享到微信聊天,小程序卡片类型 type: 5, title: this.shareData.data.title, // imageUrl: this.shareData.data.thumb_url || this.shareData.data.image_url, imageUrl: (this.type*1 == 8 ? (this.setShareImg((this.shareData.data.image_url), 500)) : (this.shareData.data.thumb_url || this.shareData.data.image_url)), miniProgram: { id: 'gh_7256f78589d4', path: this.getPath(), type: this.$developementMode !== 'pro' ? 2 : 0,// 微信小程序版本类型,可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。 webUrl: 'http://uniapp.dcloud.io' }, }, WXSceneTimeline: {// 分享到微信朋友圈 type: 0, href: this.getLink(), title: this.shareData.data.title, summary: this.shareData.data.describe || '', imageUrl: imageUrl, }, }; }, // 裂变红包 initRedPacketShareData() { let that = this let item = that.shareData.data; const typeId = item.red_type; // 红包类型 const type = { 2: { // 带文章 name: 'article', url: `${that.$urlShare}/#/pages/index/article`, mini_path: 'pages/index/article' }, 3: { // 带名片 name: 'member_card', url: `${that.$urlShare}/#/pages/index/cards`, mini_path: 'pages/index/cards' }, }; const typeItem = type[typeId]; if (!typeItem) { return that.$toast.msg('未获取到分享配置'); } uni.showLoading({ mask: true, title: '请稍后..' }) // 类型名称 let params = {}; if (typeItem.name === 'member_card') { params = { ident: item.member_card_id, red_order: item.order }; that.$api.getRedCardInfo(params).then(res => { const { code, data } = res.data; if (code === 200) { data.info.imageUrl = data.info.style_image || data.info.image; setShareData(data.info); } else { that.$toast.msg(res.data.msg || 'error'); } }).catch(err => { console.log(err) that.$toast.msg(err || 'error'); }) } if (typeItem.name === 'article') { params = { order: item.article_order, red_order: item.order }; that.$api.getRedArticleInfo(params).then(res => { const { code, data } = res.data; if (code === 200) { data.info.imageUrl = data.info.image; setShareData(data.info); } else { that.$toast.msg(res.data.msg || 'error'); } }).catch(err => { console.log(err) that.$toast.msg(err || 'error'); }) } function setShareData(shareData) { const query = formatGetUri({ ivtCode: that.userData.code, order: item.order, cardsId: shareData.ident, aid: encodeURIComponent(shareData.share), promoterCode: that.userData.promoter_code, storeId: that.userData.employee_store_id, });// url参数 const imageUrl = uni.getSystemInfoSync().platform === 'ios' ? that.setShareImg(shareData.imageUrl,100) : that.setShareImg(shareData.imageUrl); // ios 朋友圈 图片 大小20KB that.share = { WXSceneSession: {// 分享到微信聊天,小程序卡片类型 title: shareData.title, imageUrl: shareData.imageUrl, miniProgram: { id: 'gh_7256f78589d4', path: `${typeItem.mini_path}${query}`, type: that.$developementMode !== 'pro' ? 2 : 0,// 微信小程序版本类型,可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。 webUrl: 'http://uniapp.dcloud.io' }, }, WXSceneTimeline: {// 分享到微信朋友圈 href: `${typeItem.url}${query}`, title: shareData.title, summary: shareData.desc || shareData.title, imageUrl: imageUrl, }, }; that.shareLink = `${typeItem.url}${query}`; } }, // 复制链接 copyText() { // 0一元拓客/1视频引流/2外链/5优惠券/6马上有礼 if ([0,1,2,5,6].includes(this.type*1)) { uni.setClipboardData({ data: this.shareLink, success: () => { //复制成功的回调函数 this.$toast.msg('复制成功', 'success') } }) } else { uni.showLoading({ mask: true, title: '链接生成中..' }) let query = this.getPath(1); query = query.substring(1); let params = { path: this.page.substring(1), query: query, env_version: this.$developementMode !== 'pro' ? 'trial' : 'release' } console.log("params", params); this.$api.getWxMiniShortLink(params).then(res => { console.log("getWxMiniShortLink", res); if (res.data.code == 200) { const link = res.data.data.link; const txt = '【哈客】'+link+'\r\n「'+this.shareData.data.title+'」\r\n点击链接直接打开' uni.setClipboardData({ data: txt, success: () => { //复制成功的回调函数 this.$toast.msg('复制成功,快去粘贴吧!') } }); } else { this.$toast.msg(res.data.msg) } }) } }, // 生成海报 handlePoster() { uni.showLoading({ mask: true, title: '数据加载中..' }) let query = this.getPath(1); query = query.substring(1); let params = { path: this.page.substring(1), query: query, env_version: this.$developementMode !== 'pro' ? 'trial' : 'release' } console.log("params", params); this.$api.getUnlimitedWxQRCode(params).then(res => { console.log("getUnlimitedWxQRCode", res); if (res.data.code == 200) { uni.showLoading({ mask: true, title: '海报生成中..' }) let poster = {}; if (this.type*1 == 8) {// 店铺 console.log("this.shareData.data11", this.shareData.data); poster = { ...posterConfig.store }; poster.views[1].views[1].text = '发现好店,分享好友共享快乐!';// 文案 poster.views[2].src = this.shareData.data.thumb_url;// 主图第一张 poster.views[3].text = this.shareData.data.title;// 标题 if (this.shareData.data.industry.length) { poster.views[4].text = this.shareData.data.industry.join(' | '); } poster.views[6].src = res.data.data.qrcode;// 小程序码 console.log("poster=", poster); } else { poster = { ...posterConfig.item }; poster.views[1].views[1].text = '发现好物,分享好友,快乐加倍!';// 文案 poster.views[2].text = '邀请好友,领取更多福利!';// 文案 // 项目图片 let image_url = ''; if (this.shareData.data.thumb_url) { image_url = this.shareData.data.thumb_url; poster.views[3].views[0].src = image_url;// 主图第一张 } else { image_url = this.shareData.data.image_url; if (typeof image_url === "string") { poster.views[3].views[0].src = image_url;// 主图第一张 } else if (typeof image_url === "object") { if (Array.isArray(image_url)) { poster.views[3].views[0].src = image_url[0];// 主图第一张 } } } poster.views[4].views[0].text = this.shareData.data.title;// 标题 poster.views[5].views[1].text = this.shareData.data.price;// 价格 poster.views[7].src = res.data.data.qrcode;// 小程序码 } poster.views[1].views[0].src = this.userData.avatar;// 用户头像 this.$refs.painter.render(poster); this.$refs.painter.canvasToTempFilePathSync({ fileType: "png", pathType: 'url', quality: 1, success: (res) => { console.log("canvasToTempFilePathSync res=", res); uni.hideLoading(); this.posterImg = res.tempFilePath; this.isImg = true; this.imgType = 'poster'; }, fail: (err) => { console.log("canvasToTempFilePathSync fail=", err); uni.hideLoading(); this.isImg = false; this.$toast.msg('海报生成失败,请重试!') }, }); } else { this.$toast.msg(res.data.msg) this.isImg = false; } }) // console.log("handlePoster", this.isStoreGoods); // if (this.isStoreGoods) { // uni.navigateTo({ // url: `/pages/poster/poster?id=${this.shareData.data.id}&amp;type=${this.type}` // }) // } else { // this.$emit('poster'); // } }, // 分享到聊天 shareWXSceneSession() { let _this = this; // 修改分享配置 if (_this.isImg || _this.type*1 === 9) { _this.initShareDataImage(); } else { _this.initShareData(); } console.log("_this.share.WXSceneSession:" + JSON.stringify(_this.share.WXSceneSession)); console.log("_this.share.WXSceneSession:", _this.share.WXSceneSession); // #ifndef APP-PLUS _this.$toast.msg('请下载APP操作'); // #endif // #ifdef APP-PLUS _this.modalType = 'WXSceneSession'; _this.showModal = true; // #endif }, shareWXSceneSessionFunc() { let _this = this; uni.showLoading({ mask: true, title: '请稍后..' }) // 由于特殊情况下,分享跳转后,返回app未触发success,fail,complete,故延时处理loading隐藏 setTimeout(() => { _this.sharePosters(); uni.hideLoading(); // _this.show = false; }, 2000) // 分享到聊天 uni.share({ provider: "weixin", scene: "WXSceneSession", ..._this.share.WXSceneSession, success: function(res) { console.log("success:" + JSON.stringify(res)); }, fail: function(err) { console.log("fail:" + JSON.stringify(err)); } }); }, // 分享到朋友圈 shareWXSceneTimeline() { let _this = this; // 修改分享配置 if (_this.isImg || _this.type*1 === 9) { _this.initShareDataImage(); } else { _this.initShareData(); } console.log("WXSceneTimeline:" + JSON.stringify(_this.share.WXSceneTimeline)); console.log("WXSceneTimeline:", _this.share.WXSceneTimeline); // #ifndef APP-PLUS _this.$toast.msg('请下载APP操作'); // #endif // #ifdef APP-PLUS _this.modalType = 'WXSceneSession'; _this.showModal = true; // #endif }, shareWXSceneTimelineFunc() { let _this = this; uni.showLoading({ mask: true, title: '请稍后..' }) // 由于特殊情况下,分享跳转后,返回app未触发success,fail,complete,故延时处理loading隐藏 setTimeout(() => { _this.sharePosters(); uni.hideLoading(); // _this.show = false; }, 2000) uni.share({ provider: "weixin", scene: "WXSceneTimeline", ..._this.share.WXSceneTimeline, success: function(res) { console.log("success:" + JSON.stringify(res)); }, fail: function(err) { console.log('-----------朋友圈 err-----------------------') console.log("fail:" + JSON.stringify(err)); console.log('----------------------------------') } }); }, // 分享到朋友圈图片处理 setShareImg(url,width = 300){ const _url = getImgViewUrl({ url, width }); console.log("setShareImg:" + _url); return _url; }, // 分享页面链接数据整合,一元拓客/视频引流 getPath(type = null) {// 分享到小程序,一元拓客/视频引流 const that = this; const params = { // id: that.shareData.data.id || '', ivtCode: that.userData.code || '', // type: that.shareData.type || '', // identity: that.shareData.identity || '', // source: that.shareData.source || '' }; if (that.isStoreGoods) { if ([2,3,4,7,8].includes(that.type*1)) {// 外链/实物商品/服务项目/精品课程/店铺 params.id = that.shareData.data.id; } else {// 图文和视频 params.linkId = that.linkId || that.shareData.data.id; } } else { params.id = that.shareData.data.id; } if ([5,6].includes(that.type*1)) {// 优惠券/码上有礼 params.code = that.shareData.data.code; } if (type) {// 分享到微信朋友圈/复制链接 return formatGetUri(params); } else { return that.page+formatGetUri(params); } }, // 分享到微信朋友圈/复制链接 getLink() { let query = this.getPath(1); query = query.substring(1); query = encodeURIComponent(query); let path = encodeURIComponent(this.page); let env_version = developementMode == 'pro' ? 1 : 2; let shareLink = url_config+'/index/index/jump2mini?path='+path+'&amp;query='+query+'&amp;env_version='+env_version this.shareLink = shareLink; return this.shareLink; }, // 保存海报 handleSaveImg(type) { let _this = this; console.log("_this.imgSrc:" + _this.imgSrc); console.log("_this.posterImg:" + _this.posterImg); console.log("_this.wxCodeImg:" + _this.wxCodeImg); console.log("_this.qrcodeImg:" + _this.qrcodeImg); let filePath = ''; if (type == 'poster') {// 保存海报图片 filePath = (_this.imgSrc || _this.posterImg); } else { if (_this.imgType == 'wxCode') { filePath = _this.wxCodeImg; } else { filePath = _this.qrcodeImg; } } if (!filePath) { return } // #ifndef APP-PLUS _this.$toast.msg('请下载APP操作'); return // #endif // #ifdef APP-PLUS permision.actionCheck({ ios:'album', // 获取 相册 android:'android.permission.WRITE_EXTERNAL_STORAGE', // 获取 相册 callback:()=>{ uni.saveImageToPhotosAlbum({ //保存图片到系统相册。 filePath: filePath, //图片文件路径 success: function(ret) { if (type == 'poster') { _this.$toast.msg("海报已保存到本地相册"); } else { if (_this.imgType == 'wxCode') { _this.$toast.msg("小程序码已保存到本地相册"); } if (_this.imgType == 'qrcode') { _this.$toast.msg("二维码已保存到本地相册"); } } }, fail: function(e) { console.log(e); _this.$toast.msg("图片保存失败"); }, }); } }); // #endif }, // 查看海报 previewImg() { uni.previewImage({ urls: [(this.imgSrc || this.posterImg)] }) }, // 取消 handleCancel() { if (this.isImg) { this.posterImg = ''; this.isImg = false; } else { this.handleClose(); } }, // 生成微信小程序码 handleWXQrcode() { uni.showLoading({ mask: true, title: '数据加载中..' }) let query = this.getPath(1); query = query.substring(1); let params = { path: this.page.substring(1), query: query, env_version: this.$developementMode !== 'pro' ? 'trial' : 'release' } let apiUrl = 'getUnlimitedWxQRCode' if ([9].includes(this.type*1)) { // 推广商品页的分销分享 // params.query = formatGetUri(this.shareData.data); params = this.shareData.data; apiUrl = 'getOrdinaryWxQRCode'; } console.log("params", params); this.$api[apiUrl](params).then(res => { console.log("getUnlimitedWxQRCode", res); if (res.data.code == 200) { uni.showLoading({ mask: true, title: '海报生成中..' }) let poster = { ...posterConfig.qrcode.wxCode }; poster.views[1].src = this.userData.avatar;// 用户头像 poster.views[2].src = res.data.data.qrcode;// 小程序码 this.$refs.painter.render(poster); this.$refs.painter.canvasToTempFilePathSync({ fileType: "png", pathType: 'url', quality: 1, success: (ret) => { console.log("canvasToTempFilePathSync ret=", ret); uni.hideLoading(); this.posterImg = ret.tempFilePath; this.isImg = true; this.imgType = 'wxCode'; this.$nextTick(() => { let codeUrl = res.data.data.qrcode; if ([9].includes(this.type*1) ) { codeUrl = res.data.data.data; } this.handleQrcodeImg(codeUrl, 'wxCodeImg'); }) }, fail: (err) => { console.log("canvasToTempFilePathSync fail=", err); uni.hideLoading(); this.isImg = false; this.$toast.msg('海报生成失败,请重试!') }, }); } else { this.$toast.msg(res.data.msg) this.isImg = false; } }) }, // 生成二维码 handleQrcode() { uni.showLoading({ mask: true, title: '数据加载中..' }) let query = { ivtCode: this.userData.code || '', storeId: this.shareData.data.id || '', } let params = { str: this.page+formatGetUri(query) } console.log("params", params); this.$api.getMiniQrcodeV2(params).then(res => { console.log("getMiniQrcodeV2", res); if (res.data.code == 200) { uni.showLoading({ mask: true, title: '海报生成中..' }) let poster = { ...posterConfig.qrcode.qrcode }; poster.views[1].src = this.userData.avatar;// 用户头像 poster.views[2].src = res.data.data.full_url;// 二维码 this.$refs.painter.render(poster); this.$refs.painter.canvasToTempFilePathSync({ fileType: "png", pathType: 'url', quality: 1, success: (ret) => { console.log("canvasToTempFilePathSync ret=", ret); uni.hideLoading(); this.posterImg = ret.tempFilePath; this.isImg = true; this.imgType = 'qrcode'; this.$nextTick(() => { this.handleQrcodeImg(res.data.data.full_url, 'qrcodeImg'); }) }, fail: (err) => { console.log("canvasToTempFilePathSync fail=", err); uni.hideLoading(); this.isImg = false; this.$toast.msg('海报生成失败,请重试!') }, }); } else { this.$toast.msg(res.data.msg) this.isImg = false; } }) }, handleQrcodeImg(qrcode, name) { let codeImg = { ...posterConfig.qrcode[name] }; // if (name == 'wxCodeImg') { // codeImg = { ...posterConfig.qrcode.wxCodeImg }; // } else { // codeImg = { ...posterConfig.qrcode.qrcodeImg }; // } if ([9].includes(this.type * 1)) { codeImg = { ...posterConfig.qrcode.qrcodeType9 } codeImg.views[1].text = this.shareData.data.storeName;// 商店名 if (this.shareData.data.storeName.length >= 10) { codeImg.views[1].css.fontSize = '24rpx' } } codeImg.views[0].src = qrcode;// 小程序码 this.$refs.painter.render(codeImg); this.$refs.painter.canvasToTempFilePathSync({ fileType: "png", pathType: 'url', quality: 1, success: (res) => { console.log("canvasToTempFilePathSync res=", res); uni.hideLoading(); this[name] = res.tempFilePath; }, fail: (err) => { console.log("canvasToTempFilePathSync fail=", err); uni.hideLoading(); }, }); }, // 记录分享海报次数 sharePosters() { if (this.shareData.data &amp;&amp; this.shareData.data.id) { let params = { id: this.shareData.data.id }; this.$api.ShareMyPromotionGoodsPosters(params).then(res => { console.log("ShareMyPromotionGoodsPosters res", res); }).catch(err => { console.log("ShareMyPromotionGoodsPosters err", err); }) } }, handleModalConfirm() { if (this.modalType == 'WXSceneSession') {// 微信好友 this.shareWXSceneSessionFunc(); } else if (this.modalType == 'WXSceneTimeline') {// 微信朋友圈 this.shareWXSceneTimelineFunc(); } }, } } </script> 把这段代码优化为 vue3 setup ts 的写法
最新发布
11-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值