Skip to content

Commit

Permalink
feat: bm 的 标签搜索
Browse files Browse the repository at this point in the history
fixed #14
  • Loading branch information
glennliao committed Aug 19, 2023
1 parent 3206dde commit cac77bb
Show file tree
Hide file tree
Showing 13 changed files with 269 additions and 101 deletions.
5 changes: 5 additions & 0 deletions app/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ func AccessCondition(ctx context.Context, req config.ConditionReq, where *config

}

if _, exists := req.NodeReq["tags"]; exists {
where.AddRaw("json_extract(tags,'$') like ?", "%"+gconv.String(req.NodeReq["tags"])+"%")
delete(req.NodeReq, "tags")
}

where.AddRaw("drop_at is null and group_id in (select group_id from group_user where user_id = ? )", []string{user.UserId})
} else {
where.AddRaw("drop_at is null and group_id in (select group_id from group_user where user_id = ? )", []string{user.UserId})
Expand Down
37 changes: 37 additions & 0 deletions app/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func initFunc(a *apijson.ApiJson) {

a.Config().Functions.Bind("latestVersion", latestVersion())
a.Config().Functions.Bind("noteTags", noteTags())
a.Config().Functions.Bind("bmTags", bmTags())
a.Config().Functions.Bind("cateBmNum", cateBmNum())
a.Config().Functions.Bind("fetchMetaBatch", fetchMetaBatchFunc())
}
Expand Down Expand Up @@ -239,6 +240,42 @@ func noteTags() config.Func {
}
}

func bmTags() config.Func {
return config.Func{
ParamList: nil,
Batch: false,
Handler: func(ctx context.Context, param model.FuncParam) (res any, err error) {
user, _ := ctx.Value(UserIdKey).(*CurrentUser)

type TagRecord struct {
Tags []string
}

var list []TagRecord

var tagSet gset.StrSet

err = g.DB().Model("bookmark").Where("group_id", user.UserId).Scan(&list)
if err != nil {
return nil, err
}

if len(list) == 0 {
return []string{}, nil
}

for _, record := range list {
for _, tag := range record.Tags {
tagSet.Add(tag)
}

}

return tagSet.Slice(), err
},
}
}

func cateBmNum() config.Func {
return config.Func{
ParamList: nil,
Expand Down
6 changes: 4 additions & 2 deletions app/inits/_access.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"url": ["%$%","="],
"q": ["="],
"group_id": ["="],
"bm_id": ["="]
"bm_id": ["="],
"tags": ["="]
},
"out": {
"bm_id": "",
Expand All @@ -27,7 +28,8 @@
"title": "",
"remark": "",
"description": "",
"icon": ""
"icon": "",
"tags": ""
}
}
},
Expand Down
28 changes: 21 additions & 7 deletions app/inits/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ type (
Icon string `ddl:"size:256;comment:图标地址"`
Description string `ddl:"size:2048;comment:书签描述(来自网站)"`
Remark string `ddl:"size:1024;comment:书签描述(来自用户)"`
Tags string `ddl:"type:json;comment:标签"`
EncodeKey string `ddl:"size:128;comment:加密key"`
IsPublic uint8 `ddl:"comment:是否公开"`
CateId string `ddl:"size:32;comment:分类id"`
GroupId string `ddl:"size:32;comment:群组id"`
FromGroupId string `ddl:"size:32;comment:分享来源"`
DropAt *time.Time `ddl:"comment:放置到回收站时间"`
Sorts int32

Created
Updated
Deleted
Expand Down Expand Up @@ -102,27 +104,38 @@ type (
type (
Note struct {
tablesync.TableMeta `charset:"utf8mb4" comment:"笔记"`
Id uint64 `ddl:"primaryKey"`
GroupId string `ddl:"size:32;comment:groupId"`
NoteId string `ddl:"size:32;comment:@rowKey noteId"`
Content string `ddl:"type:json;comment:内容"`
Tags string `ddl:"type:json;comment:标签"`
IsPublic uint8 `ddl:"comment:是否公开"`
EncodeKey string `ddl:"size:128;comment:加密key"`
DropAt *time.Time `ddl:"comment:放置到回收站时间"`
Created
Updated
Deleted
}

NoteHistory struct {
tablesync.TableMeta `charset:"utf8mb4" comment:"笔记历史"`
Id uint64 `ddl:"primaryKey"`
GroupId string `ddl:"size:32;comment:groupId"`
NoteId string `ddl:"size:32;comment:@rowKey noteId"`
Content string `ddl:"type:json;comment:内容"`
Tags string `ddl:"type:json;comment:标签"`
IsPublic uint8 `ddl:"comment:是否公开"`
EncodeKey string `ddl:"size:128;comment:加密key"`
Created
Updated
Deleted
}
)

type (
Tag struct {
tablesync.TableMeta `charset:"utf8mb4" comment:"标签"`
Id uint64 `ddl:"primaryKey"`
Tag string `ddl:"size:32;comment:标签内容"`
Created
}
)

type (
Config struct {
tablesync.TableMeta `charset:"utf8mb4" comment:"设置表"`
Id uint64 `ddl:"primaryKey"`
Expand All @@ -148,8 +161,9 @@ func Tables() []tablesync.Table {
User{},

Note{},
Tag{},
NoteHistory{},

Tag{},
Config{},
}
}
8 changes: 8 additions & 0 deletions ui/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ export {}

declare module 'vue' {
export interface GlobalComponents {
ABadge: typeof import('ant-design-vue/es')['Badge']
ALayout: typeof import('ant-design-vue/es')['Layout']
ALayoutContent: typeof import('ant-design-vue/es')['LayoutContent']
ALayoutFooter: typeof import('ant-design-vue/es')['LayoutFooter']
ALayoutSider: typeof import('ant-design-vue/es')['LayoutSider']
AMenu: typeof import('ant-design-vue/es')['Menu']
AMenuItem: typeof import('ant-design-vue/es')['MenuItem']
ASubMenu: typeof import('ant-design-vue/es')['SubMenu']
GroupPanel: typeof import('./src/components/GroupPanel/index.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
Expand Down
2 changes: 1 addition & 1 deletion ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ watch(() => route.path, (v) => {
selectedKeys.value = [path]
})

if (key == '/') {
if (key === '/') {
key = '/bookmark'
}

Expand Down
4 changes: 2 additions & 2 deletions ui/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
Breadcrumb,
Badge,
Tag, Avatar, Segmented,
Layout, Row, Col,Pagination
Layout, Row, Col,Pagination,Select,
} from 'ant-design-vue'
import 'ant-design-vue/dist/reset.css'

Expand All @@ -43,5 +43,5 @@ app.use(Drawer).use(Button).use(Tree)
.use(Card).use(TreeSelect).use(Popover)
.use(Tabs).use(FloatButton).use(Empty).use(Upload).use(Breadcrumb)
.use(Badge).use(Tag).use(Avatar).use(Layout).use(Segmented)
.use(Row).use(Col).use(Pagination)
.use(Row).use(Col).use(Pagination).use(Select)
app.mount('#app')
71 changes: 39 additions & 32 deletions ui/src/views/bookmark/components/Bookmark.vue
Original file line number Diff line number Diff line change
@@ -1,46 +1,53 @@
<template>
<div>
<div class="bookmark cursor-pointer rounded shadow p-1 items-baseline" :class="{'simple':simple}"
:style="{'width':width}"
@click="toURL(item)">
<div class="flex">
<div>
<img v-lazy="item.icon" v-if="item.icon && item.icon !== ''" class="logo"/>
<div v-else class="logo text-center text-white" :style="{'background': colorByURL(item.url)}">{{
item.title[0]
}}
<a-popover >
<template #content>
<div style="width:300px">
<div class="font-bold truncate ...">
{{item.title}}
</div>
<div style="font-size: 13px;overflow-wrap: anywhere" class="bg-blue-100 rounded p-1 my-2" >
{{item.url}}
</div>
<div class="bg-gray-100 p-1 rounded" style="font-size: 12px">{{ item.description }}</div>

<div class="py-2">
<a-tag v-for="tag in item.tags" :key="tag" >{{tag}}</a-tag>
</div>
</div>
<div class="ml-1 title truncate ...">
{{ item.title }}
<div class="flex mt-2 justify-end ">
<a-button size="small" ghost type="primary" @click="edit">Edit</a-button>
<a-button size="small" ghost class="ml-2" danger @click="drop">Del</a-button>
</div>
</div>
<div v-if="!simple" class="remark ..." style="height: 58px; margin-top: 4px">
{{ item.remark || item.description }}
</div>
<div v-if="!simple" class="flex justify-end" style="height: 12px;line-height: 12px;color:#777" @click.stop="void">
<a-popover >
<template #content>
<div style="width:300px">
<div class="font-bold truncate ...">
{{item.title}}
</div>
<div style="font-size: 13px;overflow-wrap: anywhere" class="bg-blue-100 rounded p-1 my-2" >
{{item.url}}
</template>
<div>
<div class="bookmark cursor-pointer rounded shadow p-1 items-baseline" :class="{'simple':simple}"
:style="{'width':width}"
@click="toURL(item)">
<div class="flex">
<div>
<img v-lazy="item.icon" v-if="item.icon && item.icon !== ''" class="logo"/>
<div v-else class="logo text-center text-white" :style="{'background': colorByURL(item.url)}">{{
item.title[0]
}}
</div>
<div class="bg-gray-100 p-1 rounded" style="font-size: 12px">{{ item.description }}</div>
</div>
<div class="flex mt-2 justify-end ">
<a-button size="small" ghost type="primary" @click="edit">Edit</a-button>
<a-button size="small" ghost class="ml-2" danger @click="drop">Del</a-button>
<div class="ml-1 title truncate ...">
{{ item.title }}
</div>
</template>
<div>
</div>
<div v-if="!simple" class="remark ..." style="height: 58px; margin-top: 4px">
{{ item.remark || item.description }}
</div>
<div v-if="!simple" class="flex justify-end" style="height: 12px;line-height: 12px;color:#777" @click.stop="void">
...
</div>
</a-popover>
</div>

</div>
</div>
</a-popover>


</div>

</template>
Expand Down
35 changes: 34 additions & 1 deletion ui/src/views/bookmark/components/BookmarkEditModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@
<a-form-item label="备注" v-bind="validateInfos.remark">
<a-textarea :rows="3" v-model:value="info.remark" type="textarea"/>
</a-form-item>
<a-form-item label="标签" v-bind="validateInfos.tags">
<a-select
v-model:value="info.tags"
mode="tags"
style="width: 100%"
placeholder="Tags"
:options="tagsOptions"
@change="handleChange"
></a-select>
</a-form-item>
</div>
</a-form>
</div>
Expand Down Expand Up @@ -142,7 +152,8 @@ const info = ref({
cateId: '',
title: '',
groupId: '',
url: ''
url: '',
tags:[]
})

const hasFetchURL = ref(false)
Expand Down Expand Up @@ -228,6 +239,7 @@ function onSearch () {
info.value.title = data.meta.title
info.value.icon = data.meta.icon
info.value.description = data.meta.description
info.value.tags = []
}).catch(() => {
Modal.confirm({
title: '操作确认',
Expand Down Expand Up @@ -308,6 +320,7 @@ function open (_info = {}) {

hasFetchURL.value = _info.bmId
loadCate()
loadTagList()
}

function loadCate () {
Expand Down Expand Up @@ -356,6 +369,26 @@ function add () {

const saveBookJS = `javascript:window.open('${window.location.href.split('#')[0]}#/?url='+window.location,'_blank')`


const tagsOptions = ref([])

function loadTagList() {
apiJson.get({
'tags()': 'bmTags()'
}).then(data => {
tagsOptions.value = data.tags.map(item=>{
return {
value:item
}
})
})
}

function handleChange(e){
console.log(e)
}


defineExpose({
open
})
Expand Down
Loading

0 comments on commit cac77bb

Please sign in to comment.