Commit ea5a2b92 by Jaxon

style(d2-container): 格式化组件代码,统一代码风格与导入顺序

重新排序导入语句,统一全文件缩进与分号使用,规范整体代码格式
1 parent a6a91927
import d2ContainerCardBs from "./components/d2-container-card-bs.vue";
import d2ContainerCard from "./components/d2-container-card.vue";
import d2ContainerFullBs from "./components/d2-container-full-bs.vue";
// 组件 // 组件
import d2ContainerFull from "./components/d2-container-full.vue" import d2ContainerFull from "./components/d2-container-full.vue";
import d2ContainerFullBs from "./components/d2-container-full-bs.vue" import d2ContainerGhostBs from "./components/d2-container-ghost-bs.vue";
import d2ContainerGhost from "./components/d2-container-ghost.vue" import d2ContainerGhost from "./components/d2-container-ghost.vue";
import d2ContainerGhostBs from "./components/d2-container-ghost-bs.vue"
import d2ContainerCard from "./components/d2-container-card.vue"
import d2ContainerCardBs from "./components/d2-container-card-bs.vue"
// import d2Source from './components/d2-source.vue' // import d2Source from './components/d2-source.vue'
export default { export default {
name: "d2-container", name: "d2-container",
props: { props: {
// 容器样式 // 容器样式
type: { type: {
type: String, type: String,
required: false, required: false,
default: "full" default: "full",
}, },
// 滚动优化 // 滚动优化
betterScroll: { betterScroll: {
type: Boolean, type: Boolean,
required: false, required: false,
default: false default: false,
} },
}, },
computed: { computed: {
// 始终返回渲染组件 // 始终返回渲染组件
component() { component() {
if (this.type === "card" && !this.betterScroll) return d2ContainerCard if (this.type === "card" && !this.betterScroll)
if (this.type === "card" && this.betterScroll) return d2ContainerCardBs return d2ContainerCard;
if (this.type === "ghost" && !this.betterScroll) return d2ContainerGhost if (this.type === "card" && this.betterScroll)
if (this.type === "ghost" && this.betterScroll) return d2ContainerGhostBs return d2ContainerCardBs;
if (this.type === "full" && !this.betterScroll) return d2ContainerFull if (this.type === "ghost" && !this.betterScroll)
if (this.type === "full" && this.betterScroll) return d2ContainerFullBs return d2ContainerGhost;
else { if (this.type === "ghost" && this.betterScroll)
return "div" return d2ContainerGhostBs;
} if (this.type === "full" && !this.betterScroll)
} return d2ContainerFull;
}, if (this.type === "full" && this.betterScroll) {
render(h) { return d2ContainerFullBs;
const slots = [this.$slots.default] } else {
if (this.$slots.header) { slots.push(h("template", { slot: "header" }, [this.$slots.header])) } return "div";
if (this.$slots.footer) { slots.push(h("template", { slot: "footer" }, [this.$slots.footer])) } }
return h( },
"div", },
{ render(h) {
ref: "container", const slots = [this.$slots.default];
class: "container-component" if (this.$slots.header) {
}, slots.push(h("template", { slot: "header" }, [this.$slots.header]));
[ }
h( if (this.$slots.footer) {
this.component, slots.push(h("template", { slot: "footer" }, [this.$slots.footer]));
{ }
ref: "component", return h(
props: this.$attrs, "div",
on: { {
scroll: (e) => this.$emit("scroll", e) ref: "container",
} class: "container-component",
}, },
slots [
) h(
// h(d2Source) this.component,
] {
) ref: "component",
}, props: this.$attrs,
methods: { on: {
// 返回顶部 scroll: e => this.$emit("scroll", e),
scrollToTop() { },
this.$refs.component.scrollToTop() },
// 如果开启了 better scroll 还需要手动触发一遍 scroll 事件 slots,
const bs = this.$refs.component.BS ),
if (bs) this.$refs.component.scroll() // h(d2Source)
}, ],
// 用法同原生方法 scrollBy );
scrollBy(x = 0, y = 0, time = 300) { },
if (this.betterScroll) { methods: {
const bs = this.$refs.component.BS // 返回顶部
if (bs) { scrollToTop() {
bs.scrollBy(-x, -y, time) this.$refs.component.scrollToTop();
// 手动触发一遍 scroll 事件 // 如果开启了 better scroll 还需要手动触发一遍 scroll 事件
this.$refs.component.scroll() const bs = this.$refs.component.BS;
} if (bs)
} else { this.$refs.component.scroll();
this.$refs.component.$refs.body.scrollBy(x, y) },
} // 用法同原生方法 scrollBy
}, scrollBy(x = 0, y = 0, time = 300) {
// 用法同原生方法 scrollTo if (this.betterScroll) {
scrollTo(x = 0, y = 0, time = 300) { const bs = this.$refs.component.BS;
if (this.betterScroll) { if (bs) {
const bs = this.$refs.component.BS bs.scrollBy(-x, -y, time);
if (bs) { // 手动触发一遍 scroll 事件
bs.scrollTo(-x, -y, time) this.$refs.component.scroll();
// 手动触发一遍 scroll 事件 }
this.$refs.component.scroll() } else {
} this.$refs.component.$refs.body.scrollBy(x, y);
} else { }
this.$refs.component.$refs.body.scrollTo(x, y) },
} // 用法同原生方法 scrollTo
}, scrollTo(x = 0, y = 0, time = 300) {
// 用法同原生方法 scrollTop if (this.betterScroll) {
scrollTop(top = 0, time = 300) { const bs = this.$refs.component.BS;
if (this.betterScroll) { if (bs) {
const bs = this.$refs.component.BS bs.scrollTo(-x, -y, time);
if (bs) { // 手动触发一遍 scroll 事件
bs.scrollTo(bs.x, -top, time) this.$refs.component.scroll();
// 手动触发一遍 scroll 事件 }
this.$refs.component.scroll() } else {
} this.$refs.component.$refs.body.scrollTo(x, y);
} else { }
this.$refs.component.$refs.body.scrollTop = top },
} // 用法同原生方法 scrollTop
} scrollTop(top = 0, time = 300) {
} if (this.betterScroll) {
} const bs = this.$refs.component.BS;
if (bs) {
bs.scrollTo(bs.x, -top, time);
// 手动触发一遍 scroll 事件
this.$refs.component.scroll();
}
} else {
this.$refs.component.$refs.body.scrollTop = top;
}
},
},
};
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!