PropModal.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <t-dialog
  3. v-model:visible="props.visible"
  4. :header="$t('设备属性')"
  5. :width="470"
  6. @close="close"
  7. @confirm="confirm"
  8. >
  9. <t-tabs v-model="tabValue" @change="tabChange">
  10. <t-tab-panel :value="1" :label="$t('数据列表')">
  11. <div class="input-search mt-8">
  12. <div class="btn">
  13. <search-icon class="hover" />
  14. </div>
  15. <t-input
  16. v-model="search"
  17. @change="onSearch"
  18. @enter="onSearch"
  19. :placeholder="$t('搜索属性')"
  20. />
  21. </div>
  22. <div class="props mt-8">
  23. <t-tree
  24. v-model:actived="activedProp"
  25. activable
  26. hover
  27. :data="bindTreeData"
  28. :expand-level="1"
  29. :filter="bindFilter"
  30. @click="onClick"
  31. />
  32. </div>
  33. </t-tab-panel>
  34. <t-tab-panel :value="2" :label="$t('自定义数据')">
  35. <div class="form-item mt-16">
  36. <label>{{$t('显示名称')}}</label>
  37. <t-input
  38. v-model:value="activeObj.label"
  39. :placeholder="$t('属性简短描述')"
  40. />
  41. </div>
  42. <div class="form-item mt-16">
  43. <label>{{$t('属性名')}}</label>
  44. <t-input
  45. v-model:value="activeObj.value"
  46. :placeholder="$t('属性名')"
  47. />
  48. </div>
  49. <div class="form-item mt-16">
  50. <label>{{$t('类型')}}</label>
  51. <t-select
  52. class="w-full"
  53. :options="typeOptions"
  54. v-model="activeObj.type"
  55. :placeholder="$t('字符串')"
  56. />
  57. </div>
  58. </t-tab-panel>
  59. </t-tabs>
  60. </t-dialog>
  61. </template>
  62. <script lang="ts" setup>
  63. import { SearchIcon } from 'tdesign-icons-vue-next';
  64. import { ref, toRaw, onMounted, getCurrentInstance } from 'vue';
  65. import { typeOptions } from '@/services/common';
  66. import { MessagePlugin } from 'tdesign-vue-next';
  67. const { proxy } = getCurrentInstance();
  68. const $t = proxy.$t
  69. const props = defineProps<{
  70. visible: boolean;
  71. }>();
  72. const emit = defineEmits(['update:visible', 'change']);
  73. const activedProp = ref([]);
  74. onMounted(() => {
  75. getBindTreeData();
  76. });
  77. function close() {
  78. emit('update:visible', false);
  79. }
  80. const bindTreeData = ref<any>([]);
  81. const getBindTreeData = () => {
  82. let data: any = [];
  83. const iotTree = meta2d.store.data.iot?.tree || [];
  84. if (iotTree.length) {
  85. iotTree.forEach((item: any) => {
  86. item.checkable = false;
  87. });
  88. data.push({
  89. label: $t('物联网平台'),
  90. value: 'iot',
  91. checkable: false,
  92. children: iotTree,
  93. });
  94. }
  95. const sqlTree = meta2d.store.data.sqls || [];
  96. if (sqlTree.length) {
  97. data.push({
  98. label: $t('sql数据源'),
  99. value: 'sql',
  100. checkable: false,
  101. children: sqlTree,
  102. });
  103. }
  104. const networks = meta2d.store.data.networks || [];
  105. if (networks.length) {
  106. networks.forEach((item: any) => {
  107. item.checkable = false;
  108. });
  109. const mqttNets = meta2d.store.data.networks.filter(
  110. (item) => item.protocol === 'mqtt'
  111. );
  112. const wsNets = meta2d.store.data.networks.filter(
  113. (item) => item.protocol === 'websocket'
  114. );
  115. const httpNets = meta2d.store.data.networks.filter(
  116. (item) => item.protocol === 'http'
  117. );
  118. const SSENets = meta2d.store.data.networks.filter(
  119. (item) => item.protocol === 'SSE'
  120. );
  121. if (mqttNets.length) {
  122. data.push({
  123. label: 'MQTT',
  124. value: 'network',
  125. checkable: false,
  126. children: mqttNets,
  127. });
  128. }
  129. if (wsNets.length) {
  130. data.push({
  131. label: 'Websocket',
  132. value: 'network',
  133. checkable: false,
  134. children: wsNets,
  135. });
  136. }
  137. if (httpNets.length) {
  138. data.push({
  139. label: 'HTTP',
  140. value: 'network',
  141. checkable: false,
  142. children: httpNets,
  143. });
  144. }
  145. if (SSENets.length) {
  146. data.push({
  147. label: 'SSE',
  148. value: 'network',
  149. checkable: false,
  150. children: SSENets,
  151. });
  152. }
  153. }
  154. bindTreeData.value = data;
  155. };
  156. const search = ref('');
  157. const bindFilter = ref<any>(null);
  158. const onSearch = () => {
  159. bindFilter.value = search.value
  160. ? (node) => {
  161. return node.value?.indexOf(search.value) >= 0;
  162. }
  163. : null;
  164. };
  165. const selectedIds = ref([]);
  166. let activeObj:any = ref({
  167. label:'',
  168. type:'',
  169. value:''
  170. });
  171. const onClick = (context) => {
  172. const { node } = context;
  173. if(!node.isLeaf()){
  174. return;
  175. }
  176. const data = JSON.parse(JSON.stringify(node.data));
  177. const root = node?.getRoot()?.data;
  178. if(data._label){
  179. data._label = root.label+'#'+data._label;
  180. }else{
  181. data._label =node?.getParents()?.map((item)=>item.data.label+'#')?.reverse()?.join('') +data.label;
  182. }
  183. data._label = data._label.replace(/#/g, '->')
  184. activeObj.value = data;
  185. };
  186. const tabValue = ref(1);
  187. const confirm = () => {
  188. if(!activeObj.value.value){
  189. if(tabValue.value===1){
  190. MessagePlugin.info($t("请选择一项设备属性!"));
  191. }else{
  192. MessagePlugin.info($t("属性名必填!"));
  193. }
  194. return;
  195. }
  196. emit('change', activeObj.value);
  197. };
  198. const tabChange = ()=>{
  199. activeObj.value={
  200. label:'',
  201. type:'',
  202. value:''
  203. };
  204. }
  205. const doBind = () => {};
  206. </script>
  207. <style lang="postcss" scoped>
  208. .props {
  209. height: 300px;
  210. overflow-y: auto;
  211. padding-bottom: 16px;
  212. }
  213. .input-search {
  214. width: 100%;
  215. padding: 4px 0px;
  216. .btn {
  217. left: 14px;
  218. }
  219. }
  220. .t-tab-panel{
  221. height: 340px;
  222. overflow-y: hidden;
  223. }
  224. </style>