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-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) {
|
|
|
|
moment.locale(locale.locale)
|
|
|
|
} else {
|
|
|
|
moment.locale('en')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'LocaleProvider',
|
|
|
|
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)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
beforeMount () {
|
|
|
|
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-02-27 04:17:53 +00:00
|
|
|
return this.$slots.default[0]
|
2018-02-23 08:14:59 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|