feat:编辑页添加按钮简化为添加,字数限制4字,标签不换行,接入自定义弹窗
This commit is contained in:
@@ -143,7 +143,7 @@
|
|||||||
:class="{ active: form.personalityTags.includes(tag) }"
|
:class="{ active: form.personalityTags.includes(tag) }"
|
||||||
@click="toggleList(form.personalityTags, tag, 5)"
|
@click="toggleList(form.personalityTags, tag, 5)"
|
||||||
>{{ tag }}</text>
|
>{{ tag }}</text>
|
||||||
<text class="tag-choice dashed" @click="addCustomTag('personality')">+ 添加标签</text>
|
<text class="tag-choice dashed" @click="addCustomTag('personality')">+ 添加</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@
|
|||||||
:class="{ active: form.hobbies.includes(tag) }"
|
:class="{ active: form.hobbies.includes(tag) }"
|
||||||
@click="toggleList(form.hobbies, tag, 5)"
|
@click="toggleList(form.hobbies, tag, 5)"
|
||||||
>{{ tag }}</text>
|
>{{ tag }}</text>
|
||||||
<text class="tag-choice dashed" @click="addCustomTag('hobby')">+ 添加兴趣</text>
|
<text class="tag-choice dashed" @click="addCustomTag('hobby')">+ 添加</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@@ -183,6 +183,17 @@
|
|||||||
<text class="bio-count">{{ (form.future.ideal || '').length }}/200</text>
|
<text class="bio-count">{{ (form.future.ideal || '').length }}/200</text>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</scroll-view>
|
||||||
|
|
||||||
|
<TagDialog
|
||||||
|
v-model="dialogInput"
|
||||||
|
v-model:visible="dialogVisible"
|
||||||
|
:mode="dialogMode"
|
||||||
|
:title="dialogTitle"
|
||||||
|
:placeholder="dialogPlaceholder"
|
||||||
|
:content="dialogContent"
|
||||||
|
@confirm="onDialogConfirm"
|
||||||
|
@cancel="onDialogCancel"
|
||||||
|
/>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -191,11 +202,19 @@ import { computed, onMounted, onUnmounted, reactive, ref } from 'vue'
|
|||||||
import { onShow } from '@dcloudio/uni-app'
|
import { onShow } from '@dcloudio/uni-app'
|
||||||
import { useAppStore } from '../../stores/app.js'
|
import { useAppStore } from '../../stores/app.js'
|
||||||
import { useMenuButtonSafeArea } from '../../composables/useMenuButtonSafeArea.js'
|
import { useMenuButtonSafeArea } from '../../composables/useMenuButtonSafeArea.js'
|
||||||
|
import TagDialog from '../../components/TagDialog.vue'
|
||||||
|
|
||||||
const store = useAppStore()
|
const store = useAppStore()
|
||||||
const { capsuleTopReservePx } = useMenuButtonSafeArea({ extraTopPx: 2 })
|
const { capsuleTopReservePx } = useMenuButtonSafeArea({ extraTopPx: 2 })
|
||||||
const isEdit = ref(false)
|
const isEdit = ref(false)
|
||||||
const saving = ref(false)
|
const saving = ref(false)
|
||||||
|
const dialogVisible = ref(false)
|
||||||
|
const dialogMode = ref('input')
|
||||||
|
const dialogTitle = ref('')
|
||||||
|
const dialogPlaceholder = ref('')
|
||||||
|
const dialogContent = ref('')
|
||||||
|
const dialogInput = ref('')
|
||||||
|
const dialogAction = ref(null)
|
||||||
const birthday = ref('')
|
const birthday = ref('')
|
||||||
const avatarLocal = ref('')
|
const avatarLocal = ref('')
|
||||||
const bioPlaceholder = '热爱阅读和旅行,喜欢用文字和镜头记录生活。\n相信真诚和努力能让世界变得更美好。'
|
const bioPlaceholder = '热爱阅读和旅行,喜欢用文字和镜头记录生活。\n相信真诚和努力能让世界变得更美好。'
|
||||||
@@ -408,44 +427,69 @@ const goTagManage = (type) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增自定义标签(性格标签 / 兴趣爱好通用)
|
* 打开添加标签弹窗
|
||||||
* @param {string} type 'personality' 或 'hobby'
|
* @param {string} type 'personality' 或 'hobby'
|
||||||
*/
|
*/
|
||||||
const addCustomTag = (type) => {
|
const addCustomTag = (type) => {
|
||||||
|
const isPersonality = type === 'personality'
|
||||||
|
dialogMode.value = 'input'
|
||||||
|
dialogTitle.value = isPersonality ? '添加性格标签' : '添加兴趣爱好'
|
||||||
|
dialogPlaceholder.value = '请输入标签(最多4个字)'
|
||||||
|
dialogInput.value = ''
|
||||||
|
dialogAction.value = { kind: 'add', type }
|
||||||
|
dialogVisible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理添加标签的实际逻辑(字数限制 4 字)
|
||||||
|
*/
|
||||||
|
const handleAddTag = (type, rawValue) => {
|
||||||
|
const value = String(rawValue || '').trim()
|
||||||
const isPersonality = type === 'personality'
|
const isPersonality = type === 'personality'
|
||||||
const library = isPersonality ? form.personalityTagLibrary : form.hobbyLibrary
|
const library = isPersonality ? form.personalityTagLibrary : form.hobbyLibrary
|
||||||
const selected = isPersonality ? form.personalityTags : form.hobbies
|
const selected = isPersonality ? form.personalityTags : form.hobbies
|
||||||
const title = isPersonality ? '添加性格标签' : '添加兴趣爱好'
|
|
||||||
|
|
||||||
uni.showModal({
|
if (!value) {
|
||||||
title,
|
uni.showToast({ title: '请输入标签内容', icon: 'none' })
|
||||||
editable: true,
|
return
|
||||||
placeholderText: '请输入标签(最多8个字符)',
|
}
|
||||||
success: (res) => {
|
if (value.length > 4) {
|
||||||
const value = String(res.content || '').trim()
|
uni.showToast({ title: '内容不能超过4个字', icon: 'none' })
|
||||||
if (!res.confirm) return
|
return
|
||||||
if (!value) {
|
}
|
||||||
uni.showToast({ title: '请输入标签内容', icon: 'none' })
|
if (library.includes(value)) {
|
||||||
return
|
uni.showToast({ title: '标签已存在', icon: 'none' })
|
||||||
}
|
return
|
||||||
if (value.length > 8) {
|
}
|
||||||
uni.showToast({ title: '标签最多8个字符', icon: 'none' })
|
// 新标签插入到库数组最前面
|
||||||
return
|
library.unshift(value)
|
||||||
}
|
// 若已选未满 5 个,自动加入已选;否则仅提示
|
||||||
if (library.includes(value)) {
|
if (selected.length >= 5) {
|
||||||
uni.showToast({ title: '标签已存在', icon: 'none' })
|
uni.showToast({ title: '已达上限,仅加入标签库', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 新标签插入到库数组最前面
|
selected.push(value)
|
||||||
library.unshift(value)
|
}
|
||||||
// 若已选未满 5 个,自动加入已选;否则仅提示
|
|
||||||
if (selected.length >= 5) {
|
/**
|
||||||
uni.showToast({ title: '已达上限,仅加入标签库', icon: 'none' })
|
* 弹窗确认回调
|
||||||
return
|
*/
|
||||||
}
|
const onDialogConfirm = (value) => {
|
||||||
selected.push(value)
|
const action = dialogAction.value
|
||||||
}
|
if (!action) return
|
||||||
})
|
if (action.kind === 'add') {
|
||||||
|
handleAddTag(action.type, value)
|
||||||
|
}
|
||||||
|
dialogAction.value = null
|
||||||
|
dialogVisible.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 弹窗取消回调
|
||||||
|
*/
|
||||||
|
const onDialogCancel = () => {
|
||||||
|
dialogAction.value = null
|
||||||
|
dialogVisible.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveProfile = async () => {
|
const saveProfile = async () => {
|
||||||
@@ -1008,6 +1052,9 @@ onMounted(async () => {
|
|||||||
.tag-choice {
|
.tag-choice {
|
||||||
height: 40rpx;
|
height: 40rpx;
|
||||||
font-size: 21rpx;
|
font-size: 21rpx;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tag-choice.dashed {
|
.tag-choice.dashed {
|
||||||
|
|||||||
Reference in New Issue
Block a user