♻️(document): 重构文档结构

This commit is contained in:
就眠儀式 2022-06-25 20:12:12 +08:00
parent b86b7d308c
commit 4636c7c38d
6 changed files with 61 additions and 42 deletions

View File

@ -3,13 +3,27 @@
<img :src="imgList[index].src" /> <img :src="imgList[index].src" />
<div class="layui-layer-imgsee" v-if="imgList.length > 0"> <div class="layui-layer-imgsee" v-if="imgList.length > 0">
<span class="layui-layer-imguide" v-if="imgList.length > 1"> <span class="layui-layer-imguide" v-if="imgList.length > 1">
<a href="javascript:;" class="layui-layer-iconext layui-layer-imgprev" @click="changeIndex(-1)"></a> <a
<a href="javascript:;" class="layui-layer-iconext layui-layer-imgnext" @click="changeIndex(1)"></a> href="javascript:;"
class="layui-layer-iconext layui-layer-imgprev"
@click="changeIndex(-1)"
></a>
<a
href="javascript:;"
class="layui-layer-iconext layui-layer-imgnext"
@click="changeIndex(1)"
></a>
</span> </span>
<div class="layui-layer-imgbar" style="display: block" v-if="imgList.length > 1 || imgList[index].alt"> <div
class="layui-layer-imgbar"
style="display: block"
v-if="imgList.length > 1 || imgList[index].alt"
>
<span class="layui-layer-imgtit"> <span class="layui-layer-imgtit">
<span v-if="imgList[index].alt">{{ imgList[index].alt }}</span> <span v-if="imgList[index].alt">{{ imgList[index].alt }}</span>
<em v-if="imgList.length > 1">{{ index + 1 }} / {{ imgList.length }}</em> <em v-if="imgList.length > 1"
>{{ index + 1 }} / {{ imgList.length }}</em
>
</span> </span>
</div> </div>
</div> </div>
@ -24,7 +38,7 @@ export default {
import { watch, ref } from "vue"; import { watch, ref } from "vue";
export interface LayPhotoProps { export interface LayPhotoProps {
imgList: { src: string, alt: string }[]; imgList: { src: string; alt: string }[];
startIndex: number; startIndex: number;
} }
const emit = defineEmits(["resetCalculationPohtosArea"]); const emit = defineEmits(["resetCalculationPohtosArea"]);
@ -34,18 +48,18 @@ const props = withDefaults(defineProps<LayPhotoProps>(), {
const index = ref(props.startIndex); const index = ref(props.startIndex);
watch(index, () => { watch(index, () => {
// //
emit('resetCalculationPohtosArea', index.value) emit("resetCalculationPohtosArea", index.value);
}) });
const changeIndex = (step: number) => { const changeIndex = (step: number) => {
let nowIndex = index.value let nowIndex = index.value;
let next = nowIndex + step let next = nowIndex + step;
if (next < 0) { if (next < 0) {
next = props.imgList.length - 1 next = props.imgList.length - 1;
} }
if (next >= props.imgList.length) { if (next >= props.imgList.length) {
next = 0 next = 0;
} }
index.value = next index.value = next;
} };
</script> </script>

View File

@ -55,7 +55,17 @@ export interface LayModalProps {
btn?: Record<string, Function>[] | false; btn?: Record<string, Function>[] | false;
move?: boolean | string; move?: boolean | string;
resize?: boolean | string; resize?: boolean | string;
type?: 0 | 1 | 2 | 3 | "dialog" | "page" | "iframe" | "loading" | "drawer" | "photos"; type?:
| 0
| 1
| 2
| 3
| "dialog"
| "page"
| "iframe"
| "loading"
| "drawer"
| "photos";
content?: string | Function | object | VNodeTypes; content?: string | Function | object | VNodeTypes;
isHtmlFragment?: boolean; isHtmlFragment?: boolean;
shade?: boolean | string; shade?: boolean | string;

View File

@ -123,18 +123,18 @@ const layer = {
}, },
//图片预览 //图片预览
photos: (option: any, callback?: Function) => { photos: (option: any, callback?: Function) => {
if (typeof option === 'string') { if (typeof option === "string") {
option = { option = {
imgList: [{ src: option }] imgList: [{ src: option }],
} };
} }
let defaultOption = { let defaultOption = {
type: 'photos', type: "photos",
anim: 2, anim: 2,
startIndex: 0, startIndex: 0,
isOutAnim: true, isOutAnim: true,
shadeClose: true, shadeClose: true,
shadeOpacity: '0.7' shadeOpacity: "0.7",
}; };
return layer.create(option, defaultOption, callback); return layer.create(option, defaultOption, callback);
}, },

View File

@ -1,4 +1,4 @@
import { layer } from "../index" import { layer } from "../index";
// 随机数 // 随机数
export function nextId() { export function nextId() {
@ -255,32 +255,32 @@ export function loadImage(url: string, callback: Function, error: any) {
}; };
} }
export async function calculatePhotosArea(url: string,options:object) { export async function calculatePhotosArea(url: string, options: object) {
let img = new Image(); let img = new Image();
img.src = url; img.src = url;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (img.complete) { if (img.complete) {
resolve(area(img)) resolve(area(img));
return return;
} }
const layerId=layer.load(2) const layerId = layer.load(2);
img.onload = () => { img.onload = () => {
layer.close(layerId) layer.close(layerId);
resolve(area(img)) resolve(area(img));
}; };
img.onerror = () => { img.onerror = () => {
layer.close(layerId) layer.close(layerId);
layer.msg('图片加载失败') layer.msg("图片加载失败");
reject(false) reject(false);
} };
}) });
function area(img:{width:number,height:number}){ function area(img: { width: number; height: number }) {
var imgarea = [img.width, img.height]; var imgarea = [img.width, img.height];
var winarea = [window.innerWidth - 100, window.innerHeight - 100]; var winarea = [window.innerWidth - 100, window.innerHeight - 100];
//如果 实际图片的宽或者高比 屏幕大(那么进行缩放) //如果 实际图片的宽或者高比 屏幕大(那么进行缩放)
if ( imgarea[0] > winarea[0] || imgarea[1] > winarea[1]) { if (imgarea[0] > winarea[0] || imgarea[1] > winarea[1]) {
let wh = [imgarea[0] / winarea[0], imgarea[1] / winarea[1]]; //取宽度缩放比例、高度缩放比例 let wh = [imgarea[0] / winarea[0], imgarea[1] / winarea[1]]; //取宽度缩放比例、高度缩放比例
if (wh[0] > wh[1]) { if (wh[0] > wh[1]) {
//取缩放比例最大的进行缩放 //取缩放比例最大的进行缩放
@ -293,5 +293,4 @@ export async function calculatePhotosArea(url: string,options:object) {
} }
return [imgarea[0] + "px", imgarea[1] + "px"]; return [imgarea[0] + "px", imgarea[1] + "px"];
} }
} }

View File

@ -32,15 +32,11 @@ export default defineConfig({
}, },
plugins: [ plugins: [
babel({ babel({
babelHelpers: 'runtime', babelHelpers: "runtime",
exclude: "node_modules/**", exclude: "node_modules/**",
extensions: [".js", ".jsx", ".ts", ".tsx", ".vue"], extensions: [".js", ".jsx", ".ts", ".tsx", ".vue"],
presets: ["@babel/preset-env", "@babel/preset-typescript"], presets: ["@babel/preset-env", "@babel/preset-typescript"],
plugins: [ plugins: [["@babel/plugin-transform-runtime"]],
[
'@babel/plugin-transform-runtime',
],
]
}), }),
], ],
external: ["vue"], external: ["vue"],