2019-01-12 03:33:27 +00:00
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import * as moment from 'moment';
|
|
|
|
import interopDefault from '../_util/interopDefault';
|
|
|
|
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;
|
|
|
|
// }
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
function setMomentLocale(locale) {
|
2018-02-23 08:14:59 +00:00
|
|
|
if (locale && locale.locale) {
|
2019-01-12 03:33:27 +00:00
|
|
|
interopDefault(moment).locale(locale.locale);
|
2018-02-23 08:14:59 +00:00
|
|
|
} else {
|
2019-01-12 03:33:27 +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({}),
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
data() {
|
2018-02-23 08:14:59 +00:00
|
|
|
return {
|
|
|
|
antLocale: {
|
|
|
|
...this.locale,
|
|
|
|
exist: true,
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-02-23 08:14:59 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
provide() {
|
2018-03-15 14:21:25 +00:00
|
|
|
return {
|
|
|
|
localeData: this.$data,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-15 14:21:25 +00:00
|
|
|
},
|
2018-02-23 08:14:59 +00:00
|
|
|
watch: {
|
2019-01-12 03:33:27 +00:00
|
|
|
locale(val) {
|
2018-03-15 14:21:25 +00:00
|
|
|
this.antLocale = {
|
|
|
|
...this.locale,
|
|
|
|
exist: true,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-12-13 13:26:21 +00:00
|
|
|
this.$nextTick(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
setMomentLocale(val);
|
|
|
|
});
|
2018-02-23 08:14:59 +00:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
created() {
|
|
|
|
const { locale } = this;
|
|
|
|
setMomentLocale(locale);
|
|
|
|
changeConfirmLocale(locale && locale.Modal);
|
2018-02-23 08:14:59 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
updated() {
|
|
|
|
const { locale } = this;
|
|
|
|
changeConfirmLocale(locale && locale.Modal);
|
2018-02-23 08:14:59 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
beforeDestroy() {
|
|
|
|
changeConfirmLocale();
|
2018-02-23 08:14:59 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
return this.$slots.default ? this.$slots.default[0] : null;
|
2018-02-23 08:14:59 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-02-23 08:14:59 +00:00
|
|
|
|
2018-09-19 05:21:57 +00:00
|
|
|
/* istanbul ignore next */
|
2019-01-12 03:33:27 +00:00
|
|
|
LocaleProvider.install = function(Vue) {
|
|
|
|
Vue.component(LocaleProvider.name, LocaleProvider);
|
|
|
|
};
|
2018-09-19 05:21:57 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export default LocaleProvider;
|