diff --git a/admin/src/views/community/tag/index.vue b/admin/src/views/community/tag/index.vue index 84f4866..7df93c6 100644 --- a/admin/src/views/community/tag/index.vue +++ b/admin/src/views/community/tag/index.vue @@ -33,6 +33,12 @@ + + + @@ -83,6 +89,14 @@ + +
+ +
+ 建议上传正方形图标;未上传时用户端显示默认图标 +
+
+
@@ -125,6 +139,7 @@ const editFormRef = ref() const editData = reactive({ id: 0, name: '', + icon: '', sort: 0, is_hot: 0, status: 1 @@ -135,7 +150,7 @@ const editRules = { } const handleAdd = () => { - Object.assign(editData, { id: 0, name: '', sort: 0, is_hot: 0, status: 1 }) + Object.assign(editData, { id: 0, name: '', icon: '', sort: 0, is_hot: 0, status: 1 }) showEdit.value = true } @@ -143,6 +158,7 @@ const handleEdit = (row: any) => { Object.assign(editData, { id: row.id, name: row.name, + icon: row.icon || '', sort: row.sort, is_hot: row.is_hot, status: row.status diff --git a/server/app/adminapi/validate/community/CommunityTagValidate.php b/server/app/adminapi/validate/community/CommunityTagValidate.php index 3cbcb03..d588c29 100644 --- a/server/app/adminapi/validate/community/CommunityTagValidate.php +++ b/server/app/adminapi/validate/community/CommunityTagValidate.php @@ -10,12 +10,14 @@ class CommunityTagValidate extends BaseValidate protected $rule = [ 'id' => 'require|checkTag', 'name' => 'require|length:1,50', + 'icon' => 'max:500', ]; protected $message = [ 'id.require' => '标签id不能为空', 'name.require' => '标签名称不能为空', 'name.length' => '标签名称长度须在1-50位字符', + 'icon.max' => '标签图标地址不能超过500个字符', ]; public function sceneAdd() diff --git a/server/app/common/model/community/CommunityTag.php b/server/app/common/model/community/CommunityTag.php index effabc7..9b30fd1 100644 --- a/server/app/common/model/community/CommunityTag.php +++ b/server/app/common/model/community/CommunityTag.php @@ -3,8 +3,19 @@ namespace app\common\model\community; use app\common\model\BaseModel; +use app\common\service\FileService; class CommunityTag extends BaseModel { protected $name = 'community_tag'; + + public function getIconAttr($value): string + { + return trim((string) $value) ? FileService::getFileUrl((string) $value) : ''; + } + + public function setIconAttr($value): string + { + return trim((string) $value) ? FileService::setFileUrl($value) : ''; + } } diff --git a/uniapp/src/pages/community/community.vue b/uniapp/src/pages/community/community.vue index 77ead12..4cc4dee 100644 --- a/uniapp/src/pages/community/community.vue +++ b/uniapp/src/pages/community/community.vue @@ -33,7 +33,8 @@ - {{ tag.theme.icon }} + + {{ tag.theme.icon }} {{ tag.name }} @@ -129,6 +130,7 @@ const TOPIC_THEMES = [ const displayTags = computed(() => { return tagList.value.map((tag, index) => ({ ...tag, + icon: typeof tag.icon === 'string' ? tag.icon.trim() : '', theme: TOPIC_THEMES[index % TOPIC_THEMES.length] })) }) @@ -546,6 +548,12 @@ onShow(() => { line-height: 1; } + &__icon-image { + width: 32rpx; + height: 32rpx; + flex-shrink: 0; + } + &--active { border-color: #1468f5; color: #1468f5;