Skip to content

Commit

Permalink
chore: 代码格式化
Browse files Browse the repository at this point in the history
代码格式化
  • Loading branch information
hewx815 committed Aug 21, 2023
1 parent 319c129 commit ab598b8
Show file tree
Hide file tree
Showing 51 changed files with 848 additions and 1,476 deletions.
4 changes: 0 additions & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@

/for-vue2/babel.config.js
/for-vue2/postcss.config.js
/for-vue2/shime-uni.d.ts
/for-vue2/shime-vue.d.ts
/for-vue2/src/static

/for-vue3/dist
6 changes: 0 additions & 6 deletions .eslintrc.cjs

This file was deleted.

7 changes: 7 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"root": true,
"extends": ["eslint-config-hewx/node-javascript"],
"rules": {
"node/no-unsupported-features/es-syntax": [0]
}
}
7 changes: 7 additions & 0 deletions .vitepress/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"root": true,
"extends": ["eslint-config-hewx/vue3-typescript"],
"rules": {
"vue/multi-word-component-names": [0]
}
}
113 changes: 51 additions & 62 deletions .vitepress/components/Preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,85 +6,79 @@
<div
ref="previewIcon"
class="preview_icon"
@mousedown="mousedown"
@mouseup="mouseup"
:style="{
backgroundImage: `url(${open ? closeSvg : phoneSvg})`,
transform: `rotateZ(${open ? '360deg' : '0deg'})`,
}"
@mousedown="mousedown"
@mouseup="mouseup"
/>
<div
:style="iframeStyle"
class="iframe_box"
>
<iframe
@load="open = true"
class="preview_iframe"
:src="url"
frameborder="0"
@load="open = true"
/>
</div>
</div>
</template>

<script setup>
<script setup lang="ts">
/**
* @name 组件预览悬浮组件
* @description 在组件md文件中挂载此组件
* @property {String} path 预览的路径
*/
import {
computed, getCurrentInstance, ref, onMounted,
} from 'vue';
import closeSvg from '../static/close.svg';
import phoneSvg from '../static/phone.svg';
import { defineProps, computed, getCurrentInstance, ref, onMounted } from 'vue';
const props = defineProps({
path: {
type: String,
required: true
required: true,
},
});
// previewBtn path
const previewBtnPath = ref('');
// iframe 打开状态
const open = ref(false);
const open = ref<boolean | number>(false);
const top = ref(0);
const left = ref(0);
const previewIcon = ref<HTMLElement>(null);
const previewIcon = ref(null);
// 储存坐标信息
const KEY = 'HUNI_HEWXING_CN_PREVIEW_XY';
const saveXY = (x: string | number, y: string | number) => {
localStorage.setItem(KEY, JSON.stringify({ x, y }));
};
const getXY = () => {
const data = localStorage.getItem(KEY);
return data ? JSON.parse(data) as { x: string | number; y: string | number; } : null;
};
const { proxy } = getCurrentInstance();
// PhonePreview 组件调用此方法 更改 previewBtnPath
proxy.$root.preview = (url) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
(proxy.$root as any).preview = (url: string) => {
previewBtnPath.value = '';
setTimeout(() => {
previewBtnPath.value = url;
}, 0);
open.value = true;
};
onMounted(() => {
const data = getXY();
if (data) {
left.value = data.x;
top.value = data.y;
return;
}
left.value = 0;
top.value = window.innerHeight - 667 - 50;
});
// iframe src
const url = computed(() => {
const baseUrl = process.env.NODE_ENV === 'production' ? 'https://h-uni.hewxing.cn/preview-vue2/#/' : "http://localhost:8080/#/";
const baseUrl = process.env.NODE_ENV === 'production' ? 'https://h-uni.hewxing.cn/preview-vue2/#/' : 'http://localhost:8080/#/';
return baseUrl + (previewBtnPath.value ? previewBtnPath.value : props.path);
});
Expand All @@ -97,42 +91,38 @@ const iframeStyle = computed(() => {
borderRadius: '10px',
opacity: 1,
};
} else {
return {
width: '0px',
height: '0px',
borderRadius: '0 0 100% 0%',
opacity: 0.5,
};
}
return {
width: '0px',
height: '0px',
borderRadius: '0 0 100% 0%',
opacity: 0.5,
};
});
// 获取滚动条宽度
const getScrollBarWidth = () => {
const outer = document.createElement("div");
outer.style.visibility = "hidden";
outer.style.width = "100px";
outer.style.position = "absolute";
outer.style.top = "-9999px";
const outer = document.createElement('div');
outer.style.visibility = 'hidden';
outer.style.width = '100px';
outer.style.position = 'absolute';
outer.style.top = '-9999px';
document.body.appendChild(outer);
const widthNoScroll = outer.offsetWidth;
outer.style.overflow = "scroll";
outer.style.overflow = 'scroll';
const inner = document.createElement("div");
inner.style.width = "100%";
const inner = document.createElement('div');
inner.style.width = '100%';
outer.appendChild(inner);
const widthWithScroll = inner.offsetWidth;
outer.parentNode.removeChild(outer);
return widthNoScroll - widthWithScroll;;
return widthNoScroll - widthWithScroll;
};
// 移动
const move = (e) => {
const move = (e: MouseEvent) => {
// 鼠标距离屏幕
const mouseX = e.screenX;
const mouseY = e.screenY;
Expand Down Expand Up @@ -178,17 +168,16 @@ const move = (e) => {
open.value = open.value ? 1 : 0;
};
const mousedown = () => {
document.body.style.userSelect = 'none';
const timer = setTimeout(() => {
previewIcon.value.style.cursor = "move";
previewIcon.value.style.cursor = 'move';
document.addEventListener('mousemove', move);
document.addEventListener('mouseup', () => {
if (!previewIcon.value) return;
previewIcon.value.style.cursor = "pointer";
previewIcon.value.style.cursor = 'pointer';
document.body.style.userSelect = 'auto';
document.removeEventListener('mousemove', move);
// 来自移动的抬起事件需要关闭
Expand All @@ -204,22 +193,23 @@ const mousedown = () => {
});
};
const mouseup = () => {
// 来自移动的抬起事件忽略
if (open.value === 0 || open.value === 1) return;
open.value = !open.value;
};
// 储存坐标信息
const KEY = 'HUNI_HEWXING_CN_PREVIEW_XY';
const saveXY = (x, y) => {
localStorage.setItem(KEY, JSON.stringify({ x, y }));
};
const getXY = () => {
const data = localStorage.getItem(KEY);
return data ? JSON.parse(data) : null;
}
onMounted(() => {
const data = getXY();
if (data) {
left.value = Number(data.x);
top.value = Number(data.y);
return;
}
left.value = 0;
top.value = window.innerHeight - 667 - 50;
});
</script>

Expand Down Expand Up @@ -272,7 +262,6 @@ const getXY = () => {
0 1px 2px 0 rgba(0, 0, 0, .14),
0 1px 4px 0 rgba(0, 0, 0, .12);
&:hover {
box-shadow:
0 2px 6px -1px rgba(0, 0, 0, .2),
Expand Down
14 changes: 9 additions & 5 deletions .vitepress/components/PreviewBtn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
class="btn"
@click="clickBtn"
>
<div class="btn_text">预览</div>
<div class="btn_text">
预览
</div>
<img
class="btn_img"
src="../static/eye.svg"
Expand All @@ -13,24 +15,26 @@
</div>
</template>

<script setup>
<script setup lang="ts">
/**
* @name 预览按钮
* @description 依赖组件<Preview> 在
* 代码块的上分插入该组件 点击按钮时会更改<Preview>正在预览的路径
* @property {String} path 预览的路径
*/
import { getCurrentInstance, defineProps } from 'vue';
import { getCurrentInstance } from 'vue';
const props = defineProps({
path: {
type: String,
required: true
required: true,
},
});
const { proxy } = getCurrentInstance();
const clickBtn = () => {
proxy.$root.preview(props.path);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any
(proxy.$root as any).preview(props.path);
};
</script>

Expand Down

0 comments on commit ab598b8

Please sign in to comment.