Skip to content

Commit

Permalink
feat:优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
gzydong committed Dec 27, 2023
1 parent 9fc7686 commit 6771585
Show file tree
Hide file tree
Showing 26 changed files with 324 additions and 160 deletions.
2 changes: 1 addition & 1 deletion src/assets/css/define/theme.less
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ html[theme-mode='dark'] {
--im-active-bg-color: #2c2c32;
--im-hover-bg-color: #2c2c32;

--im-broadside-box-shadow: #1c1717;
--im-broadside-box-shadow: #201b1b;

// note
--im-note-list-bg-color: #2c2c32;
Expand Down
File renamed without changes
Binary file removed src/assets/image/banners.webp
Binary file not shown.
Binary file removed src/assets/image/default-avatar.jpg
Binary file not shown.
Binary file removed src/assets/image/iTab-ympj97.png
Binary file not shown.
1 change: 0 additions & 1 deletion src/assets/image/tes.svg

This file was deleted.

File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion src/constant/message.js → src/constant/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,4 @@ export const ForwardableMessageType = [
ChatMsgTypeFile,
ChatMsgTypeLocation,
ChatMsgTypeCard
// ChatMsgTypeForward
]
File renamed without changes.
8 changes: 0 additions & 8 deletions src/directive/copy.js

This file was deleted.

4 changes: 0 additions & 4 deletions src/directive/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import dropsize from './dropsize'
import focus from './focus'
// import paste from './paste'
import loading from './loading'
// import copy from './copy'

const directives = {
dropsize,
focus,
// paste,
loading
// copy
}

export function setupDirective(app: any) {
Expand Down
8 changes: 0 additions & 8 deletions src/directive/paste.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/layout/MainLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const settingsStore = useSettingsStore()
.container {
height: 100vh;
width: 100vw;
background: url(@/assets/image/iTab-exSKJMg-_vI.jpeg);
background: url(@/assets/image/background.jpeg);
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
Expand Down
1 change: 0 additions & 1 deletion src/layout/SubViewLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ defineProps<{
a {
text-decoration: none;
// color: rgba(0, 0, 0, 0.65);
color: var(--im-text-color);
}
Expand Down
113 changes: 98 additions & 15 deletions src/store/modules/note.js → src/store/modules/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,78 @@ import {
ServeDeleteArticleTag
} from '@/api/article'

interface Tag {
id: number
tag_name: string
count: number
}

interface Class {
id: number
class_name: string
count: number
is_default: number
}

export interface NoteItem {
id: number
title: string
abstract: string
class_id: number
class_name: string
image: string
is_asterisk: number
status: number
tags_id: string
created_at: string
updated_at: string
}

export interface NoteFileItem {
id: number
created_at: string
original_name: string
size: number
suffix: string
}

interface NoteStoreState {
tags: Tag[]
class: Class[]
notes: {
loadStatus: number
params: {
page: number
keyword: string
find_type: number
cid: number
}
items: NoteItem[]
}
view: {
editorMode: string
loadId: number
loadStatus: number
detail: {
id: number
class_id: number
class_name: string
title: string
is_asterisk: number
status: number
tags: {
id: number
}[]
files: NoteFileItem[]
md_content: string
created_at: string
updated_at: string
}
}
}

export const useNoteStore = defineStore('note', {
state: () => {
state: (): NoteStoreState => {
return {
tags: [],
class: [],
Expand All @@ -34,7 +104,6 @@ export const useNoteStore = defineStore('note', {
status: 1,
tags: [],
files: [],
content: '',
md_content: '',
created_at: '',
class_name: ''
Expand All @@ -51,7 +120,7 @@ export const useNoteStore = defineStore('note', {
addNewNote(class_id = 0) {
this.view.detail = {
class_id: class_id,
content: '',
class_name: '',
created_at: '',
files: [],
id: 0,
Expand Down Expand Up @@ -102,14 +171,14 @@ export const useNoteStore = defineStore('note', {
})
},

updateNoteItem(id, params = {}) {
updateNoteItem(id: number, params = {}) {
const item = this.notes.items.find((item) => item.id == id)

item && Object.assign(item, params)
},

// 加载详情信息
loadDetail(id) {
loadDetail(id: number) {
this.view.loadId = id
this.view.loadStatus = 0

Expand All @@ -125,41 +194,50 @@ export const useNoteStore = defineStore('note', {
this.view.loadStatus = 1

data.class_name = ''

this.view.detail = data

let node = this.class.find((item) => {
const node = this.class.find((item) => {
return item.id == data.class_id
})

this.view.detail.class_name = node.class_name || ''
if (node) {
this.view.detail.class_name = node.class_name || ''
}
})
},

// 修改编辑模式
setEditorMode(value) {
setEditorMode(value: string) {
this.view.editorMode = value
},

// 修改收藏状态
setCollectionStatus(isTrue) {
setCollectionStatus(isTrue: boolean) {
this.view.detail.is_asterisk = isTrue ? 1 : 0
},

// 编辑分类
async editClass(class_id, class_name) {
async editClass(class_id: number, class_name: string) {
const res = await ServeEditArticleClass({ class_id, class_name })

if (res && res.code === 200) {
if (class_id === 0) {
this.class.unshift({ class_name, count: 0, id: res.data.id })
this.class.unshift({
id: res.data.id,
class_name,
count: 0,
is_default: 0
})
} else {
const item = this.class.find((item) => item.id === class_id)

item && Object.assign(item, { class_name })
}
}
},

async deleteClass(class_id) {
async deleteClass(class_id: number) {
const res = await ServeDeleteArticleClass({ class_id })

if (res && res.code == 200) {
Expand All @@ -174,20 +252,25 @@ export const useNoteStore = defineStore('note', {
},

// 编辑标签
async editTag(tag_id, tag_name) {
async editTag(tag_id: number, tag_name: string) {
const res = await ServeEditArticleTag({ tag_id, tag_name })

if (res && res.code === 200) {
if (tag_id === 0) {
this.tags.unshift({ tag_name, count: 0, id: res.data.id })
this.tags.unshift({
id: res.data.id,
tag_name,
count: 0
})
} else {
const item = this.tags.find((item) => item.id === tag_id)

item && Object.assign(item, { tag_name })
}
}
},

async deleteTag(tag_id) {
async deleteTag(tag_id: number) {
const res = await ServeDeleteArticleTag({ tag_id })

if (res && res.code == 200) {
Expand Down
10 changes: 5 additions & 5 deletions src/store/modules/settings.js → src/store/modules/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ export const useSettingsStore = defineStore('settings', {
}
},
actions: {
setPromptTone(value) {
setPromptTone(value: boolean) {
this.isPromptTone = value
storage.set('isPromptTone', value, null)
},
setKeyboard(value) {
setKeyboard(value: boolean) {
this.isKeyboard = value
storage.set('isKeyboard', value, null)
},
setFullScreen(value) {
setFullScreen(value: boolean) {
this.isFullScreen = value
storage.set('isFullScreen', value, null)
},
setDarkTheme(value) {
setDarkTheme(value: boolean) {
this.darkTheme = value
storage.set('darkTheme', value, null)
},
setNotify(value) {
setNotify(value: boolean) {
this.isNotify = value
storage.set('isNotify', value, null)
}
Expand Down
33 changes: 17 additions & 16 deletions src/store/modules/uploads.js → src/store/modules/uploads.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { defineStore } from 'pinia'

import { ServeFindFileSplitInfo, ServeFileSubareaUpload } from '@/api/upload'
import { ServeSendTalkFile } from '@/api/chat'

const message = window.window.$message
// @ts-ignore
const message = window.$message

// 处理拆分上传文件
function fileSlice(file, uploadId, eachSize) {
function fileSlice(file: File, uploadId: string, eachSize: number) {
const splitNum = Math.ceil(file.size / eachSize) // 分片总数
const items = []
const items: FormData[] = []

// 处理每个分片的上传操作
for (let i = 0; i < splitNum; i++) {
let start = i * eachSize
let end = Math.min(file.size, start + eachSize)
const start = i * eachSize
const end = Math.min(file.size, start + eachSize)

const form = new FormData()
form.append('file', file.slice(start, end))
form.append('upload_id', uploadId)
form.append('split_index', i)
form.append('split_num', splitNum)
form.append('split_index', `${i}`)
form.append('split_num', `${splitNum}`)

items.push(form)
}
Expand All @@ -36,7 +36,7 @@ export const useUploadsStore = defineStore('uploads', {
},
getters: {
successCount: (state) => {
return state.items.filter((item) => {
return state.items.filter((item: any) => {
return item.status === 2
}).length
}
Expand All @@ -47,14 +47,15 @@ export const useUploadsStore = defineStore('uploads', {
},

// 初始化上传
initUploadFile(file, talkType, receiverId, username) {
initUploadFile(file: File, talkType: number, receiverId: number, username: string) {
ServeFindFileSplitInfo({
file_name: file.name,
file_size: file.size
}).then((res) => {
if (res.code == 200) {
const { upload_id, split_size } = res.data

// @ts-ignore
this.items.unshift({
file: file,
talk_type: talkType,
Expand All @@ -77,15 +78,15 @@ export const useUploadsStore = defineStore('uploads', {
},

// 获取分片文件数组索引
findItem(uploadId) {
return this.items.find((item) => item.upload_id === uploadId)
findItem(uploadId: string): any {
return this.items.find((item: any) => item.upload_id === uploadId)
},

// 触发上传
triggerUpload(uploadId) {
triggerUpload(uploadId: string) {
const item = this.findItem(uploadId)

let form = item.files[item.uploadIndex]
const form = item.files[item.uploadIndex]

item.status = 1

Expand All @@ -99,7 +100,7 @@ export const useUploadsStore = defineStore('uploads', {
item.percentage = 100
this.sendUploadMessage(item)
} else {
let percentage = (item.uploadIndex / item.files.length) * 100
const percentage = (item.uploadIndex / item.files.length) * 100
item.percentage = percentage.toFixed(1)
this.triggerUpload(uploadId)
}
Expand All @@ -113,7 +114,7 @@ export const useUploadsStore = defineStore('uploads', {
},

// 发送上传消息
sendUploadMessage(item) {
sendUploadMessage(item: any) {
ServeSendTalkFile({
upload_id: item.upload_id,
receiver_id: item.receiver_id,
Expand Down
Loading

0 comments on commit 6771585

Please sign in to comment.