提交 fa38b268 编写于 作者: fxy060608's avatar fxy060608

Merge branch 'dev-quickapp' of https://github.com/dcloudio/uni-app into dev-quickapp

import {
invoke
} from '../../bridge'
import storage from '@system.storage'
function parseValue (value) {
const types = ['object', 'string', 'number', 'boolean', 'undefined']
try {
const object = typeof value === 'string' ? JSON.parse(value) : value
const type = object.type
if (types.indexOf(type) >= 0) {
const keys = Object.keys(object)
// eslint-disable-next-line valid-typeof
if (keys.length === 2 && 'data' in object && typeof object.data === type) {
return object.data
} else if (keys.length === 1) {
return ''
}
}
} catch (error) {}
}
export function setStorage ({
key,
data,
isSync
} = {}, callbackId) {
const type = typeof data
const value = type === 'string' ? data : JSON.stringify({
type,
data: data
})
try {
storage.set({
key,
value,
success: (res) => {
invoke(callbackId, {
errMsg: 'setStorage:ok'
})
},
fail: (data, code) => {
invoke(callbackId, {
errMsg: `setStorage:fail ${code}`
})
}
})
} catch (error) {
invoke(callbackId, {
errMsg: `setStorage:fail ${error}`
})
}
}
export function getStorage ({
key
} = {}, callbackId) {
storage.get({
key,
success: (data) => {
invoke(callbackId, {
data: parseValue(data) || data,
errMsg: 'getStorage:ok'
})
},
fail: (data, code) => {
invoke(callbackId, {
data: '',
errMsg: `getStorage:fail ${code}`
})
}
})
}
export function removeStorage ({
key
} = {}, callbackId) {
storage.delete({
key,
success: (res) => {
invoke(callbackId, {
errMsg: 'removeStorage:ok'
})
},
fail: (data, code) => {
invoke(callbackId, {
errMsg: `removeStorage:fail ${code}`
})
}
})
}
export function clearStorage (args, callbackId) {
storage.clear({
success: (res) => {
invoke(callbackId, {
errMsg: 'clearStorage:ok'
})
},
fail: (data, code) => {
invoke(callbackId, {
errMsg: `clearStorage:fail ${code}`
})
}
})
}
import {
invoke
} from '../../bridge'
import prompt from '@system.prompt'
export function showModal ({
title = '',
content = '',
showCancel = true,
cancelText = '取消',
cancelColor = '#000000',
confirmText = '确定',
confirmColor = '#3CC51F'
} = {}, callbackId) {
prompt.showDialog({
title: title,
message: content,
buttons: [
{
text: '确定',
color: confirmColor
}
],
success: (data) => {
console.log('handling callback')
invoke(callbackId, {
errMsg: 'showModal:ok',
confirm: true,
cancel: false
})
},
cancel: () => {
console.log('handling cancel')
},
fail: (data, code) => {
console.log(`handling fail, code = ${code}`)
}
})
}
......@@ -6,4 +6,10 @@ export * from './api/route/redirect-to'
export * from './api/device/clipboard'
// network
export * from './api/network/request'
export * from './api/network/request'
// storage
export * from './api/storage/storage'
// ui
export * from './api/ui/popup'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册