feat: 图标搜索支持中文

This commit is contained in:
fofolee 2020-12-27 10:44:08 +08:00
parent e99de56baa
commit b887f61b9b

View File

@ -1356,7 +1356,7 @@
// 从 icons8 选择图标 // 从 icons8 选择图标
let getIcons8Icon = () => { let getIcons8Icon = () => {
let showIcon = icon => { let showIcon = icon => {
return $(`<img class="icon8s" src="https://img.icons8.com/color/1x/${icon.commonName}.png"> <span>${icon.name}</span>`) return $(`<img class="networkImg" src="https://img.icons8.com/color/1x/${icon.commonName}.png"> <span>${icon.name}</span>`)
} }
let showItems = item => { let showItems = item => {
if (item.loading) return item.text if (item.loading) return item.text
@ -1364,10 +1364,10 @@
} }
let showSelection = selection => { let showSelection = selection => {
if (!selection.commonName) return selection.text if (!selection.commonName) return selection.text
$('#networkImg').val(`https://img.icons8.com/color/1x/${selection.commonName}.png`) $('#networkImgUrl').val(`https://img.icons8.com/color/1x/${selection.commonName}.png`)
return showIcon(selection) return showIcon(selection)
} }
$('#icons8').select2({ $('#networkImg').select2({
dataType: 'json', dataType: 'json',
width: '80%', width: '80%',
delay: 250, delay: 250,
@ -1379,10 +1379,11 @@
offset: (params.page - 1) * 10 || 0, offset: (params.page - 1) * 10 || 0,
platform: 'color', platform: 'color',
amount: 10, amount: 10,
token: 'JpOyWT5TW8yYThBIk1fCbsNDd3ISSChSD5vPgCON' token: 'JpOyWT5TW8yYThBIk1fCbsNDd3ISSChSD5vPgCON',
language: /[\u4e00-\u9fa5]/.test(params.term) ? 'zh' : 'en'
} }
}, },
processResults: function (data, params) { processResults: function (data) {
return { return {
results: data.icons, results: data.icons,
pagination: { pagination: {
@ -1415,8 +1416,8 @@
let showChangeIconWindow = () => { let showChangeIconWindow = () => {
var html = ` var html = `
<button id="localImg" class="swal2-confirm swal2-styled" style="width: 80%; height: 3rem; margin: 1em">选择本地图标</button> <button id="localImg" class="swal2-confirm swal2-styled" style="width: 80%; height: 3rem; margin: 1em">选择本地图标</button>
<select id="icons8"></select> <select id="networkImg"></select>
<input id="networkImg" placeholder="使用网络图片" class="swal2-input" style="width: 80%; height: 3rem; text-align: center"> <input id="networkImgUrl" placeholder="使用网络图片" class="swal2-input" style="width: 80%; height: 3rem; text-align: center">
` `
Swal.fire({ Swal.fire({
title: "设置图标", title: "设置图标",
@ -1436,7 +1437,7 @@
html: html, html: html,
showCancelButton: true, showCancelButton: true,
preConfirm: async () => { preConfirm: async () => {
let imgUrl = $('#networkImg').val() let imgUrl = $('#networkImgUrl').val()
if (imgUrl) await getRemoteImg(imgUrl) if (imgUrl) await getRemoteImg(imgUrl)
else quickcommand.showMessageBox('没有输入图标地址', 'warning') else quickcommand.showMessageBox('没有输入图标地址', 'warning')
} }