Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins增加了地理位置、清除缓存两个模块; #1054

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Web/packages/web/src/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ import Resource from './plugins/resources/index'
import ApiMock from './plugins/api-mock/index'
import WebVitals from './plugins/web-vitals-time/index'

import Geolocation from './plugins/geolocation/index'
import ClearCache from './plugins/clear-cache/index'

import {IndependPlugin, RouterPlugin} from '@dokit/web-core'

export const BasicFeatures = {
title: '常用工具',
list: [Console, AppInfo, Resource, Network, Storage, DemoPlugin, DemoIndependPlugin, H5DoorPlugin, WebVitals, Element, OneMachineWithMultipleControls, scanCode]
list: [Console, AppInfo, Resource, Network, Storage, DemoPlugin, DemoIndependPlugin, H5DoorPlugin, WebVitals, Element,
OneMachineWithMultipleControls, scanCode, Geolocation, ClearCache]
// list: [Console, AppInfo, Resource, Network, Storage, H5DoorPlugin]
}

Expand Down
39 changes: 39 additions & 0 deletions Web/packages/web/src/plugins/clear-cache/cookie.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<template>
<div style="margin-top:20px;">
<InfoCard :infoMap="storageMap" title="Cookie" @refresh="updateList" @clear="clear" @removeItem="removeItem"></InfoCard>
</div>
</template>
<script>
import InfoCard from './info-card'
import { clearCookie, removeCookieItem, getCookieMap } from './js/storage'

export default {
components: {
InfoCard
},
data () {
return {
storageMap: {}
}
},
created() {
this.updateList()
},
methods: {
updateList() {
this.storageMap = getCookieMap()
},
removeItem(key) {
removeCookieItem(key)
this.updateList()
},
clear() {
clearCookie()
this.updateList()
}
},
}
</script>
<style lang="">

</style>
12 changes: 12 additions & 0 deletions Web/packages/web/src/plugins/clear-cache/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ClearCache from './main.vue'
// import {overrideConsole,restoreConsole} from './js/console'
import {getGlobalData, RouterPlugin} from '@dokit/web-core'

export default new RouterPlugin({
name: 'ClearCache',
nameZh: '清除缓存',
component: ClearCache,
icon: "https://pt-starimg.didistatic.com/static/starimg/img/nU9RCY0E1e1655278941997.pic",
onLoad(){},
onUnload(){}
})
161 changes: 161 additions & 0 deletions Web/packages/web/src/plugins/clear-cache/info-card.vue

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions Web/packages/web/src/plugins/clear-cache/js/storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
export const overrideLocalStorage = function(callback) {
const originSetItem = localStorage.setItem.bind(localStorage);
localStorage.setItem = function (key, value) {
// if (!isStr(key) || !isStr(value)) return;
originSetItem(key, value);
callback({type: 'setItem'})
};

const originRemoveItem = localStorage.removeItem.bind(localStorage);
localStorage.removeItem = function (key) {
originRemoveItem(key);
callback({type: 'removeItem'})
};

const originClear = localStorage.clear.bind(localStorage);
localStorage.clear = function (key) {
originClear();
callback({type: 'clear'})
};
}

export const overrideSessionStorage = function(callback) {
const originSetItem = sessionStorage.setItem.bind(sessionStorage);
sessionStorage.setItem = function (key, value) {
// if (!isStr(key) || !isStr(value)) return;
originSetItem(key, value);
callback({type: 'setItem'})
};

const originRemoveItem = sessionStorage.removeItem.bind(sessionStorage);
sessionStorage.removeItem = function (key) {
originRemoveItem(key);
callback({type: 'removeItem'})
};

const originClear = sessionStorage.clear.bind(sessionStorage);
sessionStorage.clear = function (key) {
originClear();
callback({type: 'clear'})
};
}

export const clearCookie = function () {
let cookieMap = getCookieMap()
for (const key in cookieMap) {
if (cookieMap.hasOwnProperty.call(cookieMap, key)) {
removeCookieItem(key)
}
}
}

export const removeCookieItem = function (key) {
document.cookie = encodeURIComponent(key) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
}

export const getCookieMap = function (params) {
const cookieMap = Object.create({})
const cookie = document.cookie;
if (cookie.trim() !== '') {
cookie.split(';').forEach(ele => {
ele = ele.split('=');
const key = ele.shift().trim();
ele = decodeURIComponent(ele.join('='));
cookieMap[key] = ele
})
}

return cookieMap;
}

47 changes: 47 additions & 0 deletions Web/packages/web/src/plugins/clear-cache/local-storage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<template>
<div>
<InfoCard :infoMap="storageMap" title="localStorage" @refresh="updateList" @clear="clear" @removeItem="removeItem"></InfoCard>
</div>
</template>
<script>
import InfoCard from './info-card'
import {overrideLocalStorage} from './js/storage'

export default {
components: {
InfoCard
},
data () {
return {
storageMap: {}
}
},
created() {
overrideLocalStorage(() => {
this.updateList()
});
this.updateList()
},
methods: {
updateList() {
let storageMap = {...window.localStorage}
// 有一些属性不需要展示
for (const key in storageMap) {
if (Object.hasOwnProperty.call(storageMap, key)) {
if (~key.indexOf('dokit') || typeof storageMap[key] !== 'string') delete storageMap[key]
}
}
this.storageMap = storageMap
},
removeItem(key) {
window.localStorage.removeItem(key)
},
clear() {
window.localStorage.clear()
}
},
}
</script>
<style lang="">

</style>
120 changes: 120 additions & 0 deletions Web/packages/web/src/plugins/clear-cache/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<template>
<div class="storage-plugin">
<localStorage></localStorage>
<div>
<input type="checkbox" id="check1" value="localStorage" v-model="checkedItem" />
<label for="check1">清除</label>
</div>

<sessionStorage></sessionStorage>
<div>
<input type="checkbox" id="check2" value="sessionStorage" v-model="checkedItem" />
<label for="check2">清除</label>
</div>

<cookie></cookie>
<div>
<input type="checkbox" id="check3" value="cookie" v-model="checkedItem" />
<label for="check3">清除</label>
</div>

<div>
<input type="checkbox" id="checkall" v-model="checkedAll" @change="changeAllChecked()" />
<label for="checkall">全选</label>
</div>

<div class="portal-textarea-container">
<div class="portal-opt-area">
<div class="opt-btn" @click="clearCache">清除缓存</div>
</div>
</div>
</div>

</template>
<script>
import localStorage from './local-storage';
import sessionStorage from './session-storage';
import cookie from './cookie';
import { clearCookie, removeCookieItem, getCookieMap } from './js/storage'

export default {
data() {
return {
checkedAll : false,
checkedItem: [],
checkedAttr: ["localStorage", "sessionStorage", "cookie"],
}
},

methods:{
changeAllChecked() {
if (this.checkedAll) {
this.checkedItem = this.checkedAttr;
} else {
this.checkedItem = [];
}
},
clearCache(){
if (window.confirm(`是否确认清除所选缓存?`)) {
for(var i = 0; i < checkedItem.length; i++){
if(this.checkedItem[i]=="localStorage"){
window.localStorage.clear()
}else if(this.checkedItem[i]=="sessionStorage"){
window.sessionStorage.clear()
}else{
clearCookie()
}
}
}
}
},

watch: {
checkedItem() {
if (this.checkedItem.length == this.checkedAttr.length) {
this.checkedAll = true;
} else {
this.checkedAll = false;
}
}
},

components: {
localStorage,
sessionStorage,
cookie
}
}
</script>

<style lang="less" scoped>
.portal-textarea-container{
.portal-textarea{
font-size: 13px;
border-radius: 5px;
box-sizing: border-box;
width: 100%;
border: 1px solid #d6e4ef;
resize: vertical;
}
.portal-opt-area{
margin-top: 5px;
height: 32px;
line-height: 32px;
display: flex;
justify-content: space-between;
align-items: center;
.opt-btn{
background-color: #337CC4;
border-radius: 5px;
font-size: 16px;
width: 100%;
text-align: center;
color: #fff;
}
}
}
.storage-plugin{
padding: 5px;
}
</style>
47 changes: 47 additions & 0 deletions Web/packages/web/src/plugins/clear-cache/session-storage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<template>
<div style="margin-top:20px;">
<InfoCard :infoMap="storageMap" title="sessionStorage" @refresh="updateList" @clear="clear" @removeItem="removeItem"></InfoCard>
</div>
</template>
<script>
import InfoCard from './info-card'
import {overrideSessionStorage} from './js/storage'

export default {
components: {
InfoCard
},
data () {
return {
storageMap: {}
}
},
created() {
overrideSessionStorage(() => {
this.updateList()
});
this.updateList()
},
methods: {
updateList() {
let storageMap = {...window.sessionStorage}
// 有一些属性不需要展示
for (const key in storageMap) {
if (Object.hasOwnProperty.call(storageMap, key)) {
if (~key.indexOf('dokit') || typeof storageMap[key] !== 'string') delete storageMap[key]
}
}
this.storageMap = storageMap
},
removeItem(key) {
window.sessionStorage.removeItem(key)
},
clear() {
window.sessionStorage.clear()
}
},
}
</script>
<style lang="">

</style>
19 changes: 7 additions & 12 deletions Web/packages/web/src/plugins/element/elementTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,13 @@ export default {
$bus.off(this.node.key + "refreshChild", this.refreshSon);
}
},
parentIsUnfold:{
handler: function (val) {
if(this.node?.key){
if (val) {
$bus.on(this.node.key + "refreshMy", this.refresh);
} else {
$bus.off(this.node.key + "refreshMy", this.refresh);
}
}
},
immediate: true,
}
parentIsUnfold(val) {
if (val) {
$bus.on(this.node.key + "refreshMy", this.refresh);
} else {
$bus.off(this.node.key + "refreshMy", this.refresh);
}
},
},
created() {
if (this?.node?.tagName === "HTML") {
Expand Down
9 changes: 9 additions & 0 deletions Web/packages/web/src/plugins/geolocation/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {RouterPlugin} from '@dokit/web-core'
import Geolocation from './main.vue'

export default new RouterPlugin({
nameZh: '位置信息',
name: 'geolocation-information',
icon: 'https://pt-starimg.didistatic.com/static/starimg/img/lxFgOzH5HN1655278941999.png',
component: Geolocation
})
Loading