From 6416b40cf242340eaa163c498bd49d8103e73610 Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Mon, 29 Jul 2024 17:01:52 +0800
Subject: [PATCH] 代码优化
---
src/views/cGovernance/gridPatrolRecord.vue | 870 ++++++++++++++++++++++++++++++++-------------------------
1 files changed, 484 insertions(+), 386 deletions(-)
diff --git a/src/views/cGovernance/gridPatrolRecord.vue b/src/views/cGovernance/gridPatrolRecord.vue
index 8243539..5fd5a96 100644
--- a/src/views/cGovernance/gridPatrolRecord.vue
+++ b/src/views/cGovernance/gridPatrolRecord.vue
@@ -1,409 +1,507 @@
<!-- 巡查记录 -->
<template>
- <basic-container>
- <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page" ref="crud" @row-del="rowDel"
- v-model="form" :permission="permissionList" @row-update="rowUpdate" @row-save="rowSave"
- :before-open="beforeOpen" @search-change="searchChange" @search-reset="searchReset"
- @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange"
- @refresh-change="refreshChange" @on-load="onLoad">
- <template slot="menuLeft">
- <el-button size="small" icon="el-icon-delete" plain v-if="permission.article_delete" @click="handleDelete">删
- 除
- </el-button>
- </template>
+ <basic-container>
+ <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page" ref="crud" @row-del="rowDel"
+ v-model="form" :permission="permissionList" @row-update="rowUpdate" @row-save="rowSave" :before-open="beforeOpen"
+ @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
+ @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange" @on-load="onLoad">
+ <template slot="menuLeft">
+ <el-button size="small" icon="el-icon-delete" plain v-if="permission.article_delete" @click="handleDelete">删
+ 除
+ </el-button>
+ </template>
- <template slot-scope="{row}" slot="location">
- <span v-text="showLocation(row.location)"></span>
- </template>
+ <template slot="menuLeft">
+ <el-button type="warning" size="small" plain v-if="permission.household_export" icon="el-icon-download"
+ @click="handleExport">导出
+ </el-button>
+ </template>
- <template slot-scope="{row}" slot="longitude">
- <span v-text="decimalProcessing(row.longitude)"></span>
- </template>
+ <template slot-scope="{row}" slot="location">
+ <span v-text="showLocation(row.location)"></span>
+ </template>
- <template slot-scope="{row}" slot="latitude">
- <span v-text="decimalProcessing(row.latitude)"></span>
- </template>
- </avue-crud>
- </basic-container>
+ <template slot-scope="{row}" slot="longitude">
+ <span v-text="decimalProcessing(row.longitude)"></span>
+ </template>
+
+ <template slot-scope="{row}" slot="latitude">
+ <span v-text="decimalProcessing(row.latitude)"></span>
+ </template>
+ </avue-crud>
+ </basic-container>
</template>
<script>
-import { getList, remove, update, add, getGridPatrolRecord } from "@/api/grid/gridPatrolRecord"
-import { mapGetters } from "vuex"
-import website from '@/config/website'
+ import {
+ getList,
+ remove,
+ update,
+ add,
+ getGridPatrolRecord
+ } from "@/api/grid/gridPatrolRecord"
+ import {
+ mapGetters
+ } from "vuex"
+ import website from '@/config/website'
+ import {
+ exportBlob
+ } from "@/api/common"
+ import NProgress from 'nprogress'
+ import 'nprogress/nprogress.css'
+ import Qs from "qs"
+ import {
+ getToken
+ } from '@/util/auth'
+ import {
+ downloadXls
+ } from "@/util/util"
+ import {
+ dateNow
+ } from "@/util/date"
+ export default {
+ data() {
+ return {
+ form: {},
+ query: {},
+ loading: true,
+ page: {
+ pageSize: 10,
+ currentPage: 1,
+ total: 0,
+ },
+ datetime: "",
+ selectionList: [],
+ option: {
+ labelWidth: 96,
+ searchLabelWidth: 96,
+ searchShow: true,
+ searchMenuSpan: 3,
+ menuWidth: 210,
-export default {
- data () {
- return {
- form: {},
- query: {},
- loading: true,
- page: {
- pageSize: 10,
- currentPage: 1,
- total: 0,
+ height: "auto",
+ calcHeight: 54,
+ dialogWidth: 950,
+ tip: false,
+ border: true,
+ //stripe:true,
+ index: true,
+ viewBtn: true,
+ selection: true,
+ excelBtn: true,
+ dialogClickModal: false,
+ column: [{
+ width: 96,
+ searchLabelWidth: 80,
+ searchSpan: 4,
+ addDisplay: false,
+ editDisplay: false,
+ viewDisplay: false,
+ label: "所属街道",
+ prop: "townStreetName",
+ search: true,
+ type: "tree",
+ dicUrl: "/api/blade-system/region/getTownTree",
+ props: {
+ label: "name",
+ value: "name"
+ },
+ rules: [{
+ required: true,
+ message: "请选择所属街道",
+ trigger: "blur",
+ }, ],
},
- datetime: "",
- selectionList: [],
- option: {
- labelWidth: 96,
- searchLabelWidth: 96,
- searchShow: true,
- searchMenuSpan: 3,
- menuWidth: 210,
-
- height: "auto",
- calcHeight: 54,
- dialogWidth: 950,
- tip: false,
- border: true,
- //stripe:true,
- index: true,
- viewBtn: true,
- selection: true,
- excelBtn: true,
- dialogClickModal: false,
- column: [
- {
- label: "巡查标题",
- prop: "name",
- span: 24,
- row: true,
- searchSpan: 4,
- search: true,
- searchLabelWidth: 76,
- rules: [
- {
- required: true,
- message: "请输入巡查标题",
- trigger: "blur",
- },
- ],
- },
- {
- label: "巡查内容",
- prop: "context",
- type: "textarea",
- span: 24,
- },
-
- {
- overHidden: true,
- slot: true,
- label: "巡查地址",
- prop: "location",
- type: 'map',
- dataType: "string",
- span: 24,
- value: [117.966460, 28.431002, ""],
- rules: [
- {
- required: true,
- message: "请选择巡查地址",
- trigger: "blur",
- },
- ],
- },
-
- {
- width: 96,
- slot: true,
- addDisplay: false,
- editDisplay: false,
- viewDisplay: false,
- label: "经度",
- prop: "longitude",
- },
-
- {
- width: 96,
- slot: true,
- addDisplay: false,
- editDisplay: false,
- viewDisplay: false,
- label: "纬度",
- prop: "latitude",
- },
-
- {
- width: 110,
- label: "巡查图片",
- prop: "url",
- type: "upload",
- listType: "picture-img",
- action: "/api/blade-resource/oss/endpoint/put-file",
- propsHttp: {
- res: "data",
- name: 'name',
- url: "link",
- },
- span: 24,
- },
- {
- width: 144,
- label: "巡查时间",
- prop: "patrolTime",
- type: "date",
- format: "yyyy-MM-dd HH:mm:ss",
- valueFormat: "yyyy-MM-dd HH:mm:ss",
- rules: [
- {
- required: true,
- message: "请输入巡查时间",
- trigger: "blur",
- },
- ],
- }
- ],
+ {
+ width: 160,
+ searchLabelWidth: 80,
+ searchSpan: 4,
+ parent: false,
+ label: "所属社区",
+ prop: "neiName",
+ search: true,
+ type: "tree",
+ dicUrl: "/api/blade-system/region/treeToCommunity",
+ props: {
+ label: "name",
+ value: "name",
+ },
+ rules: [{
+ required: true,
+ message: "请选择所属社区",
+ trigger: "blur",
+ }, ],
},
- data: [],
- }
+ {
+ width: 96,
+ searchSpan: 4,
+ searchLabelWidth: 100,
+ addDisplay: false,
+ editDisplay: false,
+ viewDisplay: false,
+ label: "巡查人名称",
+ prop: "userName",
+ search: true,
+ },
+ {
+ label: "巡查标题",
+ prop: "name",
+ span: 24,
+ row: true,
+ searchSpan: 4,
+ search: true,
+ searchLabelWidth: 76,
+ rules: [{
+ required: true,
+ message: "请输入巡查标题",
+ trigger: "blur",
+ }, ],
+ },
+ {
+ label: "巡查内容",
+ prop: "context",
+ type: "textarea",
+ span: 24,
+ },
+
+ {
+ overHidden: true,
+ slot: true,
+ label: "巡查地址",
+ prop: "location",
+ type: 'map',
+ dataType: "string",
+ span: 24,
+ value: [117.966460, 28.431002, ""],
+ rules: [{
+ required: true,
+ message: "请选择巡查地址",
+ trigger: "blur",
+ }, ],
+ },
+
+ {
+ width: 96,
+ slot: true,
+ addDisplay: false,
+ editDisplay: false,
+ viewDisplay: false,
+ label: "经度",
+ prop: "longitude",
+ },
+
+ {
+ width: 96,
+ slot: true,
+ addDisplay: false,
+ editDisplay: false,
+ viewDisplay: false,
+ label: "纬度",
+ prop: "latitude",
+ },
+
+ {
+ width: 110,
+ label: "巡查图片",
+ prop: "url",
+ type: "upload",
+ listType: "picture-img",
+ action: "/api/blade-resource/oss/endpoint/put-file",
+ propsHttp: {
+ res: "data",
+ name: 'name',
+ url: "link",
+ },
+ span: 24,
+ },
+ {
+ width: 144,
+ label: "巡查时间",
+ prop: "patrolTime",
+ type: "date",
+ format: "yyyy-MM-dd HH:mm:ss",
+ valueFormat: "yyyy-MM-dd HH:mm:ss",
+ rules: [{
+ required: true,
+ message: "请输入巡查时间",
+ trigger: "blur",
+ }, ],
+ }
+ ],
+ },
+ data: [],
+ }
},
- watch: {
- },
+ watch: {},
computed: {
- ...mapGetters(["permission", "userInfo"]),
+ ...mapGetters(["permission", "userInfo"]),
- permissionList () {
- return {
- addBtn: this.vaildData(this.permission.gridPatrolRecord_add, true),
- viewBtn: this.vaildData(this.permission.gridPatrolRecord_view, true),
- delBtn: this.vaildData(this.permission.gridPatrolRecord_delete, true),
- editBtn: this.vaildData(this.permission.gridPatrolRecord_edit, true),
- }
- },
-
- ids () {
- let ids = []
- this.selectionList.forEach((ele) => {
- ids.push(ele.id)
- })
- return ids.join(",")
- },
-
- showLocation () {
- return (data) => {
- if (data != null && data.indexOf(',') != -1) {
- data = data.split(',')
-
- return data[2]
- } else {
- return data || ''
- }
- }
- },
-
- decimalProcessing () {
- return (data) => {
- if (data != null) {
- return Number(data).toFixed(6)
- } else {
- return ''
- }
- }
+ permissionList() {
+ return {
+ addBtn: this.vaildData(this.permission.gridPatrolRecord_add, true),
+ viewBtn: this.vaildData(this.permission.gridPatrolRecord_view, true),
+ delBtn: this.vaildData(this.permission.gridPatrolRecord_delete, true),
+ editBtn: this.vaildData(this.permission.gridPatrolRecord_edit, true),
}
- },
- methods: {
- locationDispose (data) {
+ },
+
+ ids() {
+ let ids = []
+ this.selectionList.forEach((ele) => {
+ ids.push(ele.id)
+ })
+ return ids.join(",")
+ },
+
+ showLocation() {
+ return (data) => {
+ if (data != null && data.indexOf(',') != -1) {
data = data.split(',')
- return {
- longitude: data[0],
- latitude: data[1],
- location: data[2]
- }
- },
-
- rowSave (row, done, loading) {
- if (row.url.length > 0) {
- var urls = []
- var split = row.url.split(",")
- split.forEach(url => {
- var names = url.split("jczz/")
- urls.push(names[1])
- })
- row.url = urls.join(",")
- }
-
- add({
- ...row,
- ...this.locationDispose(row.location)
- }).then(
- () => {
- this.onLoad(this.page)
- this.$message({
- type: "success",
- message: "操作成功!",
- })
- done()
- },
- (error) => {
- window.console.log(error)
- loading()
- }
- )
- },
-
- rowUpdate (row, index, done, loading) {
- if (row.url.length > 0) {
- var urls = []
- var split = row.url.split(",")
- split.forEach(url => {
- var names = url.split("jczz/")
- urls.push(names[1])
- })
- row.url = urls.join(",")
- }
-
- update({
- ...row,
- ...this.locationDispose(row.location)
- }).then(
- () => {
- this.onLoad(this.page)
- this.$message({
- type: "success",
- message: "操作成功!",
- })
- done()
- },
- (error) => {
- window.console.log(error)
- loading()
- }
- )
- },
-
- rowDel (row) {
- this.$confirm("确定将选择数据删除?", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- return remove(row.id)
- })
- .then(() => {
- this.onLoad(this.page)
- this.$message({
- type: "success",
- message: "操作成功!",
- })
- })
- },
-
- searchReset () {
- this.query = {}
- this.onLoad(this.page)
- },
-
- searchChange (params, done) {
- this.query = params
- this.page.currentPage = 1
- this.onLoad(this.page, params)
- done()
- },
- selectionChange (list) {
- this.selectionList = list
- },
- selectionClear () {
- this.selectionList = []
- this.$refs.crud.toggleSelection()
- },
- handleDelete () {
- if (this.selectionList.length === 0) {
- this.$message.warning("请选择至少一条数据")
- return
- }
- this.$confirm("确定将选择数据删除?", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- return remove(this.ids)
- })
- .then(() => {
- this.onLoad(this.page)
- this.$message({
- type: "success",
- message: "操作成功!",
- })
- this.$refs.crud.toggleSelection()
- })
- },
- beforeOpen (done, type) {
- if (["edit", "view"].includes(type)) {
- getGridPatrolRecord(this.form.id).then((res) => {
- this.form = res.data.data
-
- this.form.location = [this.form.longitude, this.form.latitude, this.form.location].join(',')
-
- if (this.form.url.length > 0) {
- var urls = []
- var names = this.form.url.split(",")
- names.forEach(name => {
- urls.push(website.minioUrl + name)
- })
- this.form.url = urls.join(",")
- }
- })
- }
- // con
- done()
- },
- currentChange (currentPage) {
- this.page.currentPage = currentPage
- },
- sizeChange (pageSize) {
- this.page.pageSize = pageSize
- },
- refreshChange () {
- this.onLoad(this.page, this.query)
- },
- onLoad (page, params = {}) {
- const { dateTime } = this.query
- let values = {
- ...params,
- }
- if (dateTime) {
- values = {
- ...params,
- startTime: dateTime[0],
- endTime: dateTime[1],
- ...this.query,
- }
- values.dateTime = null
- }
- this.loading = true
- getList(page.currentPage, page.pageSize, values).then((res) => {
- const data = res.data.data
- this.page.total = data.total
- this.data = data.records
- this.data.forEach(item => {
- if (item.url.length > 0) {
- var urls = []
- var names = item.url.split(",")
- names.forEach(name => {
- urls.push(website.minioUrl + name)
- })
- item.url = urls.join(",")
- }
- })
- this.loading = false
- this.selectionClear()
- }).catch(err => {
- setTimeout(() => {
- this.loading = false
- }, 1000)
- })
+ return data[2]
+ } else {
+ return data || ''
+ }
}
+ },
+
+ decimalProcessing() {
+ return (data) => {
+ if (data != null) {
+ return Number(data).toFixed(6)
+ } else {
+ return ''
+ }
+ }
+ }
},
-}
+ methods: {
+
+ handleExport() {
+ this.$confirm("是否导出网格巡查记录数据?", "提示", {
+ confirmButtonText: "确定",
+ cancelButtonText: "取消",
+ type: "warning"
+ }).then(() => {
+ NProgress.start()
+ var data = {
+ ...this.query
+ }
+ data.isNine = 1
+ data = Qs.stringify(data)
+ exportBlob(
+ `/api/blade-gridPatrolRecord/gridPatrolRecord/export?${this.website.tokenHeader}=${getToken()}&` +
+ data
+ ).then(res => {
+ console.log('exportBlob', res)
+ downloadXls(res.data, `网格巡查记录${dateNow()}.xlsx`)
+ NProgress.done()
+ })
+ })
+ },
+
+ locationDispose(data) {
+ data = data.split(',')
+
+ return {
+ longitude: data[0],
+ latitude: data[1],
+ location: data[2]
+ }
+ },
+
+ rowSave(row, done, loading) {
+ if (row.url.length > 0) {
+ var urls = []
+ var split = row.url.split(",")
+ split.forEach(url => {
+ var names = url.split("jczz/")
+ urls.push(names[1])
+ })
+ row.url = urls.join(",")
+ }
+
+ add({
+ ...row,
+ ...this.locationDispose(row.location)
+ }).then(
+ () => {
+ this.onLoad(this.page)
+ this.$message({
+ type: "success",
+ message: "操作成功!",
+ })
+ done()
+ },
+ (error) => {
+ window.console.log(error)
+ loading()
+ }
+ )
+ },
+
+ rowUpdate(row, index, done, loading) {
+ if (row.url.length > 0) {
+ var urls = []
+ var split = row.url.split(",")
+ split.forEach(url => {
+ var names = url.split("jczz/")
+ urls.push(names[1])
+ })
+ row.url = urls.join(",")
+ }
+
+ update({
+ ...row,
+ ...this.locationDispose(row.location)
+ }).then(
+ () => {
+ this.onLoad(this.page)
+ this.$message({
+ type: "success",
+ message: "操作成功!",
+ })
+ done()
+ },
+ (error) => {
+ window.console.log(error)
+ loading()
+ }
+ )
+ },
+
+ rowDel(row) {
+ this.$confirm("确定将选择数据删除?", {
+ confirmButtonText: "确定",
+ cancelButtonText: "取消",
+ type: "warning",
+ })
+ .then(() => {
+ return remove(row.id)
+ })
+ .then(() => {
+ this.onLoad(this.page)
+ this.$message({
+ type: "success",
+ message: "操作成功!",
+ })
+ })
+ },
+
+ searchReset() {
+ this.query = {}
+ this.onLoad(this.page)
+ },
+
+ searchChange(params, done) {
+ this.query = params
+ this.page.currentPage = 1
+ this.onLoad(this.page, params)
+ done()
+ },
+ selectionChange(list) {
+ this.selectionList = list
+ },
+ selectionClear() {
+ this.selectionList = []
+ this.$refs.crud.toggleSelection()
+ },
+ handleDelete() {
+ if (this.selectionList.length === 0) {
+ this.$message.warning("请选择至少一条数据")
+ return
+ }
+ this.$confirm("确定将选择数据删除?", {
+ confirmButtonText: "确定",
+ cancelButtonText: "取消",
+ type: "warning",
+ })
+ .then(() => {
+ return remove(this.ids)
+ })
+ .then(() => {
+ this.onLoad(this.page)
+ this.$message({
+ type: "success",
+ message: "操作成功!",
+ })
+ this.$refs.crud.toggleSelection()
+ })
+ },
+ beforeOpen(done, type) {
+ if (["edit", "view"].includes(type)) {
+ getGridPatrolRecord(this.form.id).then((res) => {
+ this.form = res.data.data
+
+ this.form.location = [this.form.longitude, this.form.latitude, this.form.location].join(',')
+
+ if (this.form.url.length > 0) {
+ var urls = []
+ var names = this.form.url.split(",")
+ names.forEach(name => {
+ urls.push(website.minioUrl + name)
+ })
+ this.form.url = urls.join(",")
+ }
+ })
+ }
+ // con
+ done()
+ },
+ currentChange(currentPage) {
+ this.page.currentPage = currentPage
+ },
+ sizeChange(pageSize) {
+ this.page.pageSize = pageSize
+ },
+ refreshChange() {
+ this.onLoad(this.page, this.query)
+ },
+ onLoad(page, params = {}) {
+ const {
+ dateTime
+ } = this.query
+ let values = {
+ ...params,
+ }
+ if (dateTime) {
+ values = {
+ ...params,
+ startTime: dateTime[0],
+ endTime: dateTime[1],
+ ...this.query,
+ }
+ values.dateTime = null
+ }
+ this.loading = true
+ getList(page.currentPage, page.pageSize, values).then((res) => {
+ const data = res.data.data
+ this.page.total = data.total
+ this.data = data.records
+ this.data.forEach(item => {
+ if (item.url.length > 0) {
+ var urls = []
+ var names = item.url.split(",")
+ names.forEach(name => {
+ urls.push(website.minioUrl + name)
+ })
+ item.url = urls.join(",")
+ }
+ })
+ this.loading = false
+ this.selectionClear()
+ }).catch(err => {
+ setTimeout(() => {
+ this.loading = false
+ }, 1000)
+ })
+ }
+ },
+ }
</script>
<style>
-.avue-upload__icon {
+ .avue-upload__icon {
line-height: 6;
-}
-</style>
+ }
+</style>
\ No newline at end of file
--
Gitblit v1.9.3