editBoard.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <div class="edit-BI-board-page">
  3. <div class="top-box">
  4. <el-input
  5. placeholder="请输入看板名称"
  6. v-model="name"
  7. style="width: 300px; margin-right: 20px"
  8. ></el-input>
  9. <el-button type="primary" plain @click="showSelectTable = true"
  10. >添加表格</el-button
  11. >
  12. <el-button type="primary" plain @click="showSelectChart = true"
  13. >添加图表</el-button
  14. >
  15. <el-dropdown @command="handleCommand">
  16. <el-button type="primary" style="margin-left: 10px;">
  17. 添加知识资源<i class="el-icon-arrow-down el-icon--right"></i>
  18. </el-button>
  19. <el-dropdown-menu slot="dropdown">
  20. <el-dropdown-item command="0">事件库</el-dropdown-item>
  21. <el-dropdown-item command="1">政策库</el-dropdown-item>
  22. <el-dropdown-item command="2">报告库</el-dropdown-item>
  23. <el-dropdown-item command="3">知识库</el-dropdown-item>
  24. </el-dropdown-menu>
  25. </el-dropdown>
  26. <div class="right-btns">
  27. <el-button type="primary" plain @click="$router.back()">取消</el-button>
  28. <el-button type="primary" @click="handleSave">保存</el-button>
  29. </div>
  30. </div>
  31. <!-- 看板内容模块 -->
  32. <BIBoardContent
  33. ref="boardContent"
  34. :knowList.sync="knowledgeList"
  35. renderHeight="calc(100vh - 190px)"
  36. @checkDataList="checkDataList"
  37. v-model="boardDataList"
  38. :canDelete="true"
  39. :canDrag="true" />
  40. <!-- 选择图表 -->
  41. <SelectChart
  42. v-model="showSelectChart"
  43. @addChart="handleAddComp('chart', $event)"
  44. />
  45. <!-- 选择表格 -->
  46. <SelectTable
  47. v-model="showSelectTable"
  48. @addTable="handleAddComp('table', $event)"
  49. />
  50. <!-- 选择知识资源 -->
  51. <SelectKnow
  52. :show.sync="showSelectKnow"
  53. :ResourceType="selectKnowType"
  54. :knowList="knowledgeList"
  55. @addKnow="handleAddKnow"
  56. />
  57. </div>
  58. </template>
  59. <script>
  60. import apiBiBoard from '@/api/modules/BIBoard.js'
  61. import BIBoardContent from './components/BoardContent.vue'
  62. import SelectChart from './components/SelectChart.vue'
  63. import SelectTable from './components/SelectTable.vue'
  64. import SelectKnow from './components/SelectKnow.vue'
  65. const MAX_COUNT = 50
  66. // 生成唯一ID
  67. function createUniqueIdGenerator() {
  68. let id = 0;
  69. return function generateUniqueId() {
  70. id += 1;
  71. return `selfId_${id}`;
  72. };
  73. }
  74. const getUniqueId = createUniqueIdGenerator();
  75. export default {
  76. components: {
  77. BIBoardContent,
  78. SelectChart,
  79. SelectTable,
  80. SelectKnow,
  81. },
  82. data() {
  83. return {
  84. name: '',
  85. boardDataList: [],
  86. knowledgeList:[],//知识资源模块列表的全部数据
  87. showSelectChart: false,
  88. showSelectTable: false,
  89. showSelectKnow: false,
  90. selectKnowType:0,
  91. }
  92. },
  93. created() {
  94. if(this.$route.query.id){
  95. this.getBoardDetail()
  96. }
  97. },
  98. methods: {
  99. handleCommand(command){
  100. this.selectKnowType = +command || 0;
  101. this.showSelectKnow = true;
  102. },
  103. // 获取看板详情
  104. async getBoardDetail(){
  105. const res=await apiBiBoard.boardDetail({DashboardId:Number(this.$route.query.id)})
  106. if(res.Ret===200){
  107. this.name=res.Data.BiDashboardName
  108. this.boardDataList=res.Data.List||[]
  109. this.handleKnowList();
  110. }
  111. },
  112. async handleKnowList(){
  113. let item = this.boardDataList.find(_=>_.Type == 3);
  114. if(!item) return;
  115. let res = await apiBiBoard.getKnowledge({ BiDashboardDetailId:item.BiDashboardDetailId });
  116. if(res.Ret != 200) return;
  117. this.knowledgeList = res.Data.KnowledgeResourceList || [];
  118. this.cacheSaveKnowList(); //首次请求暂存,否则后端获取不到
  119. if(this.knowledgeList.length > 0) this.setFirstKnow();
  120. },
  121. async cacheSaveKnowList(){
  122. let knowItem = this.boardDataList.find(_=>_.Type == 3);
  123. await apiBiBoard.saveKnowledge({
  124. BiDashboardDetailId:knowItem ? (/^selfId_\d+$/.test(knowItem.BiDashboardDetailId) ? 0 : knowItem.BiDashboardDetailId) : 0,
  125. KnowledgeResourceList:this.knowledgeList.map(_=>({
  126. ResourceType:_.ResourceType,
  127. KnowledgeResourceId:_.KnowledgeResourceId
  128. }))
  129. });
  130. },
  131. setFirstKnow(){
  132. this.$nextTick(()=>{
  133. this.$refs.boardContent && this.$refs.boardContent.setFirstKnow()
  134. })
  135. },
  136. async handleSave() {
  137. if (!this.name) {
  138. this.$message.warning('请填写看板名称')
  139. return
  140. }
  141. if (this.boardDataList.length === 0) {
  142. this.$message.warning('请至少选择一个图表或表格!')
  143. return
  144. }
  145. const arr=this.boardDataList.map(item=>{
  146. return {
  147. Type:item.Type,
  148. UniqueCode:item.UniqueCode,
  149. Conf:item.Conf,
  150. }
  151. })
  152. const params={
  153. BiDashboardName:this.name,
  154. List:arr||[]
  155. }
  156. const res=this.$route.query.id?await apiBiBoard.editBoard({
  157. BiDashboardId:Number(this.$route.query.id),
  158. ...params
  159. }) :await apiBiBoard.addBoard(params)
  160. if(res.Ret===200){
  161. this.$message.success(this.$route.query.id?'编辑成功':'新增成功')
  162. setTimeout(() => {
  163. this.$router.back()
  164. }, 1000);
  165. }
  166. },
  167. checkDataList(dataList){ //grid-layout对x.y进行处理之后数据发生变化 同步x.y数据
  168. if(!dataList || !dataList.length) return;
  169. dataList.map((item) => {
  170. let i = this.boardDataList.findIndex(_=>item.BiDashboardDetailId == _.BiDashboardDetailId && item.Type == _.Type);
  171. if(i >= 0 && (item.x != this.boardDataList[i].x || item.y != this.boardDataList[i].y)){
  172. this.boardDataList[i].x = item.x;
  173. this.boardDataList[i].y = item.y;
  174. let configs = {
  175. w : item.w,
  176. h : item.h,
  177. x : item.x,
  178. y : item.y,
  179. i : item.i,
  180. };
  181. this.boardDataList[i].Conf = JSON.stringify(configs);
  182. }
  183. });
  184. },
  185. async handleAddKnow(data){
  186. const { ResourceType, checkedList} = data;
  187. let knowList = [...this.knowledgeList.filter(_=>_.ResourceType != ResourceType),...checkedList];
  188. let knowItem = this.boardDataList.find(_=>_.Type == 3);
  189. //后端需要暂存数据
  190. let r = await apiBiBoard.saveKnowledge({
  191. BiDashboardDetailId:knowItem ? (/^selfId_\d+$/.test(knowItem.BiDashboardDetailId) ? 0 : knowItem.BiDashboardDetailId) : 0,
  192. KnowledgeResourceList:knowList.map(_=>({
  193. ResourceType:_.ResourceType,
  194. KnowledgeResourceId:_.KnowledgeResourceId
  195. }))
  196. });
  197. if(r.Ret != 200) return this.$message.warning('添加失败,请重试')
  198. this.knowledgeList = knowList;
  199. if(!knowItem){
  200. let i = {
  201. Type: 3,
  202. UniqueCode:'uniqueTimeCode' + new Date().getTime(),
  203. BiDashboardDetailId:getUniqueId()
  204. }
  205. let addItem = this.$refs.boardContent ? this.$refs.boardContent.getAddMessage([i]) : []; //处理添加内容的位置信息
  206. this.boardDataList = [...this.boardDataList,...addItem];
  207. }else {
  208. if(!knowList.length){
  209. this.boardDataList = this.boardDataList.filter(_=>_.Type != 3);
  210. }
  211. }
  212. this.setFirstKnow();
  213. this.showSelectKnow = false;
  214. },
  215. handleAddComp(type, data) {
  216. const arr = data || []
  217. if (this.boardDataList.length + arr.length > MAX_COUNT) {
  218. this.$message.warning('添加已达上限(上限50)!')
  219. return
  220. }
  221. let objs = arr.map(item => {
  222. return {
  223. Type: type == 'chart' ? 1 : 2,
  224. UniqueCode:item.UniqueCode,
  225. BiDashboardDetailId:getUniqueId()
  226. }
  227. });
  228. let addItems = this.$refs.boardContent ? this.$refs.boardContent.getAddMessage(objs) : []; //处理添加内容的位置信息
  229. this.boardDataList = [...this.boardDataList,...addItems];
  230. this.showSelectChart = false
  231. this.showSelectTable = false
  232. },
  233. },
  234. }
  235. </script>
  236. <style lang="scss" scoped>
  237. .edit-BI-board-page {
  238. $border-color: #c8cdd9;
  239. background-color: #fff;
  240. border: 1px solid $border-color;
  241. .top-box {
  242. padding: 14px 20px;
  243. border-bottom: 1px solid $border-color;
  244. .right-btns {
  245. float: right;
  246. }
  247. }
  248. }
  249. </style>