index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <div class="__normal-page">
  3. <div class="__normal-tree">
  4. <div class="__normal-tree_filter">
  5. <el-input v-model="treeName" placeholder="请输入关键词进行搜索" clearable>
  6. <template #suffix>
  7. <img src="@/assets/images/cus/tree-search.png" alt=""/>
  8. </template>
  9. </el-input>
  10. </div>
  11. <div class="__normal-tree_content">
  12. <el-tree
  13. ref="ref_tree"
  14. :data="treeData"
  15. node-key="id"
  16. :props="{
  17. children: 'children',
  18. label: 'name',
  19. }"
  20. @node-click="handleNodeClick"
  21. :expand-on-click-node="false"
  22. highlight-current
  23. :filter-node-method="treeFilter"
  24. />
  25. </div>
  26. </div>
  27. <div class="__normal-content" v-if="currentSource">
  28. <CusForm labelWidth="100px" ref="ref_form">
  29. <div class="__cus-title_2">实时轨迹唯一标识(DATA.xxx形式,可任意拼接或使用字符串模板`POINT(${DATA.xxx} ${DATA.xxx})`或DATA.xxx + DATA.xxx)</div>
  30. <CusFormColumn
  31. :span="12"
  32. required
  33. label="轨迹"
  34. v-model:param="form.trackKey"/>
  35. <CusFormColumn
  36. :span="12"
  37. required
  38. label="轨迹点"
  39. v-model:param="form.trackPointKey"/>
  40. <CusFormColumn
  41. :span="12"
  42. required
  43. label="WKT坐标"
  44. v-model:param="form.trackWktKey"/>
  45. <CusFormColumn
  46. :span="12"
  47. required
  48. label="速度"
  49. v-model:param="form.trackSpeedKey"/>
  50. <CusFormColumn
  51. :span="12"
  52. required
  53. label="航向"
  54. v-model:param="form.trackCourseKey"/>
  55. <CusFormColumn
  56. :span="12"
  57. label="船艏向"
  58. v-model:param="form.trackHeadKey"/>
  59. <div class="__cus-title_2">历史轨迹唯一标识(DATA.xxx形式,可任意拼接或使用字符串模板`POINT(${DATA.xxx} ${DATA.xxx})`或DATA.xxx + DATA.xxx)</div>
  60. <CusFormColumn
  61. :span="12"
  62. required
  63. label="轨迹"
  64. v-model:param="form.historyTrackKey"/>
  65. <CusFormColumn
  66. :span="12"
  67. required
  68. label="轨迹点"
  69. v-model:param="form.historyTrackPointKey"/>
  70. <CusFormColumn
  71. :span="12"
  72. required
  73. label="WKT坐标"
  74. v-model:param="form.historyTrackWktKey"/>
  75. <CusFormColumn
  76. :span="12"
  77. required
  78. label="速度"
  79. v-model:param="form.historyTrackSpeedKey"/>
  80. <CusFormColumn
  81. :span="12"
  82. required
  83. label="航向"
  84. v-model:param="form.historyTrackCourseKey"/>
  85. <CusFormColumn
  86. :span="12"
  87. label="船艏向"
  88. v-model:param="form.historyTrackHeadKey"/>
  89. </CusForm>
  90. <div class="buttons">
  91. <el-button type="primary" @click="onSubmit">保存</el-button>
  92. </div>
  93. </div>
  94. </div>
  95. </template>
  96. <script lang="ts">
  97. import {
  98. defineComponent,
  99. onMounted,
  100. ref,
  101. toRefs,
  102. reactive,
  103. watch,
  104. getCurrentInstance,
  105. ComponentInternalInstance,
  106. computed, nextTick,
  107. } from "vue";
  108. import { useStore } from "vuex";
  109. import { useRouter, useRoute } from "vue-router";
  110. import { ElMessage, ElMessageBox } from "element-plus";
  111. export default defineComponent({
  112. name: "",
  113. components: {
  114. },
  115. setup(props, {emit}) {
  116. const store = useStore();
  117. const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties;
  118. const state = reactive({
  119. // 加载中
  120. loading: false,
  121. treeData: [],
  122. treeName: '',
  123. currentSource: <any>null,
  124. form: <any>{}
  125. });
  126. const ref_form = ref()
  127. // 获取字典
  128. const initDictionary = () => {
  129. }
  130. const ref_tree = ref()
  131. const handleNodeClick = (data) => {
  132. state.currentSource = data
  133. initTrack()
  134. }
  135. const treeFilter = (value, data) => {
  136. if (!value) return true
  137. return data.name.includes(value)
  138. }
  139. watch(() => state.treeName, (n) => {
  140. ref_tree.value.filter(n)
  141. })
  142. const initSource = () => {
  143. that.$api.shipTestSourceList().then(res => {
  144. state.treeData = res.data
  145. })
  146. nextTick(() => {
  147. ref_form.value?.reset()
  148. })
  149. }
  150. const initTrack = () => {
  151. that.$api.shipTestTrackInfoBySourceId(state.currentSource.id).then(res => {
  152. if (res.code === 200) {
  153. if (res.data?.[0]) {
  154. state.form = res.data[0]
  155. } else {
  156. state.form = {
  157. sourceId: state.currentSource.id
  158. }
  159. }
  160. } else {
  161. ElMessage.error(res.msg)
  162. }
  163. })
  164. }
  165. const onSubmit = () => {
  166. ref_form.value.submit().then(() => {
  167. ElMessageBox.confirm("是否提交?", "提示", {
  168. confirmButtonText: "确定",
  169. cancelButtonText: "取消",
  170. type: "warning",
  171. }).then(() => {
  172. state.loading = true
  173. const apiHandle = state.form.id ? that.$api.shipTestTrackEdit(state.form) : that.$api.shipTestTrackAdd(state.form)
  174. apiHandle.then(res => {
  175. if (res.code === 200) {
  176. ElMessage.success(state.form.id ? '编辑成功' : '新增成功')
  177. initTrack()
  178. } else {
  179. ElMessage.error(res.msg)
  180. }
  181. state.loading = false
  182. }).catch(() => {
  183. state.loading = false
  184. })
  185. }).catch(() => {})
  186. }).catch((e) => {
  187. ElMessage({
  188. message: e[0].message,
  189. grouping: true,
  190. type: 'warning',
  191. })
  192. })
  193. }
  194. onMounted(() => {
  195. initDictionary()
  196. initSource()
  197. })
  198. return {
  199. ref_form,
  200. ...toRefs(state),
  201. handleNodeClick,
  202. treeFilter,
  203. ref_tree,
  204. onSubmit
  205. }
  206. },
  207. });
  208. </script>
  209. <style scoped lang="scss">
  210. .__normal-content {
  211. background-color: #FFFFFF;
  212. padding: 20px;
  213. .__cus-title_2 {
  214. margin-bottom: 10px;
  215. }
  216. .buttons {
  217. width: 100%;
  218. display: flex;
  219. align-items: center;
  220. justify-content: center;
  221. }
  222. }
  223. </style>