mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-11-13 22:11:42 +08:00
feat: 新增友链相关组件与优化投票页面
1. 新增友链底部悬浮操作组件uh-links-actions 2. 新增站点友链信息弹窗组件uh-links-site-info 3. 新增站点友链申请表单组件uh-links-site-apply 4. 新增小程序友链信息弹窗组件uh-links-mini-info 5. 优化投票页面:替换提示文案、添加插件检测回调、新增防抖sleep工具、调整样式与交互细节
This commit is contained in:
@@ -0,0 +1,231 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 友链申请表单弹窗(站点版,源自旧页面 pages-blog/submit-link)
|
||||
* 参考小程序申请弹窗 uh-links-mini-apply 的封装方式(uh-glass-popup bottom + 表单 + 提交)
|
||||
* 提交后等待站长审核,通过后展示在「站点」列表中
|
||||
*/
|
||||
import { ref, watch } from 'vue'
|
||||
import { submitLink } from '@/api/uni-halo'
|
||||
import type { ISubmitLinkForm } from '@/api/types/uni-halo'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
show?: boolean
|
||||
}>(), {
|
||||
show: false,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'on-close', data: { isSubmit: boolean, refresh: boolean }): void
|
||||
}>()
|
||||
|
||||
const isShow = ref(false)
|
||||
|
||||
interface IApplyForm {
|
||||
name: string
|
||||
url: string
|
||||
logo: string
|
||||
linkPageUrl: string
|
||||
email: string
|
||||
rssUrl: string
|
||||
description: string
|
||||
}
|
||||
|
||||
const form = ref<IApplyForm>({
|
||||
name: '',
|
||||
url: '',
|
||||
logo: '',
|
||||
linkPageUrl: '',
|
||||
email: '',
|
||||
rssUrl: '',
|
||||
description: '',
|
||||
})
|
||||
|
||||
const submitting = ref(false)
|
||||
|
||||
function handleResetForm() {
|
||||
form.value = {
|
||||
name: '',
|
||||
url: '',
|
||||
logo: '',
|
||||
linkPageUrl: '',
|
||||
email: '',
|
||||
rssUrl: '',
|
||||
description: '',
|
||||
}
|
||||
}
|
||||
|
||||
function checkIsUrl(url: string): boolean {
|
||||
return /^https?:\/\//i.test(url)
|
||||
}
|
||||
|
||||
function checkIsEmail(email: string): boolean {
|
||||
return /^[\w.-]+@[\w-]+(?:\.[\w-]+)+$/.test(email)
|
||||
}
|
||||
|
||||
/** 提交校验 */
|
||||
function validateForm(): boolean {
|
||||
if (!form.value.name.trim()) {
|
||||
uni.showToast({ icon: 'none', title: '请输入网站名称!' })
|
||||
return false
|
||||
}
|
||||
if (!checkIsUrl(form.value.url)) {
|
||||
uni.showToast({ icon: 'none', title: '请输入正确的网站地址!' })
|
||||
return false
|
||||
}
|
||||
if (form.value.logo.trim() && !checkIsUrl(form.value.logo.trim())) {
|
||||
uni.showToast({ icon: 'none', title: '请输入正确的Logo地址!' })
|
||||
return false
|
||||
}
|
||||
if (form.value.email.trim() && !checkIsEmail(form.value.email.trim())) {
|
||||
uni.showToast({ icon: 'none', title: '请输入正确的邮箱地址!' })
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/** 提交申请 */
|
||||
async function handleSubmit() {
|
||||
if (!validateForm())
|
||||
return
|
||||
|
||||
submitting.value = true
|
||||
uni.showLoading({ title: '正在提交...' })
|
||||
try {
|
||||
const payload: ISubmitLinkForm = {
|
||||
name: form.value.name.trim(),
|
||||
url: form.value.url.trim(),
|
||||
logo: form.value.logo.trim() || undefined,
|
||||
linkPageUrl: form.value.linkPageUrl.trim() || undefined,
|
||||
email: form.value.email.trim() || undefined,
|
||||
rssUrl: form.value.rssUrl.trim() || undefined,
|
||||
description: form.value.description.trim() || undefined,
|
||||
}
|
||||
const res = await submitLink(payload)
|
||||
const msg = res.data?.msg || res.data?.message || res.message || '提交成功'
|
||||
uni.showToast({ icon: 'none', title: msg })
|
||||
if (res.code === 200 || res.code === undefined) {
|
||||
handleClose(true)
|
||||
handleResetForm()
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.error('友链申请提交失败', err)
|
||||
uni.showToast({ icon: 'none', title: '提交失败,请稍后重试!' })
|
||||
}
|
||||
finally {
|
||||
submitting.value = false
|
||||
uni.hideLoading()
|
||||
}
|
||||
}
|
||||
|
||||
function handleOnChange(isOpen: boolean) {
|
||||
isShow.value = isOpen
|
||||
if (!isOpen)
|
||||
emit('on-close', { isSubmit: false, refresh: false })
|
||||
}
|
||||
|
||||
function handleClose(refresh = false) {
|
||||
isShow.value = false
|
||||
emit('on-close', { isSubmit: true, refresh })
|
||||
}
|
||||
|
||||
watch(() => props.show, (val) => {
|
||||
if (!val)
|
||||
return
|
||||
isShow.value = true
|
||||
handleResetForm()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<uh-glass-popup
|
||||
v-model="isShow" :z-index="100" position="bottom"
|
||||
custom-class="!border rounded-xl" @close="handleClose(false)"
|
||||
>
|
||||
<view class="relative mb-4 box-border w-full flex items-center justify-around px-4 pt-4">
|
||||
<view class="w-full flex flex-col gap-y-1">
|
||||
<text class="text-md font-bold">申请友链</text>
|
||||
<text class="text-xs text-gray-500">提交后等待站长审核,通过后展示在「站点」列表中</text>
|
||||
</view>
|
||||
<view
|
||||
class="uh-global-card-glass absolute right-4 top-4 h-6 w-6 border rounded-lg text-center shadow-none"
|
||||
@click="handleClose(false)"
|
||||
>
|
||||
<wd-icon name="close" size="32rpx" class="text-gray-500" />
|
||||
</view>
|
||||
</view>
|
||||
<scroll-view :scroll-y="true" :show-scrollbar="false" class="box-border max-h-[60vh] p-4 pt-0">
|
||||
<view class="mb-5 flex items-center">
|
||||
<text class="label w-[140rpx] shrink-0 text-sm text-[#666]">名称 *</text>
|
||||
<input
|
||||
v-model="form.name"
|
||||
class="uh-global-card-glass h-9 flex-1 border rounded-xl px-4 text-sm shadow-none"
|
||||
placeholder="请输入网站名称"
|
||||
>
|
||||
</view>
|
||||
|
||||
<view class="mb-5 flex items-center">
|
||||
<text class="label w-[140rpx] shrink-0 text-sm text-[#666]">网址 *</text>
|
||||
<input
|
||||
v-model="form.url"
|
||||
class="uh-global-card-glass h-9 flex-1 border rounded-xl px-4 text-sm shadow-none"
|
||||
placeholder="请输入网站地址"
|
||||
>
|
||||
</view>
|
||||
|
||||
<view class="mb-5 flex items-center">
|
||||
<text class="label w-[140rpx] shrink-0 text-sm text-[#666]">Logo</text>
|
||||
<input
|
||||
v-model="form.logo"
|
||||
class="uh-global-card-glass h-9 flex-1 border rounded-xl px-4 text-sm shadow-none"
|
||||
placeholder="请输入网站Logo(选填)"
|
||||
>
|
||||
</view>
|
||||
|
||||
<view class="mb-5 flex items-center">
|
||||
<text class="label w-[140rpx] shrink-0 text-sm text-[#666]">邮箱</text>
|
||||
<input
|
||||
v-model="form.email"
|
||||
class="uh-global-card-glass h-9 flex-1 border rounded-xl px-4 text-sm shadow-none"
|
||||
placeholder="请输入邮箱(选填)"
|
||||
>
|
||||
</view>
|
||||
|
||||
<view class="mb-5 flex items-center">
|
||||
<text class="label w-[140rpx] shrink-0 text-sm text-[#666]">友链页面</text>
|
||||
<input
|
||||
v-model="form.linkPageUrl"
|
||||
class="uh-global-card-glass h-9 flex-1 border rounded-xl px-4 text-sm shadow-none"
|
||||
placeholder="贵站友情链接页面地址(选填)"
|
||||
>
|
||||
</view>
|
||||
<view class="mb-2 pl-[140rpx] text-xs text-gray-400 -mt-3">
|
||||
(即包含本站链接的页面)
|
||||
</view>
|
||||
|
||||
<view class="mb-5 flex items-center">
|
||||
<text class="label w-[140rpx] shrink-0 text-sm text-[#666]">RSS地址</text>
|
||||
<input
|
||||
v-model="form.rssUrl"
|
||||
class="uh-global-card-glass h-9 flex-1 border rounded-xl px-4 text-sm shadow-none"
|
||||
placeholder="用于抓取文章(选填)"
|
||||
>
|
||||
</view>
|
||||
|
||||
<view class="mb-5">
|
||||
<text class="label mb-2 block text-sm text-[#666]">网站描述</text>
|
||||
<textarea
|
||||
v-model="form.description"
|
||||
class="uh-global-card-glass box-border h-24 w-full flex-1 border rounded-xl p-3 text-sm shadow-none"
|
||||
placeholder="请输入网站描述,不超过30字符(选填)" :maxlength="30"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="my-6">
|
||||
<uh-button custom-class="py-2 !rounded-xl" :loading="submitting" @click="handleSubmit">
|
||||
提交申请
|
||||
</uh-button>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</uh-glass-popup>
|
||||
</template>
|
||||
Reference in New Issue
Block a user