NodeLinksEditDialog.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <el-dialog
  3. v-model="visible"
  4. width="850"
  5. :before-close="handleClose"
  6. >
  7. <el-form :model="formData" :rules="formRules">
  8. <el-row class="data-category">{{message}}</el-row>
  9. <el-row class="props-content">
  10. <el-table
  11. tooltip-effect="dark"
  12. :data="formData.links"
  13. style="width: 100%"
  14. @selection-change="">
  15. <el-table-column
  16. type="selection"
  17. width="55">
  18. </el-table-column>
  19. <el-table-column
  20. prop="src_node.name"
  21. label="源"
  22. width="180">
  23. </el-table-column>
  24. <el-table-column
  25. prop="name"
  26. label="链接名称"
  27. width="180">
  28. </el-table-column>
  29. <el-table-column
  30. prop="dest_node.name"
  31. label="目的">
  32. </el-table-column>
  33. <el-table-column
  34. prop="dest_node.status"
  35. label="状态">
  36. <template v-slot="scope">
  37. <div v-if="scope.row.status==0">正常</div>
  38. <div v-if="scope.row.status==-1"><el-tag type="danger">无效</el-tag></div>
  39. </template>
  40. </el-table-column>
  41. <el-table-column
  42. fixed="right"
  43. label="操作"
  44. width="180">
  45. <template #default="scope">
  46. <el-button type="danger" size="small" @click="handleEdgeDelete(scope.row, -99)" >删除</el-button>
  47. <el-button v-if="scope.row.status==0" type="warning" size="small" @click="handleEdgeDelete(scope.row, -1)" >设置无效</el-button>
  48. <el-button v-if="scope.row.status==-1" type="success" size="small" @click="handleEdgeDelete(scope.row, 0)" >设置有效</el-button>
  49. </template>
  50. </el-table-column>
  51. </el-table>
  52. </el-row>
  53. </el-form>
  54. <template #footer>
  55. <span class="dialog-footer">
  56. <el-button @click="handleCancel">取 消</el-button>
  57. <el-button type="primary" @click="handleConfirm">保 存</el-button>
  58. </span>
  59. </template>
  60. </el-dialog>
  61. </template>
  62. <script setup lang="ts">
  63. import { ref, watch, toRefs, onMounted} from 'vue';
  64. import r from '@/utils/request.ts';
  65. import { ElMessageBox, ElNotification } from 'element-plus';
  66. /**********emits**********/
  67. const emit = defineEmits(['update:modelValue', 'confirm', 'cancel','server-saved']);
  68. /**********props**********/
  69. const props = defineProps({
  70. modelValue: {
  71. type: Boolean,
  72. default: false
  73. },
  74. title: {
  75. type: String,
  76. default: '确认操作'
  77. },
  78. data: {
  79. type: Object,
  80. default: {},
  81. },
  82. links: {
  83. type: Object,
  84. default: {},
  85. },
  86. message: {
  87. type: String,
  88. default: '您确定要执行此操作吗?'
  89. },
  90. });
  91. /**********props_watch**********/
  92. watch(() => props.modelValue, (newValue) => {
  93. console.log("watch modelValue");
  94. visible.value = newValue;
  95. });
  96. watch(()=>props.data,(newvalue, oldvalue)=>{
  97. console.log("watch data");
  98. formData.value.name = '';
  99. formData.value.id = 0;
  100. formData.value.category = newvalue.category;
  101. formData.value.name = newvalue.name;
  102. formData.value.selectedLinks = [];
  103. });
  104. watch(()=>props.links,(newvalue, oldvalue)=>{
  105. console.log("watch nodes");
  106. formData.value.links = newvalue;
  107. });
  108. const handleClose = (done) => {
  109. emit('update:modelValue', false);
  110. done();
  111. };
  112. /**********ui_data**********/
  113. const visible = ref(props.modelValue);
  114. const formData = ref({
  115. id: 0,
  116. category: "",
  117. name: "",
  118. status: 0,
  119. links: [],
  120. checkAll: false,
  121. isIndeterminate: true,
  122. selectedLinks: []
  123. });
  124. const formRules = ref({
  125. linkType: [{required: true, message:"链接类型必须选择", trigger:"blur"}],
  126. });
  127. const loadEdgeData = (data) => {
  128. const response = r.request<string[]>({
  129. url: "/api/edge-of-node/"+props.data.id,
  130. method: "get"
  131. });
  132. response.then(result => {
  133. formData.value.links = result["edges"];
  134. });
  135. }
  136. const handleEdgeDelete = (data, status) =>{
  137. var message = "";
  138. if (status == -99){
  139. message = '您确认要删除这个链接吗?';
  140. }
  141. if (status == -1)
  142. {
  143. message = '您确认要将这个链接设置为无效吗?';
  144. }
  145. if (status == 0)
  146. {
  147. message = '您确认要将这个链接设置为有效吗?';
  148. }
  149. ElMessageBox.confirm(message,'提示',
  150. {
  151. confirmButtonText: '确定',
  152. cancelButtonText: '取消',
  153. type: 'warning',
  154. }
  155. ).then(() => {
  156. console.log("handleEdgeDelete(): " + data.id);
  157. const response = r.request<string[]>({
  158. url: "/api/edge-delete/"+data.id+"/"+status,
  159. method: "get"
  160. });
  161. response.then(result => {
  162. loadEdgeData(data);
  163. });
  164. }).catch(() => {
  165. console.log('取消')
  166. })
  167. };
  168. /**********ui_handler**********/
  169. const handleConfirm = () => {
  170. emit('created');
  171. emit('update:modelValue', false);
  172. emit('server-saved');
  173. };
  174. const handleCancel = () => {
  175. emit('cancel');
  176. emit('update:modelValue', false);
  177. };
  178. /**********vue_event_handler**********/
  179. onMounted( ()=>{
  180. });
  181. /**********vue_export_def**********/
  182. const openDialog = ()=>{
  183. //visible.value = true;
  184. }
  185. defineExpose({openDialog});
  186. </script>
  187. <style scoped>
  188. .data-category{
  189. width: 100%;
  190. font-size: 18pt;
  191. color:rgb(3, 57, 123);
  192. font-weight: 800;
  193. justify-content: center;
  194. margin-bottom: 10px;
  195. }
  196. .data-name{
  197. margin: 5px;
  198. display: flex;
  199. flex-direction: column;
  200. width: 580px;
  201. }
  202. .props-content{
  203. width: 100%;
  204. height: 350px;
  205. display: flex;
  206. flex-direction: row;
  207. justify-content: flex-start;
  208. overflow: auto;
  209. }
  210. .checkbox-content{
  211. width: 600px;
  212. display: flex;
  213. flex-direction: row;
  214. flex-wrap: wrap;
  215. justify-content: flex-start;
  216. overflow-y: auto;
  217. }
  218. .data-prop{
  219. margin: 5px;
  220. width: 600px;
  221. display: flex;
  222. flex-direction: column;
  223. }
  224. .prop-name{
  225. background-color: #efefef;
  226. color:rgb(11, 117, 247);
  227. width:580px;
  228. }
  229. .data-text{
  230. width: 580px;
  231. background-color: #efefef;
  232. }
  233. </style>