修复h5记事本不显示问题
This commit is contained in:
@@ -1,30 +1,107 @@
|
||||
<template>
|
||||
<web-view :src="webviewSrc" @message="onMessage" />
|
||||
<view class="geetest-container">
|
||||
<web-view :src="webviewSrc" @message="onMessage" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { onLoad, onUnload } from '@dcloudio/uni-app'
|
||||
|
||||
const webviewSrc = ref('')
|
||||
let eventChannel = null
|
||||
let settled = false
|
||||
let pollTimer = null
|
||||
|
||||
function unwrapMessage(e) {
|
||||
const raw = e?.detail?.data
|
||||
const first = Array.isArray(raw) ? raw[0] : raw
|
||||
if (!first) return {}
|
||||
if (first.type) return first
|
||||
if (first.data && first.data.type) return first.data
|
||||
return first
|
||||
}
|
||||
|
||||
function finish(payload) {
|
||||
if (settled || !payload || !payload.type) return
|
||||
settled = true
|
||||
if (pollTimer) {
|
||||
clearInterval(pollTimer)
|
||||
pollTimer = null
|
||||
}
|
||||
try {
|
||||
if (typeof plus !== 'undefined' && plus.storage) {
|
||||
plus.storage.removeItem('__geetest_payload__')
|
||||
plus.storage.removeItem('__geetest_captcha_id__')
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
if (payload.type === 'success') {
|
||||
eventChannel?.emit('geetestSuccess', payload.result || {})
|
||||
} else {
|
||||
eventChannel?.emit('geetestFail', payload.msg || '人机验证未通过')
|
||||
}
|
||||
uni.navigateBack({
|
||||
delta: 1,
|
||||
fail() {}
|
||||
})
|
||||
}
|
||||
|
||||
function onMessage(e) {
|
||||
finish(unwrapMessage(e))
|
||||
}
|
||||
|
||||
onLoad((query) => {
|
||||
const captchaId = decodeURIComponent(query.captchaId || '')
|
||||
try {
|
||||
if (typeof plus !== 'undefined' && plus.storage) {
|
||||
plus.storage.setItem('__geetest_captcha_id__', captchaId)
|
||||
plus.storage.removeItem('__geetest_payload__')
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
webviewSrc.value = `/static/html/geetest-captcha.html?captchaId=${encodeURIComponent(captchaId)}`
|
||||
const pages = getCurrentPages()
|
||||
const page = pages[pages.length - 1]
|
||||
eventChannel = page.getOpenerEventChannel?.()
|
||||
|
||||
const pagesList = getCurrentPages()
|
||||
const curPage = pagesList[pagesList.length - 1]
|
||||
eventChannel = curPage?.getOpenerEventChannel?.()
|
||||
|
||||
// 轮询 plus.storage 结果(每 60ms 检查一次)
|
||||
pollTimer = setInterval(() => {
|
||||
if (settled) return
|
||||
try {
|
||||
if (typeof plus !== 'undefined' && plus.storage) {
|
||||
const raw = plus.storage.getItem('__geetest_payload__')
|
||||
if (raw) {
|
||||
const p = JSON.parse(raw)
|
||||
if (p) finish(p)
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
}, 60)
|
||||
})
|
||||
|
||||
function onMessage(e) {
|
||||
const payload = (e.detail && e.detail.data && e.detail.data[0]) || {}
|
||||
if (payload.type === 'success') {
|
||||
eventChannel?.emit('geetestSuccess', payload.result || {})
|
||||
uni.navigateBack()
|
||||
return
|
||||
onUnload(() => {
|
||||
if (pollTimer) {
|
||||
clearInterval(pollTimer)
|
||||
pollTimer = null
|
||||
}
|
||||
eventChannel?.emit('geetestFail', payload.msg || '人机验证未通过')
|
||||
uni.navigateBack()
|
||||
}
|
||||
try {
|
||||
if (typeof plus !== 'undefined' && plus.storage) {
|
||||
plus.storage.removeItem('__geetest_payload__')
|
||||
plus.storage.removeItem('__geetest_captcha_id__')
|
||||
}
|
||||
} catch (e) {}
|
||||
if (!settled) {
|
||||
eventChannel?.emit('geetestFail', '已取消人机验证')
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.geetest-container {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
background: #f5f7fa;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -371,9 +371,11 @@ async function handleLogin() {
|
||||
if (ok) navigateAfterLogin()
|
||||
} catch (err) {
|
||||
const msg = err?.message || '人机验证失败'
|
||||
if (msg !== '人机验证未通过') {
|
||||
if (msg !== '人机验证未通过' && msg !== '已取消人机验证') {
|
||||
uni.showToast({ title: msg, icon: 'none' })
|
||||
}
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ import { ref, reactive } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { getNote, createNote, updateNote, deleteNote } from '@/api/note.js'
|
||||
import { formatDate } from '@/utils/date.js'
|
||||
import { injectTableInlineStyles } from '@/utils/table-editor.js'
|
||||
import NoteRichEditor from '@/components/NoteRichEditor.vue'
|
||||
|
||||
const noteId = ref('')
|
||||
@@ -81,7 +82,7 @@ async function loadNote(id) {
|
||||
return
|
||||
}
|
||||
form.title = note.title
|
||||
form.content = note.content
|
||||
form.content = injectTableInlineStyles(note.content || '')
|
||||
form.pinned = !!note.pinned
|
||||
meta.updatedAt = note.updatedAt
|
||||
} catch (e) {
|
||||
@@ -97,16 +98,17 @@ async function onSave() {
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
const formattedContent = injectTableInlineStyles(form.content)
|
||||
if (noteId.value) {
|
||||
await updateNote(noteId.value, {
|
||||
title: form.title,
|
||||
content: form.content,
|
||||
content: formattedContent,
|
||||
pinned: form.pinned
|
||||
})
|
||||
} else {
|
||||
await createNote({
|
||||
title: form.title,
|
||||
content: form.content,
|
||||
content: formattedContent,
|
||||
pinned: form.pinned
|
||||
})
|
||||
}
|
||||
@@ -191,14 +193,16 @@ function onDelete() {
|
||||
padding: 24rpx 28rpx 0 28rpx;
|
||||
overflow: hidden;
|
||||
border-top: 1rpx solid $color-divider;
|
||||
min-height: 520rpx;
|
||||
}
|
||||
|
||||
.note-editor {
|
||||
width: 100%;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
min-height: 440rpx;
|
||||
box-sizing: border-box;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: #f5f7fa;
|
||||
border-radius: 12rpx;
|
||||
padding: 20rpx;
|
||||
|
||||
Reference in New Issue
Block a user