chooseChannelForCatalog.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <div id="chooseChannelForCatalog" >
  3. <div style="background-color: #FFFFFF; margin-bottom: 1rem; position: relative; padding: 0.5rem; text-align: left;font-size: 14px;">
  4. <el-tree class="el-scrollbar"
  5. ref="tree"
  6. id="catalogTree"
  7. empty-text="未知节点"
  8. node-key="id"
  9. default-expand-all
  10. :highlight-current="true"
  11. :expand-on-click-node="false"
  12. :props="props"
  13. :load="loadNode"
  14. @node-contextmenu="contextmenuEventHandler"
  15. lazy>
  16. <span class="custom-tree-node" slot-scope="{ node, data }" style="width: 100%">
  17. <el-radio v-if="node.data.type === 0" style="margin-right: 0" v-model="chooseId" :label="node.data.id">{{''}}</el-radio>
  18. <span v-if="node.data.type === 0 && node.level === 1" class="el-icon-s-home"></span>
  19. <span v-if="node.data.type === 0 && node.level > 1" class="el-icon-folder-opened"></span>
  20. <span v-if="node.data.type === 1" class="iconfont icon-shexiangtou"></span>
  21. <span v-if="node.data.type === 2" class="iconfont icon-zhibo"></span>
  22. <span style="padding-left: 1px">{{ node.label }}</span>
  23. <span>
  24. <i style="margin-left: 5rem; color: #9d9d9d; padding-right: 20px" v-if="node.data.id === defaultCatalogIdSign">默认</i>
  25. </span>
  26. </span>
  27. </el-tree>
  28. </div>
  29. <catalogEdit ref="catalogEdit" :platformId="platformId"></catalogEdit>
  30. </div>
  31. </template>
  32. <script>
  33. import catalogEdit from './catalogEdit.vue'
  34. export default {
  35. name: 'chooseChannelForCatalog',
  36. props: ['platformId', 'platformName', 'defaultCatalogId', 'catalogIdChange'],
  37. created() {
  38. this.chooseId = this.defaultCatalogId;
  39. this.defaultCatalogIdSign = this.defaultCatalogId;
  40. this.initData();
  41. setTimeout(()=>{
  42. if (this.catalogIdChange)this.catalogIdChange(this.defaultCatalogId);
  43. }, 100)
  44. },
  45. components: {
  46. catalogEdit,
  47. },
  48. data() {
  49. return {
  50. props: {
  51. label: 'name',
  52. children: 'children',
  53. isLeaf: 'leaf'
  54. },
  55. defaultCatalogIdSign: null,
  56. chooseNode: null,
  57. chooseId: "",
  58. catalogTree: null,
  59. contextmenuShow: false
  60. };
  61. },
  62. watch:{
  63. platformId(newData, oldData){
  64. console.log(newData)
  65. this.initData()
  66. },
  67. chooseId(newData, oldData){
  68. console.log("发送: " + newData)
  69. if (this.catalogIdChange)this.catalogIdChange(newData);
  70. },
  71. },
  72. methods: {
  73. initData: function () {
  74. this.getCatalog();
  75. },
  76. getCatalog: function(parentId, callback) {
  77. let that = this;
  78. this.$axios({
  79. method:"get",
  80. url:`/api/platform/catalog`,
  81. params: {
  82. platformId: that.platformId,
  83. parentId: parentId
  84. }
  85. })
  86. .then((res)=> {
  87. if (res.data.code === 0) {
  88. if (typeof(callback) === 'function') {
  89. callback(res.data.data)
  90. }
  91. }
  92. })
  93. .catch(function (error) {
  94. console.log(error);
  95. });
  96. },
  97. addCatalog: function (parentId, node){
  98. let that = this;
  99. // 打开添加弹窗
  100. that.$refs.catalogEdit.openDialog(false, null, null, parentId, ()=>{
  101. node.loaded = false
  102. node.expand();
  103. });
  104. },
  105. refreshCatalog: function (node){
  106. node.loaded = false
  107. node.expand();
  108. },
  109. refreshCatalogById: function (id) {
  110. if (id) {
  111. let node = this.$refs.tree.getNode(id);
  112. this.refreshCatalog(node);
  113. }
  114. },
  115. editCatalog: function (data, node){
  116. let that = this;
  117. // 打开添加弹窗
  118. that.$refs.catalogEdit.openDialog(true, data.id, data.name, data.parentId, (data)=>{
  119. node.parent.loaded = false
  120. node.parent.expand();
  121. });
  122. },
  123. removeCatalog: function (id, node){
  124. this.$axios({
  125. method:"delete",
  126. url:`/api/platform/catalog/del`,
  127. params: {
  128. id: id,
  129. platformId: this.platformId,
  130. }
  131. })
  132. .then((res) => {
  133. if (res.data.code === 0) {
  134. console.log("移除成功")
  135. node.parent.loaded = false
  136. node.parent.expand();
  137. if (res.data.data) {
  138. this.defaultCatalogIdSign = res.data.data;
  139. }
  140. }
  141. })
  142. .catch(function (error) {
  143. console.log(error);
  144. });
  145. },
  146. setDefaultCatalog: function (id){
  147. this.$axios({
  148. method:"post",
  149. url:`/api/platform/catalog/default/update`,
  150. params: {
  151. platformId: this.platformId,
  152. catalogId: id,
  153. }
  154. })
  155. .then((res)=> {
  156. if (res.data.code === 0) {
  157. this.defaultCatalogIdSign = id;
  158. }
  159. })
  160. .catch(function (error) {
  161. console.log(error);
  162. });
  163. },
  164. loadNode: function(node, resolve){
  165. if (node.level === 0) {
  166. resolve([{
  167. name: this.platformName,
  168. id: this.platformId,
  169. type: 0
  170. }]);
  171. }
  172. if (node.level >= 1){
  173. this.getCatalog(node.data.id, resolve)
  174. }
  175. },
  176. contextmenuEventHandler: function (event,data,node,element){
  177. if (node.data.type !== 0) {
  178. data.parentId = node.parent.data.id;
  179. this.$contextmenu({
  180. items: [
  181. {
  182. label: "移除通道",
  183. icon: "el-icon-delete",
  184. disabled: false,
  185. onClick: () => {
  186. this.$axios({
  187. method:"delete",
  188. url:"/api/platform/catalog/relation/del",
  189. data: data
  190. }).then((res)=>{
  191. console.log("移除成功")
  192. node.parent.loaded = false
  193. node.parent.expand();
  194. }).catch(function (error) {
  195. console.log(error);
  196. });
  197. }
  198. }
  199. ],
  200. event, // 鼠标事件信息
  201. customClass: "custom-class", // 自定义菜单 class
  202. zIndex: 3000, // 菜单样式 z-index
  203. });
  204. }else {
  205. this.$contextmenu({
  206. items: [
  207. {
  208. label: "刷新节点",
  209. icon: "el-icon-refresh",
  210. disabled: false,
  211. onClick: () => {
  212. this.refreshCatalog(node);
  213. }
  214. },
  215. {
  216. label: "新建节点",
  217. icon: "el-icon-plus",
  218. disabled: false,
  219. onClick: () => {
  220. this.addCatalog(data.id, node);
  221. }
  222. },
  223. {
  224. label: "修改节点",
  225. icon: "el-icon-edit",
  226. disabled: node.level === 1,
  227. onClick: () => {
  228. this.editCatalog(data, node);
  229. }
  230. },
  231. {
  232. label: "删除节点",
  233. icon: "el-icon-delete",
  234. disabled: node.level === 1,
  235. divided: true,
  236. onClick: () => {
  237. this.$confirm('确定删除?', '提示', {
  238. confirmButtonText: '确定',
  239. cancelButtonText: '取消',
  240. type: 'warning'
  241. }).then(() => {
  242. this.removeCatalog(data.id, node)
  243. }).catch(() => {
  244. });
  245. }
  246. },
  247. {
  248. label: "设为默认",
  249. icon: "el-icon-folder-checked",
  250. disabled: node.data.id === this.defaultCatalogIdSign,
  251. onClick: () => {
  252. this.setDefaultCatalog(data.id)
  253. },
  254. },
  255. // {
  256. // label: "导出",
  257. // icon: "el-icon-download",
  258. // disabled: false,
  259. // children: [
  260. // {
  261. // label: "导出到文件",
  262. // onClick: () => {
  263. //
  264. // },
  265. // },
  266. // {
  267. // label: "导出到其他平台",
  268. // onClick: () => {
  269. //
  270. // },
  271. // }
  272. // ]
  273. // },
  274. ],
  275. event, // 鼠标事件信息
  276. customClass: "custom-class", // 自定义菜单 class
  277. zIndex: 3000, // 菜单样式 z-index
  278. });
  279. }
  280. return false;
  281. },
  282. }
  283. };
  284. </script>
  285. <style>
  286. #catalogTree{
  287. display: inline-block;
  288. }
  289. </style>