From 030f7525f871fbcaeabef2eb38b66f9100122c94 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=A2=E8=B6=8A?= <552369664@qq.com>
Date: Mon, 28 Jul 2025 14:07:51 +0800
Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E9=A1=B6=E9=83=A8?=
=?UTF-8?q?=E5=AF=BC=E8=88=AA=E6=A0=8F=E6=89=AB=E4=B8=80=E6=89=AB=E5=9B=BE?=
=?UTF-8?q?=E6=A0=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../s-search-block/s-search-block.vue | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/sheep/components/s-search-block/s-search-block.vue b/sheep/components/s-search-block/s-search-block.vue
index 438b13de..cef41bef 100644
--- a/sheep/components/s-search-block/s-search-block.vue
+++ b/sheep/components/s-search-block/s-search-block.vue
@@ -12,11 +12,16 @@
]"
:class="[{ 'border-content': navbar }]"
>
-
-
+
{{ placeholder }}
@@ -24,10 +29,10 @@
{{ item }}
+ >{{ item }}
From e64a9d2e6544ddacbfe8e8561c79e3daa5b80979 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=A2=E8=B6=8A?= <552369664@qq.com>
Date: Mon, 28 Jul 2025 16:49:01 +0800
Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=E6=89=AB=E4=B8=80?=
=?UTF-8?q?=E6=89=AB=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sheep/components/s-block/s-block.vue | 10 +-
.../s-search-block/s-search-block.vue | 112 +++++++++++++++---
2 files changed, 99 insertions(+), 23 deletions(-)
diff --git a/sheep/components/s-block/s-block.vue b/sheep/components/s-block/s-block.vue
index fc447866..efebe341 100644
--- a/sheep/components/s-block/s-block.vue
+++ b/sheep/components/s-block/s-block.vue
@@ -20,14 +20,14 @@
// 组件样式
const elBackground = computed(() => {
if (props.styles) {
- if (props.styles.bgType === 'color')
+ if (props.styles.bgType === 'color') {
return { background: props.styles.bgColor };
- if (props.styles.bgType === 'img')
+ }
+ if (props.styles.bgType === 'img') {
return {
- background: `url(${sheep.$url.cdn(
- props.styles.bgImg,
- )}) no-repeat top center / 100% auto`,
+ background: `url(${sheep.$url.cdn(props.styles.bgImg)}) no-repeat top center / 100% auto`,
};
+ }
}
});
diff --git a/sheep/components/s-search-block/s-search-block.vue b/sheep/components/s-search-block/s-search-block.vue
index cef41bef..0e7bff78 100644
--- a/sheep/components/s-search-block/s-search-block.vue
+++ b/sheep/components/s-search-block/s-search-block.vue
@@ -25,15 +25,15 @@
{{ placeholder }}
-
-
-
+
+
+
{{ item }}
+ >
+ {{ item }}
@@ -162,9 +163,8 @@
}
}
- // TODO 后续需完善扫一扫功能
/**
- * 扫一扫
+ * 扫一扫功能
*/
function onScan() {
uni.scanCode({
@@ -177,23 +177,99 @@
fail: (err) => {
console.error(err);
uni.showToast({
- title: '扫码失败',
- icon: 'none',
+ title: err.errMsg === 'scanCode:fail cancel' ? '操作已取消' : '扫码失败',
+ icon: 'error',
});
},
});
}
/**
- * 展示扫码结果
- * @param text 扫码内容
+ * 检测是否为有效URL
+ * @param {string} str 待检测字符串
+ * @returns {boolean} 是否为有效URL
+ */
+ function isValidUrl(str) {
+ try {
+ // 微信环境专用验证方式
+ const url = str.trim();
+ return (
+ (url.startsWith('http://') || url.startsWith('https://') || url.startsWith('ftp://')) &&
+ // 简单长度验证
+ url.length >= 10
+ );
+ } catch {
+ return false;
+ }
+ }
+
+ /**
+ * 展示扫码结果并处理用户操作
+ * @param {string} text 扫码得到的内容
*/
function showScanResult(text) {
+ const isUrl = isValidUrl(text);
+ // 显示结果弹窗
uni.showModal({
title: '扫描结果',
content: text,
- showCancel: false,
- confirmText: '知道了',
+ confirmText: isUrl ? '访问' : '复制',
+ cancelText: '取消',
+ success: (res) => {
+ if (res.confirm) {
+ if (isUrl) {
+ handleUrl(text);
+ } else {
+ handleCopy(text);
+ }
+ }
+ },
+ });
+ }
+
+ /**
+ * 处理URL跳转
+ * @param {string} url 要访问的URL
+ */
+ function handleUrl(url) {
+ // 方案1:跳转到webview页面(推荐)
+ uni.navigateTo({
+ url: `/pages/public/webview?url=${encodeURIComponent(url)}`,
+ });
+
+ // 方案2:直接复制链接(备选方案)
+ /*
+ uni.setClipboardData({
+ data: url,
+ success: () => {
+ uni.showToast({
+ title: '链接已复制,请在浏览器打开',
+ icon: 'success',
+ });
+ },
+ });
+ */
+ }
+
+ /**
+ * 处理文本复制
+ * @param {string} text 要复制的文本
+ */
+ function handleCopy(text) {
+ uni.setClipboardData({
+ data: text,
+ success: () => {
+ uni.showToast({
+ title: '已复制到剪贴板',
+ icon: 'success',
+ });
+ },
+ fail: () => {
+ uni.showToast({
+ title: '复制失败,请重试',
+ icon: 'error',
+ });
+ },
});
}