agentCheck.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <view class="agentCheck">
  3. <u-dropdown class="up-dropdown">
  4. <u-dropdown-item v-model="agentId" @change="changeAgentId" :title="agentName" :options="agentList"></u-dropdown-item>
  5. </u-dropdown>
  6. </view>
  7. </template>
  8. <script setup>
  9. import { ref, computed } from "vue";
  10. import { useAppStore } from "@/stores/app";
  11. import { getAgentList } from "@/api/home.js";
  12. import { onLoad } from '@dcloudio/uni-app'
  13. const appStore = useAppStore();
  14. const agentId = ref('');
  15. const agentList = ref([]);
  16. defineExpose({
  17. initAgentId,
  18. agentId
  19. });
  20. //计算属性
  21. const agentName = computed(()=>{
  22. return agentList.value.find(item=>item.value == agentId.value)?.label || '';
  23. })
  24. onLoad(()=>{
  25. // agentListFn();
  26. });
  27. async function agentListFn(){
  28. await getAgentList().then(res=>{
  29. if(res.code == 200){
  30. let rows = res.rows || [];
  31. agentList.value = rows.map(item=>{
  32. return {
  33. label: item.agentName,
  34. value: item.agentId
  35. }
  36. });
  37. }
  38. })
  39. }
  40. async function initAgentId(){
  41. await agentListFn();
  42. console.log('initAgentId',agentList.value,appStore.agentId);
  43. agentId.value = appStore.agentId || agentList.value[0].value;
  44. appStore.agentId = agentId.value;
  45. }
  46. function changeAgentId(){
  47. console.log('changeAgentId',agentId.value);
  48. appStore.agentId = agentId.value;
  49. appStore.sessionId = '';
  50. }
  51. </script>
  52. <style lang="scss" scoped>
  53. .agentCheck{
  54. width: 100vw;
  55. position: relative;
  56. z-index: 20;
  57. }
  58. </style>