123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- module.exports = {
-
- props: {
-
- customStyle: {
- type: [Object, String],
- default: () => ({})
- },
- customClass: {
- type: String,
- default: ''
- },
-
- url: {
- type: String,
- default: ''
- },
-
- linkType: {
- type: String,
- default: 'navigateTo'
- }
- },
- data() {
- return {}
- },
- onLoad() {
-
- this.$u.getRect = this.$uGetRect
- },
- created() {
-
- this.$u.getRect = this.$uGetRect
- },
- computed: {
-
-
-
- $u() {
-
-
- return uni.$u.deepMerge(uni.$u, {
- props: undefined,
- http: undefined,
- mixin: undefined
- })
-
-
- return uni.$u
-
- },
-
- bem() {
- return function (name, fixed, change) {
-
- const prefix = `u-${name}--`
- const classes = {}
- if (fixed) {
- fixed.map((item) => {
-
- classes[prefix + this[item]] = true
- })
- }
- if (change) {
- change.map((item) => {
-
- this[item] ? (classes[prefix + item] = this[item]) : (delete classes[prefix + item])
- })
- }
- return Object.keys(classes)
- }
- }
- },
- methods: {
-
- openPage(urlKey = 'url') {
- const url = this[urlKey]
- if (url) {
-
- uni[this.linkType]({
- url
- })
- }
- },
-
-
-
- $uGetRect(selector, all) {
- return new Promise((resolve) => {
- uni.createSelectorQuery()
- .in(this)[all ? 'selectAll' : 'select'](selector)
- .boundingClientRect((rect) => {
- if (all && Array.isArray(rect) && rect.length) {
- resolve(rect)
- }
- if (!all && rect) {
- resolve(rect)
- }
- })
- .exec()
- })
- },
- getParentData(parentName = '') {
-
- if (!this.parent) this.parent = {}
-
-
-
-
- this.parent = uni.$u.$parent.call(this, parentName)
- if (this.parent.children) {
-
- this.parent.children.indexOf(this) === -1 && this.parent.children.push(this)
- }
- if (this.parent && this.parentData) {
-
- Object.keys(this.parentData).map((key) => {
- this.parentData[key] = this.parent[key]
- })
- }
- },
-
- preventEvent(e) {
- e && typeof (e.stopPropagation) === 'function' && e.stopPropagation()
- },
-
- noop(e) {
- this.preventEvent(e)
- }
- },
- onReachBottom() {
- uni.$emit('uOnReachBottom')
- },
- beforeDestroy() {
-
-
- if (this.parent && uni.$u.test.array(this.parent.children)) {
-
- const childrenList = this.parent.children
- childrenList.map((child, index) => {
-
- if (child === this) {
- childrenList.splice(index, 1)
- }
- })
- }
- }
- }
|