Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
micro-customization-system
/
system
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 9acd1ca4
authored
Aug 24, 2021
by
jack
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修复bug
1 parent
e4bbd142
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
25 deletions
src/utils/indexDb.js
src/views/vehicleTypeManage/index.vue
src/views/vehicleTypeManage/vehicleAddUpadate.vue
src/utils/indexDb.js
View file @
9acd1ca
//浏览器indexDb封装
//浏览器indexDb封装
let
_db
=
''
;
var
_db
=
''
;
let
_indexDb
=
{};
var
_dbQuest
=
''
var
_indexDb
=
{};
/**
/**
* 打开数据库、创建数据库
* 打开数据库、创建数据库
* name:数据库名称
* name:数据库名称
* version:数据库版本号
* version:数据库版本号
*/
*/
_indexDb
.
creatIndexDb
=
function
(
options
)
{
_indexDb
.
creatIndexDb
=
function
(
options
)
{
console
.
log
(
'666666666666666666666'
)
let
oParams
=
options
||
{}
let
oParams
=
options
||
{}
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
window
.
indexedDB
)
{
if
(
!
window
.
indexedDB
)
{
console
.
log
(
'您的浏览器暂时不支持indexDb'
);
console
.
log
(
'您的浏览器暂时不支持indexDb'
);
return
false
;
return
false
;
}
}
_db
=
window
.
indexedDB
.
open
(
oParams
.
name
||
'cookie'
,
oParams
.
version
||
1
);
let
databaseName
=
oParams
.
name
||
'cookie'
;
let
version
=
oParams
.
version
||
1
;
_db
=
window
.
indexedDB
.
open
(
databaseName
,
version
);
console
.
log
(
_db
)
// 监听数据库打开失败、连接失败
// 监听数据库打开失败、连接失败
_db
.
onerror
=
function
(
event
)
{
_db
.
onerror
=
function
(
event
)
{
...
@@ -26,27 +31,25 @@ let _indexDb = {};
...
@@ -26,27 +31,25 @@ let _indexDb = {};
// if (oParams.onerror) {
// if (oParams.onerror) {
// (oParams.onerror)(event)
// (oParams.onerror)(event)
// }
// }
reject
(
event
)
}
}
// 监听数据库打开成功
// 监听数据库打开成功
_db
.
success
=
function
(
event
)
{
_db
.
on
success
=
function
(
event
)
{
console
.
log
(
_db
.
resul
t
)
console
.
log
(
even
t
)
console
.
log
(
'打开成功'
);
console
.
log
(
'打开成功'
);
_dbQuest
=
event
.
result
// if (oParams.success) {
// if (oParams.success) {
// (oParams.success)(event)
// (oParams.success)(event)
// }
// }
resolve
(
event
)
}
}
// 监听数据库升级事件
// 监听数据库升级事件
_db
.
upgradeneeded
=
function
(
event
)
{
_db
.
upgradeneeded
=
function
(
event
)
{
console
.
log
(
'监听数据库升级事件'
)
// if (oParams.upgradeneeded) {
// if (oParams.upgradeneeded) {
// (oParams.upgradeneeded)(event)
// (oParams.upgradeneeded)(event)
// }
// }
resolve
(
event
)
}
}
})
}
}
/**
/**
...
@@ -55,16 +58,40 @@ let _indexDb = {};
...
@@ -55,16 +58,40 @@ let _indexDb = {};
* data:存入数据库的值
* data:存入数据库的值
*
*
*/
*/
_indexDb
.
addItem
=
function
(
key
,
data
)
{
_indexDb
.
addItem
=
function
(
key
,
data
)
{
if
(
!
_db
)
{
if
(
!
_db
)
{
this
.
creatIndexDb
().
then
(
res
=>
{
this
.
creatIndexDb
().
then
(
res
=>
{
var
request
=
db
.
transaction
([
'cookie'
],
'readwrite'
)
var
request
=
_dbQuest
.
transaction
([
'cookie'
],
'readwrite'
)
.
objectStore
(
'person'
)
.
objectStore
(
'person'
)
.
put
({
id
:
1
,
name
:
'李四'
,
age
:
35
,
email
:
'lisi@example.com'
})
.
put
({
id
:
1
,
name
:
'李四'
,
age
:
35
,
email
:
'lisi@example.com'
})
request
.
onsuccess
=
function
(
event
)
{
console
.
log
(
'数据更新成功'
);
};
});
});
}
}
console
.
log
(
_dbQuest
)
var
request
=
_dbQuest
.
transaction
([
'cookie'
],
'readwrite'
)
.
objectStore
(
'person'
)
.
put
({
id
:
1
,
name
:
'李四'
,
age
:
35
,
email
:
'lisi@example.com'
})
request
.
onsuccess
=
function
(
event
)
{
console
.
log
(
'数据更新成功2'
);
};
}
/**
* 获取数据
*/
_indexDb
.
getItem
=
function
(
key
)
{
var
request
=
_db
.
transaction
([
'cookie'
],
'readwrite'
)
.
objectStore
(
'person'
)
.
get
(
'person'
);
request
.
onsuccess
=
function
(
event
)
{
console
.
log
(
event
);
};
}
}
...
@@ -72,6 +99,7 @@ let _indexDb = {};
...
@@ -72,6 +99,7 @@ let _indexDb = {};
// 暴露方法
// 暴露方法
export
const
creatIndexDb
=
_indexDb
.
creatIndexDb
;
export
const
creatIndexDb
=
_indexDb
.
creatIndexDb
;
export
const
addItem
=
_indexDb
.
addItem
;
export
const
addItem
=
_indexDb
.
addItem
;
export
const
getItem
=
_indexDb
.
getItem
;
src/views/vehicleTypeManage/index.vue
View file @
9acd1ca
<
template
>
<
template
>
<div
class=
"system-container"
>
<div
class=
"system-container"
>
<!--
<button
@
click=
"open()"
>
创建
</button>
<button
@
click=
"add()"
>
添加数据
</button>
<button
@
click=
"read()"
>
读取数据
</button>
-->
<div
class=
"container"
>
<div
class=
"container"
>
<search-form
<search-form
class=
"searchTop border-shadow"
class=
"searchTop border-shadow"
...
@@ -75,7 +79,7 @@
...
@@ -75,7 +79,7 @@
<
script
>
<
script
>
import
{
getTableList
,
delelteTableRowData
}
from
"services/vehicletype"
;
import
{
getTableList
,
delelteTableRowData
}
from
"services/vehicletype"
;
import
{
creatIndexDb
,
add
Item
}
from
'@/utils/indexDb'
// import {creatIndexDb,addItem,get
Item} from '@/utils/indexDb'
export
default
{
export
default
{
name
:
"vehicleTypeManage"
,
name
:
"vehicleTypeManage"
,
data
()
{
data
()
{
...
@@ -157,8 +161,8 @@ export default {
...
@@ -157,8 +161,8 @@ export default {
},
},
mounted
()
{
mounted
()
{
console
.
log
(
this
.
$store
.
state
)
console
.
log
(
this
.
$store
.
state
)
creatIndexDb
();
//
creatIndexDb();
addItem
()
//
addItem()
},
},
activated
()
{},
activated
()
{},
methods
:
{
methods
:
{
...
@@ -232,6 +236,20 @@ export default {
...
@@ -232,6 +236,20 @@ export default {
};
};
this
.
$Common
.
confirmDialog
(
tipData
);
this
.
$Common
.
confirmDialog
(
tipData
);
},
},
// open
open
(){
creatIndexDb
();
},
add
(){
addItem
()
},
read
(){
getItem
()
}
},
},
};
};
</
script
>
</
script
>
...
...
src/views/vehicleTypeManage/vehicleAddUpadate.vue
View file @
9acd1ca
...
@@ -145,18 +145,17 @@ export default {
...
@@ -145,18 +145,17 @@ export default {
if
(
n
&&
n
.
length
>
0
)
{
if
(
n
&&
n
.
length
>
0
)
{
// console.log(n,"浏览器存储");
// console.log(n,"浏览器存储");
//_this.flatData(n);
//_this.flatData(n);
_this
.
mainWorker
(
n
).
then
(
res
=>
{
_this
.
mainWorker
(
n
).
then
(
(
res
)
=>
{
_this
.
showTree
=
true
;
_this
.
showTree
=
true
;
_this
.
loading
=
false
;
_this
.
loading
=
false
;
if
(
o
.
id
)
{
_this
.
getInfo
(
o
.
id
);
}
});
});
return
false
;
return
false
;
}
}
_this
.
getMenuTree
();
_this
.
getMenuTree
();
},
10
);
},
10
);
if
(
o
.
id
)
{
this
.
getInfo
(
o
.
id
);
}
},
},
activated
()
{
activated
()
{
let
_this
=
this
;
let
_this
=
this
;
...
@@ -312,7 +311,8 @@ export default {
...
@@ -312,7 +311,8 @@ export default {
// 保存车型库
// 保存车型库
_this
.
aloading
=
true
;
_this
.
aloading
=
true
;
addVehicleType
(
params
).
then
((
res
)
=>
{
addVehicleType
(
params
)
.
then
((
res
)
=>
{
_this
.
aloading
=
false
;
_this
.
aloading
=
false
;
if
(
res
.
code
!=
200
)
{
if
(
res
.
code
!=
200
)
{
_this
.
$message
.
error
(
res
.
message
||
res
.
msg
);
_this
.
$message
.
error
(
res
.
message
||
res
.
msg
);
...
@@ -325,7 +325,8 @@ export default {
...
@@ -325,7 +325,8 @@ export default {
});
});
_this
.
goBack
();
_this
.
goBack
();
}).
catch
(
error
=>
{
})
.
catch
((
error
)
=>
{
_this
.
aloading
=
false
;
_this
.
aloading
=
false
;
});
});
});
});
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment