2018-03-19 02:16:27 +00:00
|
|
|
|
2018-02-23 08:14:59 +00:00
|
|
|
import PropTypes from '../_util/vue-types'
|
|
|
|
import * as moment from 'moment'
|
2018-04-07 06:29:59 +00:00
|
|
|
import interopDefault from '../_util/interopDefault'
|
2018-03-20 11:06:04 +00:00
|
|
|
import { changeConfirmLocale } from '../modal/locale'
|
2018-02-23 08:14:59 +00:00
|
|
|
|
|
|
|
// export interface Locale {
|
|
|
|
// locale: string;
|
|
|
|
// Pagination?: Object;
|
|
|
|
// DatePicker?: Object;
|
|
|
|
// TimePicker?: Object;
|
|
|
|
// Calendar?: Object;
|
|
|
|
// Table?: Object;
|
|
|
|
// Modal?: ModalLocale;
|
|
|
|
// Popconfirm?: Object;
|
|
|
|
// Transfer?: Object;
|
|
|
|
// Select?: Object;
|
|
|
|
// Upload?: Object;
|
|
|
|
// }
|
|
|
|
|
|
|
|
function setMomentLocale (locale) {
|
|
|
|
if (locale && locale.locale) {
|
2018-04-07 06:29:59 +00:00
|
|
|
interopDefault(moment).locale(locale.locale)
|
2018-02-23 08:14:59 +00:00
|
|
|
} else {
|
2018-04-07 06:29:59 +00:00
|
|
|
interopDefault(moment).locale('en')
|
2018-02-23 08:14:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-19 05:21:57 +00:00
|
|
|
const LocaleProvider = {
|
2018-04-08 13:17:20 +00:00
|
|
|
name: 'ALocaleProvider',
|
2018-02-23 08:14:59 +00:00
|
|
|
props: {
|
|
|
|
locale: PropTypes.object.def({}),
|
|
|
|
},
|
2018-03-15 14:21:25 +00:00
|
|
|
data () {
|
2018-02-23 08:14:59 +00:00
|
|
|
return {
|
|
|
|
antLocale: {
|
|
|
|
...this.locale,
|
|
|
|
exist: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2018-03-15 14:21:25 +00:00
|
|
|
provide () {
|
|
|
|
return {
|
|
|
|
localeData: this.$data,
|
|
|
|
}
|
|
|
|
},
|
2018-02-23 08:14:59 +00:00
|
|
|
watch: {
|
|
|
|
locale (val) {
|
2018-03-15 14:21:25 +00:00
|
|
|
this.antLocale = {
|
|
|
|
...this.locale,
|
|
|
|
exist: true,
|
|
|
|
}
|
2018-02-23 08:14:59 +00:00
|
|
|
setMomentLocale(val)
|
|
|
|
},
|
|
|
|
},
|
2018-09-05 13:28:54 +00:00
|
|
|
created () {
|
2018-02-23 08:14:59 +00:00
|
|
|
const { locale } = this
|
|
|
|
setMomentLocale(locale)
|
2018-03-20 11:06:04 +00:00
|
|
|
changeConfirmLocale(locale && locale.Modal)
|
2018-02-23 08:14:59 +00:00
|
|
|
},
|
|
|
|
updated () {
|
2018-03-20 11:06:04 +00:00
|
|
|
const { locale } = this
|
|
|
|
changeConfirmLocale(locale && locale.Modal)
|
2018-02-23 08:14:59 +00:00
|
|
|
},
|
|
|
|
beforeDestroy () {
|
2018-03-20 11:06:04 +00:00
|
|
|
changeConfirmLocale()
|
2018-02-23 08:14:59 +00:00
|
|
|
},
|
|
|
|
render () {
|
2018-09-17 02:20:23 +00:00
|
|
|
return this.$slots.default ? this.$slots.default[0] : null
|
2018-02-23 08:14:59 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-09-19 05:21:57 +00:00
|
|
|
/* istanbul ignore next */
|
|
|
|
LocaleProvider.install = function (Vue) {
|
|
|
|
Vue.component(LocaleProvider.name, LocaleProvider)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default LocaleProvider
|
|
|
|
|