2019-11-14 19:13:14 +08:00
|
|
|
function getTheme (component) {
|
2019-10-08 13:34:34 +08:00
|
|
|
let cursor = component
|
|
|
|
while (cursor.$parent) {
|
|
|
|
const name = cursor.$options.name
|
|
|
|
if (cursor.synthesizedTheme) {
|
|
|
|
return cursor.synthesizedTheme
|
|
|
|
}
|
2019-11-28 16:17:21 +08:00
|
|
|
if (name === 'NConfigProvider') {
|
2019-10-08 13:34:34 +08:00
|
|
|
return cursor.theme || null
|
|
|
|
}
|
|
|
|
cursor = cursor.$parent
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2019-11-14 19:13:14 +08:00
|
|
|
function install (Vue, Component, name) {
|
2019-10-18 17:14:47 +08:00
|
|
|
const prototypeProxy = new Proxy(
|
2019-11-14 19:13:14 +08:00
|
|
|
function () {
|
2019-10-18 17:14:47 +08:00
|
|
|
return Component
|
|
|
|
},
|
|
|
|
{
|
2019-11-14 19:13:14 +08:00
|
|
|
apply (target, thisArg, argumentsList) {
|
2019-10-18 17:14:47 +08:00
|
|
|
if (thisArg instanceof Vue) {
|
|
|
|
Component.theme = getTheme(thisArg)
|
2019-11-14 19:13:14 +08:00
|
|
|
// console.log('theme', getTheme(thisArg))
|
2019-10-18 17:14:47 +08:00
|
|
|
}
|
|
|
|
return target.bind(thisArg)(...argumentsList)
|
2019-10-08 14:14:30 +08:00
|
|
|
}
|
2019-10-08 13:34:34 +08:00
|
|
|
}
|
2019-10-18 17:14:47 +08:00
|
|
|
)
|
2019-10-08 13:34:34 +08:00
|
|
|
Object.defineProperty(Vue.prototype, name, {
|
|
|
|
get: prototypeProxy
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-10-18 17:14:47 +08:00
|
|
|
export { getTheme, install }
|