b3885840406a1dec09c26d5f3b3981779b844ed2.svn-base 9.9 KB

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