From 4dd839bc279ec09d7f1b07aa890311545a6be815 Mon Sep 17 00:00:00 2001 From: douzhuo <17611323298@163.com> Date: Thu, 18 Aug 2022 18:38:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A5=BC=E7=9B=98=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/main.js | 9 +- src/page/wel.vue | 2 - src/store/modules/indexedDb.js | 1 + src/util/indexedDb.js | 206 ------- src/util/indexedDb/index.js | 19 + src/util/indexedDb/indexedDB.js | 148 +++++ src/util/indexedDb/table.js | 86 +++ src/util/table.js | 87 --- src/views/Customer/AgentManagement.vue | 717 ++++++++++++++--------- src/views/Customer/CompanyRecord.vue | 649 +++++++++++++------- src/views/Customer/Companymanagement.vue | 370 ++++++++---- src/views/Customer/table.js | 212 +++++++ src/views/building/area.vue | 158 +++-- src/views/building/index.vue | 157 ++--- src/views/building/table.js | 34 +- 16 files changed, 1789 insertions(+), 1067 deletions(-) create mode 100644 src/store/modules/indexedDb.js delete mode 100644 src/util/indexedDb.js create mode 100644 src/util/indexedDb/index.js create mode 100644 src/util/indexedDb/indexedDB.js create mode 100644 src/util/indexedDb/table.js delete mode 100644 src/util/table.js create mode 100644 src/views/Customer/table.js diff --git a/package.json b/package.json index 896f3af..3c5b76d 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "less-loader": "^6.0.0", "nprogress": "^0.2.0", "pizzip": "^3.1.1", + "promise-indexeddb": "^1.0.4", "quill": "^1.3.7", "script-loader": "^0.7.2", "sockjs-client": "1.0.0", diff --git a/src/main.js b/src/main.js index 701a505..a549bf5 100644 --- a/src/main.js +++ b/src/main.js @@ -20,13 +20,8 @@ import AvueFormDesign from '@sscfaith/avue-form-design' import basicContainer from './components/basic-container/main' import api from './api' import AvueUeditor from 'avue-plugin-ueditor' -import indexDb from './util/indexedDb' +import './util/indexedDb/index' -let storeName = { name: 'tableOption', key: 'tableIdName' } // name 表名 key 主键 -indexDb.openDB('hxz', 1, storeName, function(db) { - Vue.prototype.$tableDb = db - Vue.prototype.$indexDb = indexDb -}) Vue.use(AvueUeditor); import VueQuillEditor from 'vue-quill-editor' //vue-quill-editor其它文件可在应用页面直接引入 @@ -81,8 +76,6 @@ iconfontVersion.forEach(ele => { Vue.config.productionTip = false import APlayer from '@moefe/vue-aplayer'; -import tableOption from './util/table' -Vue.prototype.$tableOption = tableOption Vue.use(APlayer, { productionTip: true, diff --git a/src/page/wel.vue b/src/page/wel.vue index 48bb7c9..e7eae00 100644 --- a/src/page/wel.vue +++ b/src/page/wel.vue @@ -2189,8 +2189,6 @@ export default { }, mounted() { - console.log(this.$tableOption) - console.log(this.$tableOption, '多久啊开始了的接口撒了就的克拉斯绝地狂龙撒') this.role = localStorage.getItem("orgType"); if (this.role == 3) { this.houseId = localStorage.getItem("houseId"); diff --git a/src/store/modules/indexedDb.js b/src/store/modules/indexedDb.js new file mode 100644 index 0000000..407bbab --- /dev/null +++ b/src/store/modules/indexedDb.js @@ -0,0 +1 @@ +import { getStore, removeStore ,setStore } from '@/util/store' diff --git a/src/util/indexedDb.js b/src/util/indexedDb.js deleted file mode 100644 index 02088a2..0000000 --- a/src/util/indexedDb.js +++ /dev/null @@ -1,206 +0,0 @@ -export default { - // indexedDB 兼容 - indexedDB: window.indexedDB || window.webkitindexedDB || window.msIndexedDB || window.mozIndexedDB, - - /** - * 打开数据库 - * 新对象存储空间newStore参数:name、key - * 新增对象存储空间要更改数据库版本 - * @param {数据库名称} dbname - * @param {版本} version - * @param {数据库} db - * @param {配置} newStore - * @param {回调函数} callback - * */ - openDB(dbname, version, newStore, callback) { - let db - version = version || 1; - const request = this.indexedDB.open(dbname, version); - - // 打开失败回调 - request.onerror = function () { - throw "IndexedDb数据库打开错误" - } - - // 打开成功回调 - request.onsuccess = function (event) { - db = event.target.result; - if (callback && (typeof callback === 'function')) { - callback(db); - } - } - - // 调用创建新的存储空间 - request.onupgradeneeded = function (event) { - db = event.target.result; - if (newStore) { - if (!db.objectStoreNames.contains(newStore.name)) { - const objectStore = db.createObjectStore(newStore.name, { - keyPath: newStore.key - }, { - unique: false, - autoIncrement: true - }) - // newStore.index.forEach(item => { - // objectStore.createIndex(`${item}`, item, { - // unique: false, - // autoIncrement: true - // }) - // }) - } - } - } - }, - - /** - * 删除数据库 - * @params {*} dbname - * @params {*} callback - * */ - deleteDb(dbname, callback) { - const deleteQuest = this.indexedDB.deleteDatabase(dbname); - deleteQuest.onerror = function () { - throw "删除数据库出错"; - } - - deleteQuest.onsuccess = function () { - if (callback && (typeof callback === 'function')) { - callback(); - } - } - }, - - /** - * 关闭数据库 - * @params {*} dbname - * */ - closeDB(dbname) { - dbname.close(); - }, - - /** - * 删除数据 - * @params {*} db - * @params {*} storename - * @params {*} key - * @params {*} callback - * */ - deleteData(db, storename, key, callback) { - const store = db.transaction(storename, 'readwrite').objectStore(storename) - const request = store.delete(key); - request.onsuccess = function () { - if (callback && (typeof callback === 'function')) { - callback(`删除${storename}成功`) - } - } - request.onerror = function () { - if (callback && (typeof callback === 'function')) { - callback(`删除${storename}失败`) - } - } - }, - - - /** - * 清空数据 - * @params {*} db - * @params {*} storename - * @params {*} callback - * */ - clearData(db, storename, callback) { - const store = db.transaction(storename, 'readwrite').objectStore(storename); - const request = store.clear(); - - request.onsuccess = function () { - if (callback && (typeof callback === 'function')) { - callback(`清空${storename}成功`) - } - } - request.onerror = function () { - if (callback && (typeof callback === 'function')) { - callback(`清空${storename}失败`) - } - } - }, - - - /** - * 添加数据 - * @params {*} db - * @params {*} storename - * @params {*} obj - * */ - addData(db, storename, obj) { - const store = db.transaction(storename, 'readwrite').objectStore(storename); - const request = store.add(obj); - request.onsuccess = function () { - console.log(`写入${storename}数据成功`) - } - request.onerror = function (e) { - console.log(`写入${storename}数据失败`) - console.log(e) - } - }, - - /** - * 更新数据 - * @params {*} db - * @params {*} storename - * @params {*} obj - * */ - updateData(db, storename, obj) { - const store = db.transaction(storename, 'readwrite').objectStore(storename); - const request = store.put(obj); - request.onsuccess = function () { - console.log(`更新${storename}数据成功`) - } - request.onerror = function () { - console.log(`更新${storename}数据失败`) - } - }, - - /** - * 根据主键获取数据 - * @params {*} db - * @params {*} storename - * @params {*} key - * @return - * */ - getData(db, storename, key) { - const store = db.transaction(storename, 'readwrite').objectStore(storename); - const request = store.get(key); - request.onerror = function () { - console.log(`获取${storename} 里主键 ${key} 的数据失败`) - } - return new Promise(resolve => { - request.onsuccess = function (e) { - resolve(e.target.result) - } - }) - }, - - /** - * 获取全部数据 - * @params {*} db - * @params {*} storename - * @return - * */ - getAllData(db, storename) { - const store = db.transaction(storename, 'readwrite').objectStore(storename); - const request = store.openCursor(); - - let data = []; - return new Promise(resolve => { - request.onsuccess = function (e) { - let cursor = e.target.result; - if (cursor) { - data.push(cursor.value); - cursor.continue(); - } else { - resolve(data) - } - } - }) - }, - -} \ No newline at end of file diff --git a/src/util/indexedDb/index.js b/src/util/indexedDb/index.js new file mode 100644 index 0000000..cafdb67 --- /dev/null +++ b/src/util/indexedDb/index.js @@ -0,0 +1,19 @@ +import Vue from 'vue' +import tableOption from './table' +import IndexDBCache from './indexedDB' + +//初始化数据库 +const indexDb = new IndexDBCache() +indexDb.initDB().then(async(res) => { + if (res.type == 'upgradeneeded') { + console.log('indexDB 数据库创建或更新成功!') + } else { + console.log('indexDB 数据库初始化成功!') + } +}).catch((err) => { + console.log('indexDB 数据库初始化失败! ', err) +}) + + +Vue.prototype.$db = indexDb +Vue.prototype.$tableOption = tableOption \ No newline at end of file diff --git a/src/util/indexedDb/indexedDB.js b/src/util/indexedDb/indexedDB.js new file mode 100644 index 0000000..daa4814 --- /dev/null +++ b/src/util/indexedDb/indexedDB.js @@ -0,0 +1,148 @@ +const indexDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB +class IndexDBCache { + // 构造函数 + constructor() { + this._db = null //数据库 + this._transaction = null //事务 + this._request = null + this._dbName = 'hxz' //数据库名 + this._cacheTableName = 'tableOption' //表名 + this._keyPath = 'tableIdName' + this._dbversion = 1 //数据库版本 + } + + // 初始化数据库 + initDB() { + return new Promise((resolve, reject) => { + this._request = indexDB.open(this._dbName, this._dbversion) // 打开数据库 + // 数据库初始化成功 + this._request.onsuccess = (event) => { + this._db = this._request.result + resolve(event) + } + // 数据库初始化失败 + this._request.onerror = (event) => { + reject(event) + } + // 数据库初次创建或更新时会触发 + this._request.onupgradeneeded = (event) => { + let db = this._request.result + if (!db.objectStoreNames.contains(this._cacheTableName)) { + db.createObjectStore(this._cacheTableName, { + keyPath: this._keyPath, // 设置主键 + }) + } + resolve(event) + } + }) + } + + /** + * @description : 新增数据 + * @param {Object} params { tableName, optionData } //两个参数 + * @return {*} + */ + addData(params) { + params.optionData = JSON.stringify(params.optionData, this.serialize) + return new Promise((resolve, reject) => { + let transaction = this._db.transaction(this._cacheTableName, 'readwrite') + let store = transaction.objectStore(this._cacheTableName) + let response = store.add(params) + // 操作成功 + response.onsuccess = (event) => { + resolve(event) + } + // 操作失败 + response.onerror = (event) => { + reject(event) + } + }) + } + + // 通过主键读取数据 + getDataByKey(key) { + return new Promise((resolve, reject) => { + let transaction = this._db.transaction(this._cacheTableName) + let objectStore = transaction.objectStore(this._cacheTableName) + // 通过主键读取数据 + let request = objectStore.get(key) + // 操作成功 + request.onsuccess = () => { + console.log('拿到数据了') + request.result.optionData = JSON.parse(request.result.optionData, this.deserialize) + resolve(request.result) + } + // 操作失败 + request.onerror = (event) => { + console.log('获取失败') + reject(event) + } + }) + } + + /** + * @description : 更新数据 + * @param {Object} params + * @return {*} + */ + upDate(params) { + params.optionData = JSON.stringify(params.optionData, this.serialize) + return new Promise((resolve, reject) => { + let transaction = this._db.transaction(this._cacheTableName, 'readwrite') + let store = transaction.objectStore(this._cacheTableName) + let response = store.put(params) + // 操作成功 + response.onsuccess = (event) => { + resolve(event) + } + // 操作失败 + response.onerror = (event) => { + reject(event) + } + }) + } + + // 获取所有数据 + getAllDate() { + return new Promise((resolve, reject) => { + let transaction = this._db.transaction(this._cacheTableName, 'readwrite') + let store = transaction.objectStore(this._cacheTableName) + let response = store.getAll() + // 操作成功 + response.onsuccess = (event) => { + console.log(event, 'adsklasjdkalsjdklasjdklasjkdls') + resolve(event) + } + // 操作失败 + response.onerror = (event) => { + reject(event) + } + }) + } + + + + + // 使用string调用 JSON.stringify(obj, serialize) + serialize(key, value) { + if (typeof value === 'function') { + return value.toString(); + } + return value; + } + + // 使用parse调用 JSON.parse(obj, deserialize) + deserialize(key, value) { + if (value && typeof value === "string" && value.substr(0, 8) == "function") { + var startBody = value.indexOf('{') + 1; + var endBody = value.lastIndexOf('}'); + var startArgs = value.indexOf('(') + 1; + var endArgs = value.indexOf(')'); + + return new Function(value.substring(startArgs, endArgs), value.substring(startBody, endBody)); + } + return value; + } + +} +export default IndexDBCache \ No newline at end of file diff --git a/src/util/indexedDb/table.js b/src/util/indexedDb/table.js new file mode 100644 index 0000000..b2f6a0c --- /dev/null +++ b/src/util/indexedDb/table.js @@ -0,0 +1,86 @@ +// 公共配置项,示例 +const publicOption = { + // CustomerAgentManagement: { + // border: true, + // index: true, + // height: 527, + // indexLabel: "序号", + // stripe: true, + // menuAlign: "center", + // menuWidth: 250, + // menu: false, + // align: "center", + // refreshBtn: false, + // showColumnBtn: false, + // searchSize: "mini", + // searchMenuSpan: 9, + // delBtn: false, + // addBtn: false, + // editBtn: false, + // viewBtn: true, + // size: "small", + // column: [ + // { + // label: "操作人", + // prop: "name", + // search: true + // }, + // { + // label: "操作手机", + // prop: "createBy", + // search: true + // }, + // { + // label: "登录IP", + // prop: "remoteAddr" + // }, + // { + // label: "操作时间", + // prop: "createTime", + // }, + // { + // label: "操作类型", + // prop: "type", + // dicData: [{ + // label: '新增管理', + // value: "0" + // }, { + // label: '编辑项目', + // value: "1" + // }, { + // label: '删除项目', + // value: "2" + // }, { + // label: '新增公司', + // value: "3" + // }, { + // label: '编辑公司', + // value: "4" + // }, { + // label: '删除公司', + // value: "5" + // }, { + // label: '新增代理商', + // value: "6" + // }, { + // label: '系统运营', + // value: '7' + // }] + // }, + // { + // label: '操作内容', + // prop: 'title', + // search: true + // } + // ] + // } +} + +const modulesFiles = require.context('@/views',true,/\.js$/); +const modules = modulesFiles.keys().reduce((modules, modulePath) => { + const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1'); + const value = modulesFiles(modulePath); + Object.assign(modules, value.default); + return modules; +}, publicOption); +export default modules; \ No newline at end of file diff --git a/src/util/table.js b/src/util/table.js deleted file mode 100644 index dada9e7..0000000 --- a/src/util/table.js +++ /dev/null @@ -1,87 +0,0 @@ -// 公共配置项,示例 -const publicOption = { - CustomerAgentManagement: { - tableIdName: 'CustomerAgentManagement', - border: true, - index: true, - height: 527, - indexLabel: "序号", - stripe: true, - menuAlign: "center", - menuWidth: 250, - menu: false, - align: "center", - refreshBtn: false, - showColumnBtn: false, - searchSize: "mini", - searchMenuSpan: 9, - delBtn: false, - addBtn: false, - editBtn: false, - viewBtn: true, - size: "small", - column: [ - { - label: "操作人", - prop: "name", - search: true - }, - { - label: "操作手机", - prop: "createBy", - search: true - }, - { - label: "登录IP", - prop: "remoteAddr" - }, - { - label: "操作时间", - prop: "createTime", - }, - { - label: "操作类型", - prop: "type", - dicData: [{ - label: '新增管理', - value: "0" - }, { - label: '编辑项目', - value: "1" - }, { - label: '删除项目', - value: "2" - }, { - label: '新增公司', - value: "3" - }, { - label: '编辑公司', - value: "4" - }, { - label: '删除公司', - value: "5" - }, { - label: '新增代理商', - value: "6" - }, { - label: '系统运营', - value: '7' - }] - }, - { - label: '操作内容', - prop: 'title', - search: true - } - ] - } -} - -const modulesFiles = require.context('@/views',true,/\.js$/); -const modules = modulesFiles.keys().reduce((modules, modulePath) => { - const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1'); - const value = modulesFiles(modulePath); - Object.assign(modules, value.default); - return modules; -}, publicOption); -export default modules; \ No newline at end of file diff --git a/src/views/Customer/AgentManagement.vue b/src/views/Customer/AgentManagement.vue index 566eb7b..9592eda 100644 --- a/src/views/Customer/AgentManagement.vue +++ b/src/views/Customer/AgentManagement.vue @@ -5,324 +5,471 @@
合同结束日期:
- +
服务状态:
- - + +
地区:
- +
代理商名称:
- +
运营人员:
- - + +
-
+
-
- 筛选 +
+ 筛选 +
+
+ 清空筛选条件 +
-
- 清空筛选条件 +
+ 新增
-
- 新增 -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
+ + +
- - + + - + - + - + - + - - - + - + - - + - + - -
+
筛选相关:
@@ -56,18 +66,92 @@ 筛选
- 清空筛选条件 + 清空筛选条件
- 新增 + 新增
- + + + + - - - - -
+ --> +
- - - - - - + + - + - + - + - + - - + - - + - + -