✨ Feat: chrome插件,首页搜索初步完成
This commit is contained in:
parent
90ddef3eca
commit
360bad76d7
@ -7,6 +7,7 @@ chrome.extension.onConnect.addListener(port => {
|
|||||||
switch (msg.type) {
|
switch (msg.type) {
|
||||||
case 'sendToken':
|
case 'sendToken':
|
||||||
localStorage.setItem('token', msg.data);
|
localStorage.setItem('token', msg.data);
|
||||||
|
window.token = msg.data;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.error('未知的数据', msg);
|
console.error('未知的数据', msg);
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
},
|
},
|
||||||
"content_scripts": [{
|
"content_scripts": [{
|
||||||
"matches": ["http://west.tapme.top/*", "http://bookmark.tapme.top/*","http://localhost:3000/*"],
|
"matches": ["http://west.tapme.top/*", "http://bookmark.tapme.top/*","http://localhost:3000/*"],
|
||||||
"js": ["popup/static/sso.js"]
|
"js": ["static/sso.js"]
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
|
@ -4,31 +4,24 @@ import store from '../store';
|
|||||||
import router from './router';
|
import router from './router';
|
||||||
import ElementUI from 'element-ui';
|
import ElementUI from 'element-ui';
|
||||||
import 'element-ui/lib/theme-chalk/index.css';
|
import 'element-ui/lib/theme-chalk/index.css';
|
||||||
|
import config from '../util/config';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
global.browser = require('webextension-polyfill');
|
global.browser = require('webextension-polyfill');
|
||||||
Vue.prototype.$browser = global.browser;
|
Vue.prototype.$browser = global.browser;
|
||||||
Vue.use(ElementUI);
|
Vue.use(ElementUI);
|
||||||
|
|
||||||
/* eslint-disable no-new */
|
|
||||||
window.vueInstance = new Vue({
|
|
||||||
el: '#app',
|
|
||||||
store,
|
|
||||||
router,
|
|
||||||
render: h => h(App),
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 配置axios
|
* 配置axios
|
||||||
*/
|
*/
|
||||||
axios.defaults.timeout = 15000;
|
axios.defaults.timeout = 15000;
|
||||||
|
axios.defaults.baseURL = config.baseUrl;
|
||||||
/**
|
/**
|
||||||
* 请求拦截器
|
* 请求拦截器
|
||||||
*/
|
*/
|
||||||
axios.interceptors.request.use(
|
axios.interceptors.request.use(
|
||||||
function(config) {
|
function(config) {
|
||||||
console.log(config);
|
config.headers['jwt-token'] = window.token;
|
||||||
return config;
|
return config;
|
||||||
},
|
},
|
||||||
function(error) {
|
function(error) {
|
||||||
@ -39,10 +32,23 @@ axios.interceptors.request.use(
|
|||||||
|
|
||||||
axios.interceptors.response.use(
|
axios.interceptors.response.use(
|
||||||
res => {
|
res => {
|
||||||
console.log(res);
|
if (res.data.code === -1) {
|
||||||
return res.data;
|
window.vueInstance.$router.replace('/public/login');
|
||||||
|
} else if (res.data.code === 1) {
|
||||||
|
return res.data.data;
|
||||||
|
} else {
|
||||||
|
Promise.reject(res);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/* eslint-disable no-new */
|
||||||
|
window.vueInstance = new Vue({
|
||||||
|
el: '#app',
|
||||||
|
store,
|
||||||
|
router,
|
||||||
|
render: h => h(App),
|
||||||
|
});
|
||||||
|
@ -1,20 +1,71 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="main">
|
<div>
|
||||||
<p>Hello world!</p>
|
<div class="head">
|
||||||
|
<img width="30%" src="/static/img/bookmarkLogo.png" alt="icon" />
|
||||||
|
<span>{{personInfo.username}}</span>
|
||||||
|
</div>
|
||||||
|
<!-- 书签检索 -->
|
||||||
|
<div class="search">
|
||||||
|
<el-input placeholder="关键词检索" v-model="searchContent">
|
||||||
|
<el-button slot="append" icon="el-icon-search"></el-button>
|
||||||
|
</el-input>
|
||||||
|
<div class="searchResult">
|
||||||
|
<div class="item" v-for="item in searchList" :key="item.bookmarkId"><a target="_blank" :href="item.url">{{item.name}}</a></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import axios from 'axios';
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {};
|
return {
|
||||||
|
personInfo: {},
|
||||||
|
searchContent: "",
|
||||||
|
searchList: [],
|
||||||
|
timeOut: null
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
searchContent(newVal, oldVal) {
|
||||||
|
if (newVal.trim() != oldVal) {
|
||||||
|
if (this.timeOut != null) {
|
||||||
|
clearTimeout(this.timeOut);
|
||||||
|
}
|
||||||
|
this.searchList = [];
|
||||||
|
this.timeOut = setTimeout(async () => {
|
||||||
|
this.searchList = await axios.get(`bookmark/searchUserBookmark?content=${newVal}`);
|
||||||
|
this.timeOut = null;
|
||||||
|
}, 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
window.token = localStorage.getItem('token');
|
||||||
|
this.init();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async init() {
|
||||||
|
let personInfo = await axios.get("/user/currentUserInfo");
|
||||||
|
window.personInfo = personInfo;
|
||||||
|
this.personInfo = personInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.main {
|
.head {
|
||||||
width: 50%;
|
display: flex;
|
||||||
height: 50%;
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0 5% 0 5%;
|
||||||
|
}
|
||||||
|
.searchResult {
|
||||||
|
}
|
||||||
|
.item {
|
||||||
|
padding: 5px;
|
||||||
|
border-bottom: 1px solid black;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="main">您还未登陆授权,<el-button type="primary" @click="go">前往授权页面</el-button></div>
|
<div class="main">您还未登陆授权<br />
|
||||||
|
<el-button type="primary" @click="go">前往授权页面</el-button>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import config from '../../../../util/config';
|
||||||
export default {
|
export default {
|
||||||
name: 'login',
|
name: 'login',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
// href: 'http://west.tapme.top:8083',
|
|
||||||
href: 'http://localhost:3000/userSpace/ssoAuth',
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
@ -16,7 +17,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
go() {
|
go() {
|
||||||
window.open(this.href);
|
window.open(config.ssoUrl);
|
||||||
},
|
},
|
||||||
// 循环检测token是否生效
|
// 循环检测token是否生效
|
||||||
checkToken() {
|
checkToken() {
|
||||||
@ -33,6 +34,4 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.main {
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
BIN
浏览器插件/bookmark-chrome/src/static/fonts/element-icons.ttf
Normal file
BIN
浏览器插件/bookmark-chrome/src/static/fonts/element-icons.ttf
Normal file
Binary file not shown.
BIN
浏览器插件/bookmark-chrome/src/static/fonts/element-icons.woff
Normal file
BIN
浏览器插件/bookmark-chrome/src/static/fonts/element-icons.woff
Normal file
Binary file not shown.
BIN
浏览器插件/bookmark-chrome/src/static/img/bookmarkLogo.png
Normal file
BIN
浏览器插件/bookmark-chrome/src/static/img/bookmarkLogo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
9
浏览器插件/bookmark-chrome/src/util/config.js
Normal file
9
浏览器插件/bookmark-chrome/src/util/config.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// const baseUri = 'https://bm.tapme.top';
|
||||||
|
const baseUri = 'http://localhost:3000';
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
baseUrl: baseUri + '/bookmark/api',
|
||||||
|
ssoUrl: baseUri + '/userSpace/ssoAuth',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
@ -74,7 +74,8 @@ const config = {
|
|||||||
}),
|
}),
|
||||||
new CopyWebpackPlugin([
|
new CopyWebpackPlugin([
|
||||||
{ from: 'icons', to: 'icons', ignore: ['icon.xcf'] },
|
{ from: 'icons', to: 'icons', ignore: ['icon.xcf'] },
|
||||||
{ from: 'static', to: 'popup/static' },
|
{ from: 'static', to: 'static' },
|
||||||
|
{ from: 'static/fonts', to: 'fonts' },
|
||||||
{ from: 'popup/popup.html', to: 'popup/popup.html', transform: transformHtml },
|
{ from: 'popup/popup.html', to: 'popup/popup.html', transform: transformHtml },
|
||||||
{ from: 'options/options.html', to: 'options/options.html', transform: transformHtml },
|
{ from: 'options/options.html', to: 'options/options.html', transform: transformHtml },
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user