123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- <template>
- <div v-loading="loading" class="container">
- <el-card v-show="false" body-style="padding: 0px;" class="dashboard-list" shadow="never">
- <!-- <div slot="header">
- <span>看板</span>
- <i class="el-icon-plus" @click="addDashboard" />
- </div> -->
- <ul>
- <draggable v-model="dashboardList" :group="{name: 'dashboard',pull: true}" class="draggable-wrapper" @change="handleOrderChange">
- <li v-for="item in dashboardList" :key="item.dashboard_id" :class="{'dashboard-list-item': true, 'high-light-dashboard': currentDashboard.dashboard_id === item.dashboard_id}">
- <span @click="switchDb(item)">
- <i class="el-icon-document" />
- <span>{{ item.name }}</span>
- </span>
- <el-dropdown szie="mini" trigger="click" @command="handleCommand">
- <span class="el-dropdown-link">
- <i class="el-icon-more" />
- </span>
- <el-dropdown-menu slot="dropdown">
- <el-dropdown-item :command="{
- type: 'edit',
- target: item
- }">
- {{ $t('common.edit') }}
- </el-dropdown-item>
- <el-dropdown-item :command="{
- type: 'delete',
- target: item
- }">
- {{ $t('common.delete') }}
- </el-dropdown-item>
- </el-dropdown-menu>
- </el-dropdown>
- </li>
- </draggable>
- </ul>
- </el-card>
- <dashboardItem :dashboard="currentDashboard" :mode="isEdit" @fatherMethod="getList" />
- <el-dialog :title="$t('dashboard.addOrEditDashboard')" width="750px" :visible.sync="editDialogVisible">
- <el-form label-width="160px">
- <el-form-item :label="$t('dashboard.dashboardName')">
- <el-input v-model="dbObj.name" size="small" style="width: 450px;" :placeholder="$t('dashboard.dashboardNamePlaceholder')" />
- </el-form-item>
- <el-form-item :label="$t('dashboard.dashboardDesc')">
- <el-input v-model="dbObj.desc" type="textarea" :rows="5" size="small" style="width: 450px;" :placeholder="$t('dashboard.dashboardDescPlaceholder')" />
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button type="primary" size="small" @click="editDialogVisible = false"> {{ $t('common.cancel') }}</el-button>
- <el-button type="primary" size="small" @click="handleSubmit"> {{ $t('common.confirm') }}</el-button>
- </span>
- </el-dialog>
- </div>
- </template>
- <script>
- import draggable from 'vuedraggable'
- import dashboardItem from './dashboardItem'
- import { GetDataByName, ExeSqlJiade, PostDataByName, dashboardListJiade } from '@/api/common'
- import Cookies from 'js-cookie'
- // import { addDashboard, updateDashboard, dashboardList, deleteDashboard, dbOrder } from '@/api/dashboard'
- import { addDashboard, updateDashboard, deleteDashboard, dbOrder } from '@/api/dashboard'
- export default {
- name: 'Addboard',
- components: { dashboardItem, draggable },
- data() {
- return {
- isEdit: 'edit',
- dashboardList: [],
- currentDashboard: undefined,
- editDialogVisible: false,
- dbObj: {},
- loading: false,
- isCollapse: false,
- did: ''
- }
- },
- created() {
- console.log('this.$route.params.id', this.$route.params.id)
- const isEdit = this.$route.params.isEdit
- this.isEdit = isEdit
- this.did = window.location.href.split('~')[1]
- this.getList()
- },
- methods: {
- // getList() {
- // this.loading = true
- // dashboardList().then(resp => {
- // this.loading = false
- // this.dashboardList = []
- // resp.data.order.forEach((id, index) => {
- // const itemIndex = resp.data.dashboards.findIndex(item => item.dashboard_id === id)
- // if (itemIndex >= 0) {
- // this.dashboardList.push(resp.data.dashboards[itemIndex])
- // resp.data.dashboards.splice(itemIndex, 1)
- // } else {
- // console.log(id, index)
- // }
- // })
- // this.dashboardList = this.dashboardList.concat(resp.data.dashboards)
- // const dashboard = this.dashboardList.find(item => item.dashboard_id === this.$route.query.id)
- // if (dashboard) {
- // this.currentDashboard = dashboard
- // } else {
- // this.currentDashboard = this.dashboardList[0]
- // }
- // if (this.currentDashboard) {
- // this.$router.push(`/dashboard?id=${this.currentDashboard.dashboard_id}`).catch(_ => { })
- // }
- // })
- // },
- getList() {
- this.loading = true
- if (this.$route.params.id) {
- this.did = this.$route.params.id
- } else {
- this.did = this.did
- }
- var send_data = {
- name: 'getdashboards',
- parammaps: {
- pastureid: Cookies.get('pastureid'),
- empid: Cookies.get('employeid'),
- did: this.did
- }
- }
- console.log('进入大页面=================')
- dashboardListJiade(send_data).then(resp => {
- this.loading = false
- this.dashboardList = []
- console.log('看板列表数据:', resp)
- console.log('看板列表优化数据list:', resp.data.list)
- console.log('看板列表优化数据dashboards:', resp.data.dashboards)
- // resp.data.order.forEach((id, index) => {
- // const itemIndex = resp.data.dashboards.findIndex(item => item.dashboard_id === id)
- // if (itemIndex >= 0) {
- // this.dashboardList.push(resp.data.dashboards[itemIndex])
- // resp.data.dashboards.splice(itemIndex, 1)
- // } else {
- // console.log(id, index)
- // }
- // })
- this.dashboardList = this.dashboardList.concat(resp.data.dashboards)
- const dashboard = this.dashboardList.find(item => item.dashboard_id === this.$route.query.id)
- if (dashboard) {
- this.currentDashboard = dashboard
- } else {
- this.currentDashboard = this.dashboardList[0]
- }
- console.log('this.currentDashboard', this.currentDashboard)
- console.log('this.dashboardList', this.dashboardList)
- if (this.currentDashboard) {
- // this.$router.push({ path: '/customboard/addboard', query: { id: this.currentDashboard.dashboard_id }}).catch(_ => { })
- }
- })
- },
- switchDb(db) {
- if (db.dashboard_id === this.currentDashboard.dashboard_id) {
- this.getList()
- return
- }
- this.currentDashboard = db
- this.$router.push(`/dashboard?id=${this.currentDashboard.dashboard_id}`)
- },
- addDashboard() {
- this.dbObj = {}
- this.editDialogVisible = true
- },
- editDashboard(db) {
- this.dbObj = Object.assign({}, db)
- this.editDialogVisible = true
- },
- handleCommand(cmd) {
- if (cmd.type === 'edit') {
- this.editDashboard(cmd.target)
- } else {
- this.deleteDashboard(cmd.target)
- }
- },
- // handleSubmit() {
- // if (this.dbObj.dashboard_id) {
- // updateDashboard(this.dbObj).then(resp => {
- // this.getList()
- // this.editDialogVisible = false
- // })
- // } else {
- // addDashboard(this.dbObj).then(resp => {
- // this.getList()
- // this.editDialogVisible = false
- // })
- // }
- // },
- handleSubmit() {
- if (this.dbObj.dashboard_id) {
- updateDashboard(this.dbObj).then(resp => {
- this.getList()
- this.editDialogVisible = false
- })
- } else {
- console.log('this.dbObj', this.dbObj)
- var data = {
- name: 'insertDashboard',
- parammaps: {
- dname: this.dbObj.name,
- display: this.dbObj.desc,
- pastureid: Cookies.get('pastureid'),
- empid: Cookies.get('employeid'),
- emp: Cookies.get('employename')
- }
- }
- PostDataByName(data).then(response => {
- console.log('新增保存发送参数', data)
- this.$message({
- type: 'success',
- message: this.$t('common.saveSuccess')
- })
- this.getList()
- this.editDialogVisible = false
- })
- // addDashboard(this.dbObj).then(resp => {
- // this.getList()
- // this.editDialogVisible = false
- // })
- }
- },
- handleOrderChange(evt) {
- const data = {
- order: this.dashboardList.map(item => item.dashboard_id)
- }
- dbOrder(data)
- },
- deleteDashboard(db) {
- this.$confirm(this.$t('dashboard.deleteConfirm', db.name), this.$t('common.confirm')).then(() => {
- deleteDashboard({ dashboard_id: db.dashboard_id }).then(() => {
- this.getList()
- this.$message({
- type: 'success',
- message: this.$t('common.deleteSuccess')
- })
- })
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .container {
- display: flex;
- min-height: calc(100vh - 62px);
- // align-items: stretch;
- .dashboard-list {
- width: 250px;
- min-height: 100%;
- padding: 20px 10px;
- /deep/ .el-card__header {
- div {
- display: flex;
- justify-content: space-between;
- font-size: 14px;
- color: #606266;
- i {
- cursor: pointer;
- }
- }
- padding: 5px 0px;
- }
- .dashboard-list-item {
- display: flex;
- justify-content: space-between;
- line-height: 35px;
- font-size: 14px;
- cursor: pointer;
- color: #606266;
- i {
- margin-right: 10px;
- line-height: 35px;
- }
- }
- .high-light-dashboard {
- color: #205cd8;
- }
- }
- .dashboard-wrapper {
- width: 100%;
- }
- }
- </style>
|