wanggang
1 year ago
15 changed files with 185 additions and 65 deletions
@ -1,13 +1,7 @@ |
|||
import { createI18n } from "vue-i18n"; |
|||
import { useAppStore } from "../store/index.js"; |
|||
import { getLocalizationAsync } from "../api/site.js"; |
|||
|
|||
function useLocale() { |
|||
const appStore = useAppStore(); |
|||
const i18n = createI18n({ |
|||
legacy: false, |
|||
...appStore.localization, |
|||
}); |
|||
return i18n; |
|||
} |
|||
const localization = await getLocalizationAsync(); |
|||
const i18n = createI18n(localization); |
|||
|
|||
export default useLocale; |
|||
export default i18n; |
|||
|
@ -0,0 +1,38 @@ |
|||
export default function () { |
|||
return { |
|||
title: "登录", |
|||
type: "object", |
|||
properties: { |
|||
currentPassword: { |
|||
title: "当前密码", |
|||
type: "string", |
|||
input: "password", |
|||
rules: [ |
|||
{ |
|||
required: true, |
|||
}, |
|||
], |
|||
}, |
|||
newPassword: { |
|||
title: "新密码", |
|||
type: "string", |
|||
input: "password", |
|||
rules: [ |
|||
{ |
|||
required: true, |
|||
}, |
|||
], |
|||
}, |
|||
newPassword2: { |
|||
title: "确认新密码", |
|||
type: "string", |
|||
input: "password", |
|||
rules: [ |
|||
{ |
|||
required: true, |
|||
}, |
|||
], |
|||
}, |
|||
}, |
|||
}; |
|||
} |
@ -0,0 +1,64 @@ |
|||
import html, { schemaToModel } from "html"; |
|||
import { reactive } from "vue"; |
|||
import AppForm from "../components/form/index.js"; |
|||
import { getUser, setAccessToken } from "../api/user.js"; |
|||
import router, { refreshRouter } from "../router/index.js"; |
|||
import request from "../request/index.js"; |
|||
import LayoutLogo from "../layouts/logo.js"; |
|||
import LayoutLocale from "../layouts/locale.js"; |
|||
import LayoutFooter from "../layouts/footer.js"; |
|||
import { useAppStore } from "../store/index.js"; |
|||
import useConfig from "../models/account.js"; |
|||
import { ElMessage } from "element-plus"; |
|||
|
|||
export default { |
|||
components: { AppForm, LayoutLogo, LayoutLocale, LayoutFooter }, |
|||
template: html`<el-container>
|
|||
<el-main class="flex justify-center"> |
|||
<div> |
|||
<div class="flex items-center justify-center"> |
|||
<layout-logo /> |
|||
<layout-locale /> |
|||
</div> |
|||
<el-card class="box-card" style="width:400px;"> |
|||
<app-form :schema="schema" v-model="model" @submit="submit"> |
|||
<template #submitText>确定</template> |
|||
</app-form> |
|||
</el-card> |
|||
<layout-footer /> |
|||
</div> |
|||
</el-main> |
|||
</el-container>`, |
|||
setup() { |
|||
const schema = useConfig(); |
|||
const model = reactive(schemaToModel(schema)); |
|||
schema.properties.newPassword2.rules.push({ |
|||
validator: (rule, value, callback) => { |
|||
if (value !== model.newPassword) { |
|||
callback(new Error("确认新密码和新密码必须一致")); |
|||
} else { |
|||
callback(); |
|||
} |
|||
}, |
|||
}); |
|||
const submit = async (callback, loading) => { |
|||
try { |
|||
const appStore = useAppStore(); |
|||
const url = `base/user/${appStore.user.id}/change-password`; |
|||
const result = await request(url, model, { method: "POST" }); |
|||
if (!result.errors) { |
|||
ElMessage.success("密码修改成功"); |
|||
} |
|||
} catch (error) { |
|||
console.log(error); |
|||
} finally { |
|||
loading.value = false; |
|||
} |
|||
}; |
|||
return { |
|||
schema, |
|||
model, |
|||
submit, |
|||
}; |
|||
}, |
|||
}; |
Loading…
Reference in new issue