Skip to content

Commit b0e93bf

Browse files
committed
fix: 修复一些问题
1 parent 9e731b6 commit b0e93bf

File tree

8 files changed

+221
-23
lines changed

8 files changed

+221
-23
lines changed

src/layout/components/LayoutHistory.vue

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@
1313
:disable-transitions="true"
1414
effect="dark"
1515
round
16+
:title="getTitle(tag)"
1617
:type="
1718
routeStore.currentRoute?.fullPath === tag.route.fullPath ? '' : 'info'
1819
"
1920
>
20-
<RouterLink :to="{ path: tag.route.fullPath }">{{
21+
<div
22+
@click="Utils.toPath(tag.route.fullPath)"
23+
class="ck-nav-history-href t-pointer"
24+
>
25+
{{ getTitle(tag) }}
26+
</div>
27+
<!-- <RouterLink :to="{ path: tag.route.fullPath }">{{
2128
getTitle(tag)
22-
}}</RouterLink>
29+
}}</RouterLink> -->
2330
</el-tag>
2431
<!-- </div> -->
2532
</el-scrollbar>
@@ -47,8 +54,9 @@
4754

4855
<script lang="ts">
4956
import { defineComponent, inject, ref } from 'vue';
50-
import { RouterLink } from 'vue-router';
57+
// import { RouterLink } from 'vue-router';
5158
import { ElScrollbar } from 'element-plus';
59+
import Utils from '@/utils';
5260
import { routeStoreInject, layoutStoreInject, LangEnum } from '@/contants';
5361
export default defineComponent({
5462
setup() {
@@ -58,22 +66,29 @@ export default defineComponent({
5866
// scrollbarRef: ref<InstanceType<typeof ElScrollbar>>(),
5967
routeStore,
6068
layoutStore,
69+
Utils,
6170
};
6271
},
6372
components: {
64-
RouterLink,
73+
// RouterLink,
6574
},
6675
mounted() {
6776
this.setScrollLeft();
68-
this.routeStore.$subscribe(() => {
77+
this.routeStore.$subscribe(async () => {
78+
await Utils.sleep(0.2);
6979
this.setScrollLeft();
7080
});
7181
},
7282
methods: {
7383
setScrollLeft() {
74-
const $targetNav: any = document.querySelector(
84+
let $targetNav: any = document.querySelector(
7585
`#CkNav-${this.routeStore.nowCacheIndex}`
7686
);
87+
if (!$targetNav) {
88+
$targetNav = document.querySelector(
89+
`#CkNav-${this.routeStore.cacheCount - 2}`
90+
);
91+
}
7792
(
7893
this.$refs['scrollbarRef'] as InstanceType<typeof ElScrollbar>
7994
)?.setScrollLeft($targetNav?.offsetLeft);
@@ -91,16 +106,16 @@ export default defineComponent({
91106
}
92107
const cacheCount = this.routeStore.cacheCount;
93108
if (
94-
this.routeStore.cache[index].route.path ===
95-
this.routeStore.currentRoute?.path
109+
this.routeStore.cache[index].route.fullPath ===
110+
this.routeStore.currentRoute?.fullPath
96111
) {
97112
if (this.routeStore.cache.length >= 1) {
98113
const nextIndex = index == 0 ? index + 1 : index - 1;
99114
if (nextIndex >= cacheCount) {
100115
this.$router.replace({ path: '/' });
101116
} else {
102-
const path = this.routeStore.cache[nextIndex].route.path;
103-
this.$router.replace({ path });
117+
const path = this.routeStore.cache[nextIndex].route.fullPath;
118+
this.$router.replace(path);
104119
}
105120
}
106121
}
@@ -134,6 +149,10 @@ export default defineComponent({
134149
color: #fff;
135150
}
136151
}
152+
.ck-nav-history-href {
153+
max-width: 170px;
154+
@include ellipsis();
155+
}
137156
.ck-nav-menu {
138157
@include flexCenter();
139158
&-text {

src/plugins/axios.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,21 @@ service.interceptors.response.use(
8888
case 200:
8989
// [ 示例 ] code === 0 代表没有错误
9090
return dataAxios;
91-
break;
9291
default:
9392
// 不是正确的 code
9493
// 如果config或者data里面有silent字段,不弹出信息
9594
if (!response.config.silent) {
95+
console.info('axios info', response.config);
9696
if (response.config.params && response.config.params.silent) {
9797
break;
9898
}
9999
if (response.config.data && response.config.data.silent) {
100100
break;
101101
}
102102
errorCreat({ msg: `${errMsg}`, otherinfo });
103-
} else {
104-
throw new Error(errMsg);
105103
}
106-
break;
104+
return Promise.reject({ message: errMsg });
105+
// throw new Error(errMsg);
107106
}
108107
}
109108
},

src/stores/layout.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ export const useLayoutStore = defineStore({
7575
}
7676
const defaultLang = Utils.storage.get(StorageEnum.lang) || 'zh-cn';
7777
i18n.global.locale = defaultLang;
78+
const isMiniScreen =
79+
(document as any).querySelector('html')?.offsetWidth <= 500;
80+
if (isMiniScreen) {
81+
(document as any).querySelector('html').classList.add('is-phone');
82+
}
7883
return {
7984
langList: [
8085
{
@@ -91,7 +96,7 @@ export const useLayoutStore = defineStore({
9196
leftMenuOpen,
9297
asideMenuActive: '0',
9398
dark,
94-
isMiniScreen: (document as any).querySelector('html')?.offsetWidth <= 500,
99+
isMiniScreen,
95100
asideMenu: [],
96101
pathLog: [],
97102
themes: Themes,
@@ -155,12 +160,12 @@ export const useLayoutStore = defineStore({
155160
return;
156161
}
157162
// 根据路径更新active的index
158-
const { path } = route;
163+
const { fullPath } = route;
159164
let outIndex = '';
160165
let tempArr: any = [];
161166
const findIndex = (item: any) => {
162167
tempArr.push(item);
163-
if (item.path === path) {
168+
if (item.path === fullPath) {
164169
this.pathLog = tempArr;
165170
outIndex = item.hash;
166171
return;

src/stores/route.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,21 @@ export const useRouteStore = defineStore({
6060
},
6161
nowCacheIndex(state): number {
6262
return state.cache.findIndex(
63-
(n) => n.route.path === state?.currentRoute?.path
63+
(n) => n.route.fullPath === state?.currentRoute?.fullPath
6464
);
6565
},
6666
},
6767
actions: {
68+
updateCache(metaObj = {}): void {
69+
const { cache } = this;
70+
cache[this.nowCacheIndex].route.meta = Object.assign(
71+
{},
72+
cache[this.nowCacheIndex].route.meta,
73+
metaObj
74+
);
75+
this.cache = cache;
76+
Utils.storage.set(StorageEnum.routeCache, this.cache);
77+
},
6878
clearCache(): void {
6979
this.cache = [];
7080
},
@@ -95,7 +105,9 @@ export const useRouteStore = defineStore({
95105
return;
96106
}
97107
//查一次原数组是否有此路径,有的话不做操作
98-
const delIndex = this.cache.findIndex((n) => n.route.path === path);
108+
const delIndex = this.cache.findIndex(
109+
(n) => n.route.fullPath === fullPath
110+
);
99111
// delIndex >= 0 && this.cache.splice(delIndex, 1);
100112
if (delIndex >= 0) {
101113
return;

src/styles/base.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ html {
4848
*::after {
4949
box-sizing: border-box;
5050
margin: 0;
51-
font-weight: normal;
5251
}
5352

5453
.ck-scrollbar{

src/styles/mixins.scss

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,30 @@
4545
left: -10px;
4646
}
4747
}
48+
/*
49+
* @name: 文本隐藏 (text-indent: -9999px;有性能问题)
50+
* @param: $support-for-ie {boolean} 是否支持IE6
51+
*/
52+
53+
@mixin text-hide($support-for-ie:true) {
54+
text-indent: 100%;
55+
white-space: nowrap;
56+
overflow: hidden;
57+
@if $support-for-ie {
58+
*text-indent: -9999px;
59+
*text-align: left;
60+
}
61+
}
62+
@mixin ellipsis() {
63+
overflow: hidden;
64+
white-space: nowrap;
65+
word-break: keep-all;
66+
text-overflow: ellipsis;
67+
}
68+
@mixin clamp($n:2){
69+
word-break: break-all;
70+
display: -webkit-box;
71+
-webkit-box-orient: vertical;
72+
-webkit-line-clamp: $n;
73+
overflow: hidden;
74+
}

src/utils/index.ts

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ export default {
3131
return true;
3232
}
3333
},
34+
clone: function (obj: any) {
35+
//返回一个克隆的对象
36+
const newObj: any = {};
37+
for (const prop in obj) {
38+
newObj[prop] = obj[prop];
39+
}
40+
return newObj;
41+
},
3442
isDarkMode(): boolean {
3543
return (
3644
window.matchMedia &&
@@ -60,4 +68,130 @@ export default {
6068
goLogin() {
6169
window.CkRouter.push({ path: '/login' });
6270
},
71+
dateFormat(
72+
timestamp: any = new Date().getTime(),
73+
format = 'yyyy-MM-dd hh:mm:ss'
74+
): string {
75+
if (timestamp == 0) {
76+
return '/';
77+
}
78+
if (String(timestamp).length < 12) {
79+
timestamp = timestamp * 1000;
80+
}
81+
const date = new Date(parseInt(timestamp, 10)),
82+
o: any = {
83+
'M+': date.getMonth() + 1,
84+
'd+': date.getDate(),
85+
'h+': date.getHours(),
86+
'm+': date.getMinutes(),
87+
's+': date.getSeconds(),
88+
'q+': Math.floor((date.getMonth() + 3) / 3),
89+
S: date.getMilliseconds(),
90+
};
91+
92+
if (/(y+)/.test(format)) {
93+
format = format.replace(
94+
RegExp.$1,
95+
(date.getFullYear() + '').substr(4 - RegExp.$1.length)
96+
);
97+
}
98+
99+
for (const k in o) {
100+
if (new RegExp('(' + k + ')').test(format)) {
101+
format = format.replace(
102+
RegExp.$1,
103+
RegExp.$1.length === 1
104+
? o[k]
105+
: ('00' + o[k]).substr(('' + o[k]).length)
106+
);
107+
}
108+
}
109+
return format;
110+
},
111+
/**
112+
* 封装七牛云图片的操作(默认会压缩质量到80以及使用webp格式)
113+
*
114+
* 更多params参数请参考七牛云官方文档
115+
* https://developer.qiniu.com/dora/api/1270/the-advanced-treatment-of-images-imagemogr2#imagemogr2-thumbnail-spec
116+
*/
117+
getQnImg(url = '', params: Array<string> = [''], keepParams = true): string {
118+
//七牛云
119+
if (!url) return '';
120+
let result = ['?imageMogr2', 'interlace', '1'];
121+
// 处理原始阿里云参数
122+
if (keepParams) {
123+
const origin = (url.match(/imageView2([\/\w,]+)/) || [])[1];
124+
if (origin) {
125+
result = result.concat(origin.substr(1).split('/'));
126+
}
127+
}
128+
// 处理调用者的参数
129+
result = result.concat(params);
130+
// 处理缺省的参数
131+
const temp = result.join('/');
132+
// 是否gif图片
133+
const isGif = /\.gif/.test(url);
134+
if (!/quality\//i.test(temp) && !isGif) {
135+
//没有设置质量, 那么默认给80, 但gif图片不设置, 不然就不动了
136+
result.push('quality');
137+
result.push('80');
138+
}
139+
// if(!/format/i.test(temp) && !isGif && isSupportWebp){
140+
// //如果没有设置格式,同时支持webp格式, 那么用webp
141+
// result.push('format')
142+
// result.push('webp')
143+
// }
144+
return (
145+
url.replace(/\?.*/, '') + (result.length > 1 ? result.join('/') : '')
146+
);
147+
},
148+
getFilePrefix(filename = ''): string | undefined {
149+
return filename.split('.').pop();
150+
},
151+
getJScript(url: string, cb: any): void {
152+
console.warn('getJScript');
153+
// return
154+
cb = typeof cb === 'function' ? cb : void 0;
155+
const head = document.getElementsByTagName('head')[0];
156+
const script = document.createElement('script') as any;
157+
script.type = 'text/javascript';
158+
script.onload = script.onreadystatechange = function () {
159+
if (
160+
!this.readyState ||
161+
this.readyState === 'loaded' ||
162+
this.readyState === 'complete'
163+
) {
164+
cb();
165+
script.onload = script.onreadystatechange = null;
166+
}
167+
};
168+
script.src = url;
169+
head.appendChild(script);
170+
},
171+
onRange(num: number, min: number, max: number): boolean {
172+
if (num < min || num > max) {
173+
return false;
174+
}
175+
return true;
176+
},
177+
byteConvert(bytes: number, j = 0): string {
178+
if (bytes < 1000 && !j) return bytes + 'B';
179+
const k = 1024; // 1024
180+
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
181+
let i = 0;
182+
if (j) {
183+
i = j;
184+
return parseFloat((bytes / Math.pow(k, i)).toPrecision()).toFixed(2);
185+
} else {
186+
i = Math.floor(Math.log(bytes) / Math.log(k));
187+
}
188+
return (
189+
parseFloat((bytes / Math.pow(k, i)).toPrecision()).toFixed(2) +
190+
' ' +
191+
sizes[i]
192+
);
193+
},
194+
toPath(path: string): void {
195+
window.CkRouter.push(path);
196+
},
63197
};

0 commit comments

Comments
 (0)