Skip to content

Commit

Permalink
feat(roll-tools-api): add single qrcode generate demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Aysnine committed Feb 1, 2020
1 parent 248b07e commit 52d5728
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/api/roll-tools-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ export const client = () => {
},
address: {
list: () => instance.get('/address/list')
},
qrcode: {
single: (content, { size = 500, type = 1 } = {}) =>
instance.get('/qrcode/create/single', {
params: {
content,
size,
type
}
})
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/locales/main/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,8 @@
"admin.login.rules.password.required": "password is required",
"admin.login.rules.username.range": "username must be between {min} and {max} characters",
"admin.login.rules.password.range": "password must be between {min} and {max} characters",
"admin.logout": "Logout"
"admin.logout": "Logout",
"QR Code": "QR Code",
"admin.roll-tools-api.qrcode.placeholder.content": "Please input content",
"admin.roll-tools-api.qrcode.generate": "Generate"
}
5 changes: 4 additions & 1 deletion src/locales/main/lang/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,8 @@
"admin.login.rules.password.required": "请填写密码",
"admin.login.rules.username.range": "用户名在 {min} 到 {max} 个字符内",
"admin.login.rules.password.range": "密码在 {min} 到 {max} 个字符内",
"admin.logout": "退出登陆"
"admin.logout": "退出登陆",
"QR Code": "二维码",
"admin.roll-tools-api.qrcode.placeholder.content": "请输入内容",
"admin.roll-tools-api.qrcode.generate": "立即生成"
}
1 change: 1 addition & 0 deletions src/routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const routes = app => {
'roll-tools-api/china-cities',
'roll-tools-api/fuli-images',
'roll-tools-api/ip-address',
'roll-tools-api/qrcode',
'some-icon',
'development',
'forbidden',
Expand Down
4 changes: 4 additions & 0 deletions src/store/modules/admin/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export const createMenu = () => [
label: 'China Cities',
index: `${pathPrefix}/roll-tools-api/china-cities`
},
{
label: 'QR Code',
index: `${pathPrefix}/roll-tools-api/qrcode`
},
{
label: 'Fuli Images',
index: `${pathPrefix}/roll-tools-api/fuli-images`
Expand Down
86 changes: 86 additions & 0 deletions src/views/admin/roll-tools-api/qrcode/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<template>
<page-container>
<template #header>
<h2>
{{ $t('QR Code') }}
<el-link
icon="el-icon-link"
type="primary"
href="https://github.com/MZCretin/RollToolsApi#%E5%85%AB%E7%94%9F%E6%88%90%E4%BA%8C%E7%BB%B4%E7%A0%81"
target="_blank"
>{{ $t('Document link') }}</el-link
>
</h2>
</template>
<el-input
type="textarea"
:placeholder="$t('admin.roll-tools-api.qrcode.placeholder.content')"
v-model="content"
maxlength="255"
show-word-limit
/>
<p>
<el-slider
:format-tooltip="v => v + 'px'"
v-model="size"
:max="maxSize"
:min="minSize"
show-input
></el-slider>
</p>
<p>
<el-button
type="primary"
:disabled="!content.length"
@click="handleGenerate"
>{{ $t('admin.roll-tools-api.qrcode.generate') }}</el-button
>
</p>
<async
v-if="confirmed"
:api="$rta.apis.qrcode.single"
:args="confirmed"
:transform="transform"
>
<template v-slot:default="{ pending, error, data }">
<div v-if="pending">
Loading ...
</div>
<div v-else-if="error">
{{ error.message }}
</div>
<div v-else>
<el-image
:src="data.qrCodeUrl || data.qrCodeBase64"
fit="contain"
></el-image>
</div>
</template>
</async>
</page-container>
</template>

<script>
import { get } from 'lodash'
export default {
inject: ['@adminContainer'],
data() {
return {
confirmed: null,
content: '',
size: 500,
maxSize: 1024,
minSize: 100
}
},
methods: {
transform(result) {
return get(result, 'data.data', {})
},
handleGenerate() {
this.confirmed = [this.content, { size: this.size }]
}
}
}
</script>

0 comments on commit 52d5728

Please sign in to comment.