Skip to content

Commit

Permalink
feat(sys-client): add ejson ObjectId & Binaray type support to dbm;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Oct 15, 2021
1 parent 4471e6f commit 0097910
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/system-client/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"typescript.updateImportsOnFileMove.enabled": "always",
// json
"[json]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
"editor.defaultFormatter": "vscode.json-language-features"
},
"cSpell.words": [
"cloudfunction"
Expand Down
64 changes: 56 additions & 8 deletions packages/system-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/system-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"axios": "^0.21.1",
"bson": "^4.5.3",
"clipboard": "2.0.4",
"element-ui": "2.13.2",
"file-saver": "2.0.1",
Expand Down
18 changes: 12 additions & 6 deletions packages/system-client/src/views/database/collections.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</el-aside>

<el-container class="record-list">
<div v-for="item in list" :key="item._id" class="record-item" :class="getClass(item)">
<div v-for="item in list" :key="item._id.toString()" class="record-item" :class="getClass(item)">
<div class="doc">
<pre class="">{{ item }}</pre>
</div>
Expand Down Expand Up @@ -158,6 +158,7 @@ import { getCollections, getCollectionIndexes, deleCollectionIndex, setCollectio
import JsonEditor from '@/components/JsonEditor/param'
import MiniPagination from '@/components/Pagination/mini'
import { showError, showSuccess } from '@/utils/show'
import { EJSON } from 'bson'
const db = getDb()
Expand Down Expand Up @@ -334,20 +335,25 @@ export default {
this.getList()
},
handleEditRecord(val) {
this.record = val
this.record = EJSON.serialize(val)
this.formMode = 'edit'
this.showDocEditorForm = true
},
async updateDocument() {
await this.$confirm('确认要更新数据?', '确认')
const record = typeof this.record === 'string' ? JSON.parse(this.record) : this.record
const { _id, ...params } = record
// 将 [EJSON字符串] 解析为 [JSON对象]
const parsed = typeof this.record === 'string' ? JSON.parse(this.record) : this.record
// 将 [JSON对象] 序列化为 [EJSON对象]
const serialized = EJSON.serialize(parsed)
const { _id, ...params } = serialized
if (!_id) return
const r = await db
.collection(this.collectionName)
.doc(_id)
.set({ ...params })
.where({ _id })
.update({ ...params })
if (r.error) {
const message = typeof r.error !== 'string' ? JSON.stringify(r.error) : r.error
Expand Down

0 comments on commit 0097910

Please sign in to comment.