mirror of
https://github.com/kuaifan/dootask.git
synced 2026-02-28 21:20:31 +00:00
perf: 支持搜索在线表情
This commit is contained in:
parent
f49b157d13
commit
8cdfe01afa
@ -338,6 +338,30 @@ class IndexController extends InvokeController
|
||||
return abort(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索表情
|
||||
* @return array
|
||||
*/
|
||||
public function emo__search()
|
||||
{
|
||||
$key = Request::input('key');
|
||||
if (empty($key)) {
|
||||
return Base::retError("key empty");
|
||||
}
|
||||
return Cache::remember("emo__search:" . md5($key), now()->addDay(), function () use ($key) {
|
||||
$res = Ihttp::ihttp_get("http://www.adoutu.com/search?keyword=" . urlencode($key));
|
||||
if (Base::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
$content = Base::getMiddle($res['data'], '<!--图片列表-->', '<!--分页器-->');
|
||||
preg_match_all("/<img\s+src=\"(.*?)\"/s", $content, $matchs);
|
||||
if ($matchs && $matchs[1]) {
|
||||
return Base::retSuccess('success', array_slice($matchs[1], 0, 20));
|
||||
}
|
||||
return Base::retError("result empty");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置语言和皮肤
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "DooTask",
|
||||
"version": "0.20.78",
|
||||
"version": "0.20.79",
|
||||
"description": "DooTask is task management system.",
|
||||
"scripts": {
|
||||
"start": "./cmd dev",
|
||||
|
||||
2
public/js/build/226.js
vendored
2
public/js/build/226.js
vendored
File diff suppressed because one or more lines are too long
2
public/js/build/382.js
vendored
2
public/js/build/382.js
vendored
File diff suppressed because one or more lines are too long
2
public/js/build/434.js
vendored
2
public/js/build/434.js
vendored
File diff suppressed because one or more lines are too long
2
public/js/build/481.js
vendored
2
public/js/build/481.js
vendored
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
7c46245fccbbfd5f
|
||||
1232463f96c3b53b
|
||||
|
||||
@ -1235,6 +1235,10 @@
|
||||
"/uploads/chat/202211/33/b59239e2c85d1830.png": "/uploads/chat/202211/33/b59239e2c85d1830.png",
|
||||
"/uploads/chat/202211/33/b59239e2c85d1830.png_thumb.jpg": "/uploads/chat/202211/33/b59239e2c85d1830.png_thumb.jpg",
|
||||
"/uploads/chat/202211/33/f682a136679c12bb641bb6967a9ff475.mov": "/uploads/chat/202211/33/f682a136679c12bb641bb6967a9ff475.mov",
|
||||
"/uploads/chat/202211/45/088a642eb13ee5cf.jpg": "/uploads/chat/202211/45/088a642eb13ee5cf.jpg",
|
||||
"/uploads/chat/202211/45/088a642eb13ee5cf.jpg_thumb.jpg": "/uploads/chat/202211/45/088a642eb13ee5cf.jpg_thumb.jpg",
|
||||
"/uploads/chat/202211/45/f242ea07dda50e76.jpg": "/uploads/chat/202211/45/f242ea07dda50e76.jpg",
|
||||
"/uploads/chat/202211/45/f242ea07dda50e76.jpg_thumb.jpg": "/uploads/chat/202211/45/f242ea07dda50e76.jpg_thumb.jpg",
|
||||
"/uploads/desktop/0.12.0/builder-debug.yml": "/uploads/desktop/0.12.0/builder-debug.yml",
|
||||
"/uploads/desktop/0.12.0/builder-effective-config.yaml": "/uploads/desktop/0.12.0/builder-effective-config.yaml",
|
||||
"/uploads/desktop/0.12.0/latest-mac.yml": "/uploads/desktop/0.12.0/latest-mac.yml",
|
||||
|
||||
@ -696,6 +696,7 @@ export default {
|
||||
},
|
||||
|
||||
updateEmojiQuick(text) {
|
||||
this.emojiSearchKey = "";
|
||||
if (!this.isFocus || !text) {
|
||||
this.emojiQuickShow = false
|
||||
return
|
||||
@ -709,13 +710,15 @@ export default {
|
||||
&& text.length >= 1
|
||||
&& text.length <= 8
|
||||
&& $A.isArray(window.emoticonData)) {
|
||||
// 搜索在线表情
|
||||
this.searchEmoji(text);
|
||||
// 显示快捷选择表情窗口
|
||||
this.emojiQuickItems = [];
|
||||
window.emoticonData.some(data => {
|
||||
let item = data.list.find(({name}) => $A.strExists(name, text))
|
||||
if (item) {
|
||||
this.emojiQuickItems.push({data, item})
|
||||
if (this.emojiQuickItems.length >= 3) {
|
||||
if (this.emojiQuickItems.length >= 2) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -732,6 +735,70 @@ export default {
|
||||
}, 100)
|
||||
},
|
||||
|
||||
searchEmoji(text) {
|
||||
this.emojiSearchKey = text;
|
||||
this.emojiSearchTimer && clearTimeout(this.emojiSearchTimer);
|
||||
this.emojiSearchTimer = setTimeout(_ => {
|
||||
if (this.emojiSearchKey !== text) {
|
||||
return;
|
||||
}
|
||||
this.$store.dispatch("call", {
|
||||
url: '../emo/search',
|
||||
data: {
|
||||
key: text,
|
||||
}
|
||||
}).then(({data}) => {
|
||||
if (this.emojiSearchKey !== text) {
|
||||
return;
|
||||
}
|
||||
let maxNum = 3;
|
||||
if (this.windowWidth > 1000) maxNum = 5;
|
||||
else if (this.windowWidth > 900) maxNum = 4;
|
||||
const array = this.getRandomArrayElements(data.map(item => {
|
||||
return {
|
||||
data: {},
|
||||
item: {
|
||||
type: "online",
|
||||
name: this.$L("动画表情"),
|
||||
src: this.asciiConvertNative(item)
|
||||
}
|
||||
}
|
||||
}), maxNum - this.emojiQuickItems.length)
|
||||
if (array.length > 0) {
|
||||
this.emojiQuickItems.push(...array)
|
||||
this.$nextTick(_ => {
|
||||
this.emojiQuickShow = true
|
||||
this.$refs.emojiQuickRef.updatePopper()
|
||||
})
|
||||
}
|
||||
});
|
||||
}, 800)
|
||||
},
|
||||
|
||||
asciiConvertNative(val) {
|
||||
let asciicode = val.split("\\u");
|
||||
let nativeValue = asciicode[0];
|
||||
for (let i = 1; i < asciicode.length; i++) {
|
||||
let code = asciicode[i];
|
||||
nativeValue += String.fromCharCode(parseInt("0x" + code.substring(0, 4)));
|
||||
if (code.length > 4) {
|
||||
nativeValue += code.substring(4, code.length);
|
||||
}
|
||||
}
|
||||
return nativeValue
|
||||
},
|
||||
|
||||
getRandomArrayElements(arr, count) {
|
||||
let shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index;
|
||||
while (i-- > min) {
|
||||
index = Math.floor((i + 1) * Math.random());
|
||||
temp = shuffled[index];
|
||||
shuffled[index] = shuffled[i];
|
||||
shuffled[i] = temp;
|
||||
}
|
||||
return shuffled.slice(min);
|
||||
},
|
||||
|
||||
setText(value) {
|
||||
if (this.quill) {
|
||||
this.quill.setText(value)
|
||||
@ -907,14 +974,19 @@ export default {
|
||||
},
|
||||
|
||||
onEmojiQuick({data, item}) {
|
||||
const baseUrl = $A.apiUrl("../images/emoticon")
|
||||
const emoji = {
|
||||
asset: `images/emoticon/${data.path}/${item.path}`,
|
||||
name: item.name,
|
||||
src: `${baseUrl}/${data.path}/${item.path}`
|
||||
if (item.type === 'online') {
|
||||
this.$emit('input', "")
|
||||
this.$emit('on-send', `<img src="${item.src}"/>`)
|
||||
} else {
|
||||
const baseUrl = $A.apiUrl("../images/emoticon")
|
||||
const emoji = {
|
||||
asset: `images/emoticon/${data.path}/${item.path}`,
|
||||
name: item.name,
|
||||
src: `${baseUrl}/${data.path}/${item.path}`
|
||||
}
|
||||
this.$emit('input', "")
|
||||
this.$emit('on-send', `<img class="emoticon" data-asset="${emoji.asset}" data-name="${emoji.name}" src="${emoji.src}"/>`)
|
||||
}
|
||||
this.$emit('input', "")
|
||||
this.$emit('on-send', `<img class="emoticon" data-asset="${emoji.asset}" data-name="${emoji.name}" src="${emoji.src}"/>`)
|
||||
this.emojiQuickShow = false
|
||||
this.focus()
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user