5fe92272f0a924c714a603a9642cc18603524b62.svn-base 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <div v-loading="loading" class="container">
  3. <el-card v-show="false" body-style="padding: 0px;" class="dashboard-list" shadow="never">
  4. <!-- <div slot="header">
  5. <span>看板</span>
  6. <i class="el-icon-plus" @click="addDashboard" />
  7. </div> -->
  8. <ul>
  9. <draggable v-model="dashboardList" :group="{name: 'dashboard',pull: true}" class="draggable-wrapper" @change="handleOrderChange">
  10. <li v-for="item in dashboardList" :key="item.dashboard_id" :class="{'dashboard-list-item': true, 'high-light-dashboard': currentDashboard.dashboard_id === item.dashboard_id}">
  11. <span @click="switchDb(item)">
  12. <i class="el-icon-document" />
  13. <span>{{ item.name }}</span>
  14. </span>
  15. <el-dropdown szie="mini" trigger="click" @command="handleCommand">
  16. <span class="el-dropdown-link">
  17. <i class="el-icon-more" />
  18. </span>
  19. <el-dropdown-menu slot="dropdown">
  20. <el-dropdown-item :command="{
  21. type: 'edit',
  22. target: item
  23. }">
  24. {{ $t('common.edit') }}
  25. </el-dropdown-item>
  26. <el-dropdown-item :command="{
  27. type: 'delete',
  28. target: item
  29. }">
  30. {{ $t('common.delete') }}
  31. </el-dropdown-item>
  32. </el-dropdown-menu>
  33. </el-dropdown>
  34. </li>
  35. </draggable>
  36. </ul>
  37. </el-card>
  38. <dashboardItem :dashboard="currentDashboard" :mode="isEdit" @fatherMethod="getList" :title="isTitle" />
  39. <el-dialog :title="$t('dashboard.addOrEditDashboard')" width="750px" :visible.sync="editDialogVisible">
  40. <el-form label-width="160px">
  41. <el-form-item :label="$t('dashboard.dashboardName')">
  42. <el-input v-model="dbObj.name" size="small" style="width: 450px;" :placeholder="$t('dashboard.dashboardNamePlaceholder')" />
  43. </el-form-item>
  44. <el-form-item :label="$t('dashboard.dashboardDesc')">
  45. <el-input v-model="dbObj.desc" type="textarea" :rows="5" size="small" style="width: 450px;" :placeholder="$t('dashboard.dashboardDescPlaceholder')" />
  46. </el-form-item>
  47. </el-form>
  48. <span slot="footer" class="dialog-footer">
  49. <el-button type="primary" size="small" @click="editDialogVisible = false"> {{ $t('common.cancel') }}</el-button>
  50. <el-button type="primary" size="small" @click="handleSubmit"> {{ $t('common.confirm') }}</el-button>
  51. </span>
  52. </el-dialog>
  53. </div>
  54. </template>
  55. <script>
  56. import draggable from 'vuedraggable'
  57. import dashboardItem from './dashboardItem'
  58. import { GetDataByName, ExeSqlJiade, PostDataByName, dashboardListJiade } from '@/api/common'
  59. import Cookies from 'js-cookie'
  60. // import { addDashboard, updateDashboard, dashboardList, deleteDashboard, dbOrder } from '@/api/dashboard'
  61. import { addDashboard, updateDashboard, deleteDashboard, dbOrder } from '@/api/dashboard'
  62. export default {
  63. name: 'Addboard',
  64. components: { dashboardItem, draggable },
  65. data() {
  66. return {
  67. isEdit: 'edit',
  68. dashboardList: [],
  69. currentDashboard: undefined,
  70. editDialogVisible: false,
  71. dbObj: {},
  72. loading: false,
  73. isCollapse: false,
  74. did: '',
  75. isTitle: '2',
  76. }
  77. },
  78. created() {
  79. console.log('this.$route.params.id', this.$route.params.id)
  80. const isEdit = this.$route.params.isEdit
  81. this.isEdit = isEdit
  82. this.did = window.location.href.split('~')[1]
  83. this.haha = window.location.href.split('~')[2]
  84. console.log('this.did', this.did)
  85. console.log('this.haha', this.haha)
  86. if (this.haha == '3') {
  87. this.isTitle = '3'
  88. } else {
  89. this.isTitle = '2'
  90. }
  91. this.getList()
  92. },
  93. methods: {
  94. // getList() {
  95. // this.loading = true
  96. // dashboardList().then(resp => {
  97. // this.loading = false
  98. // this.dashboardList = []
  99. // resp.data.order.forEach((id, index) => {
  100. // const itemIndex = resp.data.dashboards.findIndex(item => item.dashboard_id === id)
  101. // if (itemIndex >= 0) {
  102. // this.dashboardList.push(resp.data.dashboards[itemIndex])
  103. // resp.data.dashboards.splice(itemIndex, 1)
  104. // } else {
  105. // console.log(id, index)
  106. // }
  107. // })
  108. // this.dashboardList = this.dashboardList.concat(resp.data.dashboards)
  109. // const dashboard = this.dashboardList.find(item => item.dashboard_id === this.$route.query.id)
  110. // if (dashboard) {
  111. // this.currentDashboard = dashboard
  112. // } else {
  113. // this.currentDashboard = this.dashboardList[0]
  114. // }
  115. // if (this.currentDashboard) {
  116. // this.$router.push(`/dashboard?id=${this.currentDashboard.dashboard_id}`).catch(_ => { })
  117. // }
  118. // })
  119. // },
  120. getList() {
  121. this.loading = true
  122. if (this.$route.params.id) {
  123. this.did = this.$route.params.id
  124. } else {
  125. this.did = this.did
  126. }
  127. var send_data = {
  128. name: 'getdashboards',
  129. parammaps: {
  130. pastureid: Cookies.get('pastureid'),
  131. empid: Cookies.get('employeid'),
  132. did: this.did
  133. }
  134. }
  135. console.log('进入大页面=================')
  136. dashboardListJiade(send_data).then(resp => {
  137. this.loading = false
  138. this.dashboardList = []
  139. console.log('看板列表数据:', resp)
  140. console.log('看板列表优化数据list:', resp.data.list)
  141. console.log('看板列表优化数据dashboards:', resp.data.dashboards)
  142. // resp.data.order.forEach((id, index) => {
  143. // const itemIndex = resp.data.dashboards.findIndex(item => item.dashboard_id === id)
  144. // if (itemIndex >= 0) {
  145. // this.dashboardList.push(resp.data.dashboards[itemIndex])
  146. // resp.data.dashboards.splice(itemIndex, 1)
  147. // } else {
  148. // console.log(id, index)
  149. // }
  150. // })
  151. this.dashboardList = this.dashboardList.concat(resp.data.dashboards)
  152. const dashboard = this.dashboardList.find(item => item.dashboard_id === this.$route.params.id)
  153. if (dashboard) {
  154. this.currentDashboard = dashboard
  155. } else {
  156. this.currentDashboard = this.dashboardList[0]
  157. }
  158. console.log('this.currentDashboard', this.currentDashboard)
  159. console.log('this.dashboardList', this.dashboardList)
  160. if (this.currentDashboard) {
  161. // this.$router.push({ path: '/customboard/addboard', query: { id: this.currentDashboard.dashboard_id }}).catch(_ => { })
  162. }
  163. })
  164. },
  165. switchDb(db) {
  166. if (db.dashboard_id === this.currentDashboard.dashboard_id) {
  167. this.getList()
  168. return
  169. }
  170. this.currentDashboard = db
  171. this.$router.push(`/dashboard?id=${this.currentDashboard.dashboard_id}`)
  172. },
  173. addDashboard() {
  174. this.dbObj = {}
  175. this.editDialogVisible = true
  176. },
  177. editDashboard(db) {
  178. this.dbObj = Object.assign({}, db)
  179. this.editDialogVisible = true
  180. },
  181. handleCommand(cmd) {
  182. if (cmd.type === 'edit') {
  183. this.editDashboard(cmd.target)
  184. } else {
  185. this.deleteDashboard(cmd.target)
  186. }
  187. },
  188. // handleSubmit() {
  189. // if (this.dbObj.dashboard_id) {
  190. // updateDashboard(this.dbObj).then(resp => {
  191. // this.getList()
  192. // this.editDialogVisible = false
  193. // })
  194. // } else {
  195. // addDashboard(this.dbObj).then(resp => {
  196. // this.getList()
  197. // this.editDialogVisible = false
  198. // })
  199. // }
  200. // },
  201. handleSubmit() {
  202. if (this.dbObj.dashboard_id) {
  203. updateDashboard(this.dbObj).then(resp => {
  204. this.getList()
  205. this.editDialogVisible = false
  206. })
  207. } else {
  208. console.log('this.dbObj', this.dbObj)
  209. var data = {
  210. name: 'insertDashboard',
  211. parammaps: {
  212. dname: this.dbObj.name,
  213. display: this.dbObj.desc,
  214. pastureid: Cookies.get('pastureid'),
  215. empid: Cookies.get('employeid'),
  216. emp: Cookies.get('employename')
  217. }
  218. }
  219. PostDataByName(data).then(response => {
  220. console.log('新增保存发送参数', data)
  221. this.$message({
  222. type: 'success',
  223. message: this.$t('common.saveSuccess')
  224. })
  225. this.getList()
  226. this.editDialogVisible = false
  227. })
  228. // addDashboard(this.dbObj).then(resp => {
  229. // this.getList()
  230. // this.editDialogVisible = false
  231. // })
  232. }
  233. },
  234. handleOrderChange(evt) {
  235. const data = {
  236. order: this.dashboardList.map(item => item.dashboard_id)
  237. }
  238. dbOrder(data)
  239. },
  240. deleteDashboard(db) {
  241. this.$confirm(this.$t('dashboard.deleteConfirm', db.name), this.$t('common.confirm')).then(() => {
  242. deleteDashboard({ dashboard_id: db.dashboard_id }).then(() => {
  243. this.getList()
  244. this.$message({
  245. type: 'success',
  246. message: this.$t('common.deleteSuccess')
  247. })
  248. })
  249. })
  250. }
  251. }
  252. }
  253. </script>
  254. <style lang="scss" scoped>
  255. .container {
  256. display: flex;
  257. min-height: calc(100vh - 62px);
  258. // align-items: stretch;
  259. .dashboard-list {
  260. width: 250px;
  261. min-height: 100%;
  262. padding: 20px 10px;
  263. /deep/ .el-card__header {
  264. div {
  265. display: flex;
  266. justify-content: space-between;
  267. font-size: 14px;
  268. color: #606266;
  269. i {
  270. cursor: pointer;
  271. }
  272. }
  273. padding: 5px 0px;
  274. }
  275. .dashboard-list-item {
  276. display: flex;
  277. justify-content: space-between;
  278. line-height: 35px;
  279. font-size: 14px;
  280. cursor: pointer;
  281. color: #606266;
  282. i {
  283. margin-right: 10px;
  284. line-height: 35px;
  285. }
  286. }
  287. .high-light-dashboard {
  288. color: #205cd8;
  289. }
  290. }
  291. .dashboard-wrapper {
  292. width: 100%;
  293. }
  294. }
  295. </style>