Skip to content

Commit

Permalink
Merge pull request #626 from JQinglong/feature/generateid
Browse files Browse the repository at this point in the history
クラスID生成多言語対応
  • Loading branch information
kaizumaki authored May 22, 2021
2 parents 62b6e26 + 7b39670 commit 0629b6c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/pages/user/registerClass.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default Vue.extend({
.registerClass({
schoolName: this.schoolName,
className: this.className,
locale: this.$i18n.locale,
})
.then(() => {
this.loading = false
Expand Down
23 changes: 19 additions & 4 deletions src/store/modules/classData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,22 @@ const VuexModule = createModule({
target: 'nuxt',
})

const generateUniqueId = (): string => {
const c =
'あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん'
const generateUniqueId = (locale: string): string => {
let c: string = ''
switch (locale) {
case 'ja':
c =
'あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん'
break
case 'en':
c = 'abcdefghijklmnopqrstuvwxyz'
break
case 'zh-tw':
c =
'ㄅㄆㄇㄈㄉㄊㄋㄌㄍㄎㄏㄐㄑㄒㄓㄔㄕㄖㄗㄘㄙㄧㄨㄩㄚㄛㄜㄝㄞㄟㄠㄡㄢㄣㄤㄥㄦ'
break
}

const cl = c.length
const result =
c[Math.floor(Math.random() * cl)] +
Expand Down Expand Up @@ -237,17 +250,19 @@ export class ClassDataStore extends VuexModule implements classData.ClassData {
public async registerClass({
className,
schoolName,
locale,
}: {
className: string
schoolName: string
locale: string
}) {
if (!vxm.user.isAuthenticated) {
throw new Error('ユーザーが正しくログインされていません')
}

let classId, classObject
do {
classId = generateUniqueId()
classId = generateUniqueId(locale)
try {
const result = (await API.graphql({
query: getClassSimple,
Expand Down

0 comments on commit 0629b6c

Please sign in to comment.