小程序链接转二维码组件i18n
This commit is contained in:
parent
82279251f1
commit
24f328047d
|
|
@ -47,8 +47,10 @@ export default OakComponent({
|
|||
// 保存Base64图片到相册
|
||||
saveBase64Image(base64Data) {
|
||||
const that = this;
|
||||
const { filename } = this.props;
|
||||
const name = filename || `temp_image_${Date.now()}.png`;
|
||||
// 1. 定义文件路径
|
||||
const filePath = `${wx.env.USER_DATA_PATH}/temp_image_${Date.now()}.png`;
|
||||
const filePath = `${wx.env.USER_DATA_PATH}/${name}`;
|
||||
// 2. 获取文件系统管理器
|
||||
const fs = wx.getFileSystemManager();
|
||||
// 3. 写入临时文件
|
||||
|
|
@ -62,9 +64,9 @@ export default OakComponent({
|
|||
that.checkAuthAndSave(filePath);
|
||||
},
|
||||
fail(err) {
|
||||
console.error('写入文件失败', err);
|
||||
// console.error('写入文件失败', err);
|
||||
wx.showToast({
|
||||
title: '保存失败,写入文件时出错',
|
||||
title: that.t('Save failed, error occurred while writing file'),
|
||||
icon: 'none',
|
||||
});
|
||||
},
|
||||
|
|
@ -89,11 +91,11 @@ export default OakComponent({
|
|||
that.saveImageToAlbum(filePath);
|
||||
},
|
||||
fail(err) {
|
||||
console.error('授权失败', err);
|
||||
// console.error('授权失败', err);
|
||||
// 引导用户手动开启
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '需要您授权保存相册权限才能保存图片',
|
||||
title: that.t('tip'),
|
||||
content: that.t('You need to authorize the permission to save the album in order to save the pictures'),
|
||||
showCancel: false,
|
||||
success(modalRes) {
|
||||
if (modalRes.confirm) {
|
||||
|
|
@ -102,8 +104,8 @@ export default OakComponent({
|
|||
success(settingRes) {
|
||||
if (settingRes.authSetting['scope.writePhotosAlbum']) {
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '授权成功,请再次点击保存按钮',
|
||||
title: that.t('tip'),
|
||||
content: that.t('Authorization successful'),
|
||||
showCancel: false,
|
||||
});
|
||||
}
|
||||
|
|
@ -117,27 +119,31 @@ export default OakComponent({
|
|||
}
|
||||
},
|
||||
fail(err) {
|
||||
console.error('获取设置失败', err);
|
||||
// console.error('获取设置失败', err);
|
||||
},
|
||||
});
|
||||
},
|
||||
// 执行保存到相册的操作
|
||||
saveImageToAlbum(filePath) {
|
||||
const that = this;
|
||||
wx.saveImageToPhotosAlbum({
|
||||
filePath: filePath,
|
||||
success(res) {
|
||||
wx.showToast({
|
||||
title: '保存成功',
|
||||
title: that.t('Save successful'),
|
||||
icon: 'success',
|
||||
duration: 2000,
|
||||
});
|
||||
},
|
||||
fail(err) {
|
||||
console.error('保存到相册失败', err);
|
||||
let errMsg = '保存失败';
|
||||
// console.error('保存到相册失败', err);
|
||||
if (err.errMsg.includes('cancel')) {
|
||||
return;
|
||||
}
|
||||
let errMsg = that.t('Save fail');
|
||||
if (err.errMsg.includes('fail auth deny') ||
|
||||
err.errMsg.includes('fail:auth denied')) {
|
||||
errMsg = '相册权限被拒绝,请重新授权';
|
||||
errMsg = that.t('Album permission denied, please reauthorize');
|
||||
}
|
||||
wx.showToast({
|
||||
title: errMsg,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,12 @@
|
|||
{
|
||||
"This QR code": "该二维码",
|
||||
"effective": "前有效",
|
||||
"The QR code has expired": "该二维码已过期"
|
||||
"The QR code has expired": "该二维码已过期",
|
||||
"Save failed, error occurred while writing file": "保存失败,写入文件时出错",
|
||||
"tip": "提示",
|
||||
"You need to authorize the permission to save the album in order to save the pictures": "需要您授权保存相册权限才能保存图片",
|
||||
"Album permission denied, please reauthorize": "相册权限被拒绝,请重新授权",
|
||||
"Save fail": "保存失败",
|
||||
"Save successful": "保存成功",
|
||||
"Authorization successful": "授权成功"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,14 @@ const i18ns = [
|
|||
data: {
|
||||
"This QR code": "该二维码",
|
||||
"effective": "前有效",
|
||||
"The QR code has expired": "该二维码已过期"
|
||||
"The QR code has expired": "该二维码已过期",
|
||||
"Save failed, error occurred while writing file": "保存失败,写入文件时出错",
|
||||
"tip": "提示",
|
||||
"You need to authorize the permission to save the album in order to save the pictures": "需要您授权保存相册权限才能保存图片",
|
||||
"Album permission denied, please reauthorize": "相册权限被拒绝,请重新授权",
|
||||
"Save fail": "保存失败",
|
||||
"Save successful": "保存成功",
|
||||
"Authorization successful": "授权成功"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -48,7 +48,14 @@ const i18ns = [
|
|||
data: {
|
||||
"This QR code": "该二维码",
|
||||
"effective": "前有效",
|
||||
"The QR code has expired": "该二维码已过期"
|
||||
"The QR code has expired": "该二维码已过期",
|
||||
"Save failed, error occurred while writing file": "保存失败,写入文件时出错",
|
||||
"tip": "提示",
|
||||
"You need to authorize the permission to save the album in order to save the pictures": "需要您授权保存相册权限才能保存图片",
|
||||
"Album permission denied, please reauthorize": "相册权限被拒绝,请重新授权",
|
||||
"Save fail": "保存失败",
|
||||
"Save successful": "保存成功",
|
||||
"Authorization successful": "授权成功"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -59,11 +59,13 @@ export default OakComponent({
|
|||
// 保存Base64图片到相册
|
||||
saveBase64Image(base64Data: string) {
|
||||
const that = this;
|
||||
const { filename } = this.props;
|
||||
|
||||
const name = filename || `temp_image_${Date.now()}.png`;
|
||||
// 1. 定义文件路径
|
||||
const filePath = `${
|
||||
wx.env.USER_DATA_PATH
|
||||
}/temp_image_${Date.now()}.png`;
|
||||
}/${name}`;
|
||||
|
||||
// 2. 获取文件系统管理器
|
||||
const fs = wx.getFileSystemManager();
|
||||
|
|
@ -79,9 +81,9 @@ export default OakComponent({
|
|||
that.checkAuthAndSave(filePath);
|
||||
},
|
||||
fail(err) {
|
||||
console.error('写入文件失败', err);
|
||||
// console.error('写入文件失败', err);
|
||||
wx.showToast({
|
||||
title: '保存失败,写入文件时出错',
|
||||
title: that.t('Save failed, error occurred while writing file'),
|
||||
icon: 'none',
|
||||
});
|
||||
},
|
||||
|
|
@ -106,12 +108,11 @@ export default OakComponent({
|
|||
that.saveImageToAlbum(filePath);
|
||||
},
|
||||
fail(err) {
|
||||
console.error('授权失败', err);
|
||||
// console.error('授权失败', err);
|
||||
// 引导用户手动开启
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content:
|
||||
'需要您授权保存相册权限才能保存图片',
|
||||
title: that.t('tip'),
|
||||
content: that.t('You need to authorize the permission to save the album in order to save the pictures'),
|
||||
showCancel: false,
|
||||
success(modalRes) {
|
||||
if (modalRes.confirm) {
|
||||
|
|
@ -124,9 +125,8 @@ export default OakComponent({
|
|||
]
|
||||
) {
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content:
|
||||
'授权成功,请再次点击保存按钮',
|
||||
title: that.t('tip'),
|
||||
content: that.t('Authorization successful'),
|
||||
showCancel: false,
|
||||
});
|
||||
}
|
||||
|
|
@ -140,29 +140,35 @@ export default OakComponent({
|
|||
}
|
||||
},
|
||||
fail(err) {
|
||||
console.error('获取设置失败', err);
|
||||
// console.error('获取设置失败', err);
|
||||
},
|
||||
});
|
||||
},
|
||||
// 执行保存到相册的操作
|
||||
saveImageToAlbum(filePath: string) {
|
||||
const that = this;
|
||||
wx.saveImageToPhotosAlbum({
|
||||
filePath: filePath,
|
||||
success(res) {
|
||||
wx.showToast({
|
||||
title: '保存成功',
|
||||
title: that.t('Save successful'),
|
||||
icon: 'success',
|
||||
duration: 2000,
|
||||
});
|
||||
},
|
||||
fail(err) {
|
||||
console.error('保存到相册失败', err);
|
||||
let errMsg = '保存失败';
|
||||
// console.error('保存到相册失败', err);
|
||||
if (
|
||||
err.errMsg.includes('cancel')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
let errMsg = that.t('Save fail');
|
||||
if (
|
||||
err.errMsg.includes('fail auth deny') ||
|
||||
err.errMsg.includes('fail:auth denied')
|
||||
) {
|
||||
errMsg = '相册权限被拒绝,请重新授权';
|
||||
errMsg = that.t('Album permission denied, please reauthorize')
|
||||
}
|
||||
wx.showToast({
|
||||
title: errMsg,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,12 @@
|
|||
{
|
||||
"This QR code": "该二维码",
|
||||
"effective": "前有效",
|
||||
"The QR code has expired": "该二维码已过期"
|
||||
"The QR code has expired": "该二维码已过期",
|
||||
"Save failed, error occurred while writing file": "保存失败,写入文件时出错",
|
||||
"tip": "提示",
|
||||
"You need to authorize the permission to save the album in order to save the pictures": "需要您授权保存相册权限才能保存图片",
|
||||
"Album permission denied, please reauthorize": "相册权限被拒绝,请重新授权",
|
||||
"Save fail": "保存失败",
|
||||
"Save successful": "保存成功",
|
||||
"Authorization successful": "授权成功"
|
||||
}
|
||||
|
|
@ -48,7 +48,14 @@ const i18ns: I18n[] = [
|
|||
data: {
|
||||
"This QR code": "该二维码",
|
||||
"effective": "前有效",
|
||||
"The QR code has expired": "该二维码已过期"
|
||||
"The QR code has expired": "该二维码已过期",
|
||||
"Save failed, error occurred while writing file": "保存失败,写入文件时出错",
|
||||
"tip": "提示",
|
||||
"You need to authorize the permission to save the album in order to save the pictures": "需要您授权保存相册权限才能保存图片",
|
||||
"Album permission denied, please reauthorize": "相册权限被拒绝,请重新授权",
|
||||
"Save fail": "保存失败",
|
||||
"Save successful": "保存成功",
|
||||
"Authorization successful": "授权成功"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue