Skip to content

Commit

Permalink
工具类调整
Browse files Browse the repository at this point in the history
💚 [not-build-web]
  • Loading branch information
Stapxs committed Apr 2, 2024
1 parent ec51dbe commit df7895b
Showing 18 changed files with 468 additions and 526 deletions.
9 changes: 8 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
@@ -231,7 +231,8 @@ import { Connector, login as loginInfo } from '@/function/connect'
import { Logger, popList, PopInfo } from '@/function/base'
import { runtimeData } from '@/function/msg'
import { BaseChatInfoElem } from '@/function/elements/information'
import { loadHistory, getTrueLang, gitmojiToEmoji, openLink } from '@/function/util'
import { getTrueLang, gitmojiToEmoji } from '@/utils/systemUtil'
import { openLink, loadHistory } from './utils/appUtil'
import Options from '@/pages/Options.vue'
import Friends from '@/pages/Friends.vue'
@@ -429,6 +430,12 @@ export default defineComponent({
mounted () {
const logger = new Logger()
window.moYu = () => { return 'undefined' }
// MacOS:初始化菜单
const electron = (process.env.IS_ELECTRON as any) === true ? window.require('electron') : null
const reader = electron ? electron.ipcRenderer : null
if (reader) {
reader.send('sys:updateMenu')
}
// 页面加载完成后
window.onload = () => {
app.config.globalProperties.$viewer = this.viewerBody
2 changes: 1 addition & 1 deletion src/components/FileBody.vue
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@
<script lang="ts">
import { defineComponent } from 'vue'

import { getTrueLang, getSizeFromBytes, htmlDecodeByRegExp } from '@/function/util'
import { getTrueLang, htmlDecodeByRegExp, getSizeFromBytes } from '@/utils/systemUtil'
import { Connector } from '@/function/connect'
import { runtimeData } from '@/function/msg'

2 changes: 1 addition & 1 deletion src/components/FriendBody.vue
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@

<script lang="ts">
import { defineComponent } from 'vue'
import { getTrueLang } from '@/function/util'
import { getTrueLang } from '@/utils/systemUtil'

export default defineComponent({
name: 'FriendBody',
14 changes: 7 additions & 7 deletions src/components/MsgBody.vue
Original file line number Diff line number Diff line change
@@ -122,7 +122,6 @@

<script lang="ts">

import Util from '@/function/util'
import Option from '@/function/option'
import CardMessage from './msg-component/CardMessage.vue'
import app from '@/main'
@@ -134,8 +133,9 @@ import { Connector } from '@/function/connect'
import { runtimeData } from '@/function/msg'
import { Logger, PopInfo, PopType } from '@/function/base'
import { StringifyOptions } from 'querystring'
import { getMsgRawTxt } from '@/function/util'
import { getFace } from '@/utils/msgUtil'
import { getFace, getMsgRawTxt } from '@/utils/msgUtil'
import { openLink, downloadFile } from '@/utils/appUtil'
import { getSizeFromBytes } from '@/utils/systemUtil'

export default defineComponent({
name: 'MsgBody',
@@ -144,7 +144,7 @@ export default defineComponent({
data () {
return {
getFace: getFace,
getSizeFromBytes: Util.getSizeFromBytes,
getSizeFromBytes: getSizeFromBytes,
isMe: false,
isDebugMsg: Option.get('debug_msg'),
linkViewStyle: '',
@@ -161,7 +161,7 @@ export default defineComponent({
* @param message 消息对象
*/
getMsgRawTxt (message: any) {
return Util.getMsgRawTxt(message)
return getMsgRawTxt(message)
},

/**
@@ -454,7 +454,7 @@ export default defineComponent({
}
if(data.url) {
// 消息中有文件链接的话就不用获取了 ……
Util.downloadFile(data.url, data.name, onProcess)
downloadFile(data.url, data.name, onProcess)
} else {
// 获取下载链接
Connector.send('get_file_url', {
@@ -489,7 +489,7 @@ export default defineComponent({
if(target.dataset.link) {
// 点击了链接
const link = target.dataset.link
Util.openLink(link)
openLink(link)
}
},

2 changes: 1 addition & 1 deletion src/components/NoticeBody.vue
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
<script lang="ts">
import { defineComponent, ref } from 'vue'
import { runtimeData } from '@/function/msg'
import { getTrueLang } from '@/function/util'
import { getTrueLang } from '@/utils/systemUtil'

export default defineComponent({
name: 'NoticeBody',
7 changes: 4 additions & 3 deletions src/function/model/msg-body.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,8 @@ import app from '@/main'
import { PopInfo, PopType } from '@/function/base'
import { runtimeData } from '@/function/msg'
import { Connector } from '@/function/connect'
import util from '../util'
import { openLink } from '@/utils/appUtil'
import { getDeviceType } from '@/utils/systemUtil'

const popInfo = new PopInfo()

@@ -180,7 +181,7 @@ export class MsgBodyFuns {
if(json.app == 'com.tencent.map') {
info.title = json.meta['Location.Search'].name
append.urlOpenType = '_self'
const deviceType = util.getDeviceType()
const deviceType = getDeviceType()
if(deviceType == 'Android') {
info.url = 'geo:' + json.meta['Location.Search'].lat + ',' + json.meta['Location.Search'].lng
} else if(deviceType == 'iOS' || deviceType == 'MacOS') {
@@ -209,7 +210,7 @@ export class MsgBodyFuns {
window.open(sender.dataset.url, '_self')
} else {
// 默认都以 _blank 打开
util.openLink(sender.dataset.url)
openLink(sender.dataset.url)
}
return
}
24 changes: 12 additions & 12 deletions src/function/msg.ts
Original file line number Diff line number Diff line change
@@ -13,14 +13,14 @@ import qed from '@/assets/qed.txt'

import app from '@/main'
import Option from './option'
import Util from './util'
import xss from 'xss'
import pinyin from 'pinyin'

import Umami from '@bitprojects/umami-logger-typescript'

import { buildMsgList, getMsgData, parseMsgList } from '@/utils/msgUtil'

import { buildMsgList, getMsgData, parseMsgList, getMsgRawTxt } from '@/utils/msgUtil'
import { htmlDecodeByRegExp, randomNum } from '@/utils/systemUtil'
import { reloadUsers, downloadFile } from '@/utils/appUtil'
import { reactive, nextTick, markRaw, defineAsyncComponent } from 'vue'
import { PopInfo, PopType, Logger, LogType } from './base'
import { Connector, login } from './connect'
@@ -162,7 +162,7 @@ function saveLoginInfo(msg: { [key: string]: any }) {
'getMoreLoginInfo'
)
// 加载列表消息
Util.reloadUsers()
reloadUsers()
}
}

@@ -490,7 +490,7 @@ function downloadFileChat(msg: any) {
runtimeData.messageList[index].message[indexMsg].
downloadingPercentage = Math.floor(event.loaded / event.total * 100)
}
Util.downloadFile(url, msg.echo.substring(msg.echo.lastIndexOf('_') + 1, msg.echo.length), onProcess)
downloadFile(url, msg.echo.substring(msg.echo.lastIndexOf('_') + 1, msg.echo.length), onProcess)
}
}

@@ -504,15 +504,15 @@ function downloadGroupFile(msg: any) {
let subFileIndex = -1
runtimeData.chatInfo.info.group_files.file_list.forEach((item: any, index: number) => {
if (item.id === id) {
fileName = Util.htmlDecodeByRegExp(item.name)
fileName = htmlDecodeByRegExp(item.name)
fileIndex = index
}
})
// 特殊情况:这是个子文件
if (info[2] !== undefined) {
runtimeData.chatInfo.info.group_files.file_list[fileIndex].sub_list.forEach((item: any, index:number) => {
if (item.id === info[2]) {
fileName = Util.htmlDecodeByRegExp(item.name)
fileName = htmlDecodeByRegExp(item.name)
subFileIndex = index
}
})
@@ -537,7 +537,7 @@ function downloadGroupFile(msg: any) {
}

// 下载文件
Util.downloadFile(msg.data.url, fileName, onProcess)
downloadFile(msg.data.url, fileName, onProcess)
}

function getVideoUrl(msg: any) {
@@ -613,7 +613,7 @@ function newMsg(data: any) {
// 保存消息
saveMsg(buildMsgList([data]), 'bottom')
// 抽个签
const num = Util.randomNum(0, 10000)
const num = randomNum(0, 10000)
if (num >= 4500 && num <= 5500) {
new Logger().add(LogType.INFO, num.toString() + ',这只是个神秘的数字...')
}
@@ -738,7 +738,7 @@ function newMsg(data: any) {

function sendNotice(msg: any) {
if (Option.get('close_notice') !== true) {
let raw = Util.getMsgRawTxt(msg.message)
let raw = getMsgRawTxt(msg.message)
raw = raw === '' ? msg.raw_message : raw
// 检查消息内是否有群名
if(msg.group_name === undefined) {
@@ -892,7 +892,7 @@ function updateSysInfo(type: string) {
Connector.send('get_system_msg', {}, 'getSystemMsg')
switch(type) {
case 'setFriendAdd':
Util.reloadUsers(); break
reloadUsers(); break
}
}

@@ -914,7 +914,7 @@ function addSystemNotice(msg: any) {
*/
function friendNotice(msg: any) {
// 重新加载联系人列表
Util.reloadUsers();
reloadUsers();
switch(msg.sub_type) {
case 'increase': {
// 添加系统通知
3 changes: 2 additions & 1 deletion src/function/option.ts
Original file line number Diff line number Diff line change
@@ -17,7 +17,8 @@ import { i18n } from '@/main'
import { markRaw, defineAsyncComponent } from 'vue'
import { Logger, LogType, PopInfo, PopType } from './base'
import { runtimeData } from './msg'
import { initUITest, getTrueLang, loadSystemThemeColor, loadWinColor, updateWinColor } from './util'
import { initUITest, loadSystemThemeColor, loadWinColor, updateWinColor } from '@/utils/appUtil'
import { getTrueLang } from '@/utils/systemUtil'

let cacheConfigs: { [key: string]: any }

12 changes: 7 additions & 5 deletions src/pages/Chat.vue
Original file line number Diff line number Diff line change
@@ -384,7 +384,6 @@
import app from '@/main'
import SendUtil from '@/function/sender'
import Option from '@/function/option'
import Util from '@/function/util'
import Info from '@/pages/Info.vue'
import MsgBody from '@/components/MsgBody.vue'
import NoticeBody from '@/components/NoticeBody.vue'
@@ -393,7 +392,10 @@ import imageCompression from 'browser-image-compression'
import jp from 'jsonpath'

import { defineComponent, markRaw } from 'vue'
import { getTrueLang, loadHistory as loadHistoryFirst, getMsgRawTxt } from '@/function/util'
import { loadHistory as loadHistoryFirst } from '@/utils/appUtil'
import { getTrueLang } from '@/utils/systemUtil'
import { getMsgRawTxt, parseJSONCQCode } from '@/utils/msgUtil'
import { scrollToMsg } from '@/utils/appUtil'
import { Logger, LogType, PopInfo, PopType } from '@/function/base'
import { Connector, login as loginInfo } from '@/function/connect'
import { runtimeData } from '@/function/msg'
@@ -559,7 +561,7 @@ export default defineComponent({
},
scrollToMsg (message_id: string) {
// oicq1:seq 字段名消息格式兼容
if (!Util.scrollToMsg(message_id, true)) {
if (!scrollToMsg(message_id, true)) {
new PopInfo().add(PopType.INFO, this.$t('pop_chat_msg_not_load') + ' ( ' + message_id.split('-')[1] + ' ) ')
}
},
@@ -911,7 +913,7 @@ export default defineComponent({
fun: () => {
let msgSend = msg.message
if(runtimeData.tags.msgType == BotMsgType.CQCode) {
msgSend = Util.parseJSONCQCode(msgSend)
msgSend = parseJSONCQCode(msgSend)
}
switch (type) {
case 'group': Connector.send('send_group_msg', { 'group_id': id, 'message': msgSend }, 'sendMsgBack_forward'); break
@@ -934,7 +936,7 @@ export default defineComponent({
if (msg !== null) {
// 如果消息体没有简述消息的话 ……
if(!msg.raw_message) {
msg.raw_message = Util.getMsgRawTxt(msg.message)
msg.raw_message = getMsgRawTxt(msg.message)
}
const popInfo = new PopInfo()
app.config.globalProperties.$copyText(msg.raw_message).then(() => {
2 changes: 1 addition & 1 deletion src/pages/Friends.vue
Original file line number Diff line number Diff line change
@@ -112,7 +112,7 @@ import { BaseChatInfoElem, UserFriendElem } from '@/function/elements/informatio
import { UserGroupElem } from '@/function/elements/information'

import { runtimeData } from '@/function/msg'
import { reloadUsers } from '@/function/util'
import { reloadUsers } from '@/utils/appUtil'

export default defineComponent({
name: 'ViewFriends',
2 changes: 1 addition & 1 deletion src/pages/Info.vue
Original file line number Diff line number Diff line change
@@ -164,7 +164,7 @@ import FileBody from '@/components/FileBody.vue'
import OptInfo from './options/OptInfo.vue'

import { defineComponent, toRaw } from 'vue'
import { getTrueLang } from '@/function/util'
import { getTrueLang } from '@/utils/systemUtil'
import { runtimeData } from '@/function/msg'
import { UserFriendElem, UserGroupElem } from '@/function/elements/information'

2 changes: 1 addition & 1 deletion src/pages/Messages.vue
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ import { defineComponent } from 'vue'
import { runtimeData, notificationList } from '@/function/msg'
import { UserFriendElem, UserGroupElem } from '@/function/elements/information'
import { getRaw as getOpt, run as runOpt } from '@/function/option'
import { loadHistoryMessage } from '@/function/util'
import { loadHistoryMessage } from '@/utils/appUtil'
import { PopInfo, PopType } from '@/function/base'
import { MenuStatue } from 'vue3-bcui/packages/dist/types'
import { library } from '@fortawesome/fontawesome-svg-core'
10 changes: 5 additions & 5 deletions src/pages/Options.vue
Original file line number Diff line number Diff line change
@@ -44,16 +44,16 @@
</div>
<span style="text-align: center;">{{ $t('description') }}</span>
<a>v{{ packageInfo.version }}</a>
<a class="ss-button" @click="util.openLink('https://github.com/Stapxs/Stapxs-QQ-Lite-2.0')">{{ $t('option_info_visit_github') }}</a>
<a class="ss-button" @click="openLink('https://github.com/Stapxs/Stapxs-QQ-Lite-2.0')">{{ $t('option_info_visit_github') }}</a>
<div v-if="constList.length > 0" class="ss-card contributors-card">
<div>
<div v-for="info in constList" :key="'contributors-' + info.title" :title="info.title"
:style="'background-image: url(' + info.url + ');'" :class="info.isMe ? 'me' : ''"
@click="util.openLink(info.link)"></div>
@click="openLink(info.link)"></div>
</div>
</div>
</div>
<div class="ss-card bcd-about" @click="util.openLink('https://stapxs.github.io/Border-Card-UI/docs/')">
<div class="ss-card bcd-about" @click="openLink('https://stapxs.github.io/Border-Card-UI/docs/')">
<div>
<div>
<div class="bcd-body"
@@ -206,14 +206,14 @@
import { defineComponent } from 'vue'

import packageInfo from '../../package.json'
import Util from '@/function/util'

import OptAccount from './options/OptAccount.vue'
import OptView from './options/OptView.vue'
import OptDev from './options/OptDev.vue'
import OptFunction from './options/OptFunction.vue'

import { ContributorElem } from '@/function/elements/system'
import { openLink } from '@/utils/appUtil'

export default defineComponent({
name: 'ViewOption',
@@ -225,7 +225,7 @@ export default defineComponent({
return {
constList: [] as ContributorElem[],
packageInfo: packageInfo,
util: Util
openLink: openLink
}
},
mounted() {
2 changes: 1 addition & 1 deletion src/pages/chat-view/ChatShell.vue
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ import { nextTick } from 'vue'
import { Connector } from '@/function/connect'
import { defineComponent, markRaw } from 'vue'
import { runtimeData, appendMsg } from '@/function/msg'
import { getTrueLang } from '@/function/util'
import { getTrueLang } from '@/utils/systemUtil'
import { MsgItemElem, SQCodeElem, UserFriendElem, UserGroupElem } from '@/function/elements/information'
import { Logger, LogType, PopInfo, popList, PopType } from '@/function/base'

5 changes: 2 additions & 3 deletions src/pages/options/OptAccount.vue
Original file line number Diff line number Diff line change
@@ -80,11 +80,10 @@
</template>

<script lang="ts">
import Util from '@/function/util'

import { runASWEvent as saveR, remove } from '@/function/option'
import { runtimeData } from '@/function/msg'
import { Connector, login } from '@/function/connect'
import { getTrueLang } from '@/utils/systemUtil'

export default {
name: 'ViewOptAccount',
@@ -109,7 +108,7 @@ export default {
value = value * 1000
}
return Intl.DateTimeFormat(
Util.getTrueLang(),
getTrueLang(),
{ year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric' }).format(new Date(value))
}
return value
Loading

0 comments on commit df7895b

Please sign in to comment.