Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

service.vue 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <navBar title="服务" :scrollTop="scrollTop" :isBack="isBack" navbgClass="nav-bgXin" fontColor='#fff'></navBar>
  3. <view class="wrapper">
  4. <view class="search-box">
  5. <image :src="`${$imgUrl}service/icon-search.png`" class="icon" mode="aspectFill" @click="search()"></image>
  6. <input class="search" placeholder="请输入业务名称" v-model="state.searchVal" @confirm="search()" />
  7. </view>
  8. <view class="content" v-if="menuShow.list && menuShow.list.length > 0">
  9. <view class="left">
  10. <view v-for="(item,index) in menuShow.list" :key="index"
  11. :class="activeTab === item.name ? 'menu active' : 'menu'" @click="tabHandle(item.name,index)">
  12. <view :class="activeTab === item.name ? 'border on' : 'border'" :style="{ '--background': bgOn }"></view>
  13. <view class="menu-text">{{item.name}}</view>
  14. </view>
  15. </view>
  16. <view class="right">
  17. <rightListVue class="rightListVue" :menuList='menuShow.list[tableSelectIndex].children'
  18. v-if="menuShow.list.length > 0" />
  19. </view>
  20. </view>
  21. <view class="content" v-else-if="state.load"></view>
  22. <view class="content" v-else>
  23. <view class="left">
  24. <view class="menu active">
  25. <view class="border on"></view>
  26. <view class="menu-text">其他服务</view>
  27. </view>
  28. </view>
  29. <view class="right">
  30. <view class="login-content" @click="goToLogin">
  31. <view class="tips" >登录查看更多模块</view>
  32. <view class="custom-btn">登录</view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script lang="ts" setup>
  39. import { source } from "@/utils/network/difference";
  40. import rightListVue from "./components/rightList.vue";
  41. import { ref, reactive, } from "vue";
  42. import { onLoad, onShow, onPageScroll } from "@dcloudio/uni-app";
  43. import navBar from "../../components/nav-bar/nav-bar2.vue";
  44. import { fileURL, fileURLList } from "@/datas/fileURL.js";
  45. import { queryMenuConfig } from "@/utils/network/api.js";
  46. import {requestNew } from "@/utils/network/request.js";
  47. import { getItem, StorageKeys } from "@/utils/storage";
  48. import { hasLogin, confirm, navTo} from "@/utils/utils";
  49. const bgOn = `url(${fileURL}image/newHome/bg-on.png) center center no-repeat`;
  50. const activeTab = ref("");
  51. const tableSelectIndex = ref(0);
  52. const scrollTop = ref(0);
  53. const isBack = ref(false);
  54. // 切换
  55. function tabHandle(val, index) {
  56. activeTab.value = val;
  57. tableSelectIndex.value = index
  58. console.log(tableSelectIndex.value)
  59. }
  60. const menu = reactive({
  61. list: [] //请求的真正的不会变得
  62. });
  63. const menuShow = reactive({
  64. list: [],//展示的
  65. });
  66. const emptyList = reactive({
  67. list: [] //请求的真正的不会变得
  68. });
  69. const state = reactive({
  70. searchVal: '', //input输入值
  71. newArr: [],
  72. load: false // 是否已经请求过数据
  73. });
  74. onLoad(() => {
  75. // load()
  76. });
  77. onShow(() => {
  78. // state.load = false
  79. console.log(hasLogin())
  80. if (!hasLogin()) {
  81. state.load = false
  82. menu.list = []
  83. menuShow.list = []
  84. }
  85. if (menu && menu.list.length <= 0) {
  86. load()
  87. }
  88. })
  89. onPageScroll((e) => {
  90. scrollTop.value = e.scrollTop;
  91. });
  92. function load(){
  93. if (!hasLogin()) {
  94. state.load = false
  95. // confirm('您需要登录过后才能使用此功能', () => {
  96. // uni.navigateTo({
  97. // url: '/login/login',
  98. // });
  99. // }, '温馨提示', true, '去登录');
  100. } else {
  101. queryMenuConfigAction().then((val : any) => {
  102. console.log("列表",val)
  103. state.load = true
  104. menu.list = val.menuList ? val.menuList : [],
  105. menu.list = deepClone(menu.list)
  106. state.newArr = deepClone(menu.list);
  107. menuShow.list = val.menuList ? val.menuList : [],
  108. activeTab.value = val.menuList[0]['name']
  109. }).catch(() => {
  110. state.load = true
  111. })
  112. }
  113. }
  114. // 深拷贝
  115. const deepClone = (obj) => {
  116. if (typeof obj !== 'object' || obj === null) {
  117. return obj;
  118. }
  119. let clone = Array.isArray(obj) ? [] : {};
  120. for (let key in obj) {
  121. if (obj.hasOwnProperty(key)) {
  122. clone[key] = deepClone(obj[key]);
  123. }
  124. }
  125. return clone;
  126. }
  127. const search = () => {
  128. for (var i = 0; i < menu.list.length; i++) {
  129. state.newArr[i]['children'] = [];
  130. for (var j = 0; j < menu.list[i]['children'].length; j++) {
  131. const name = menu.list[i]['children'][j].name;
  132. if (name.indexOf(state.searchVal) >= 0) {
  133. state.newArr[i]['children'].push(menu.list[i]['children'][j])
  134. }
  135. }
  136. }
  137. // 清除没有孩子的父亲
  138. const lastArr = []
  139. for (var k = 0; k < state.newArr.length; k++) {
  140. if (state.newArr[k]['children'].length != 0) {
  141. lastArr.push(state.newArr[k])
  142. }
  143. }
  144. console.log("lastArr", lastArr)
  145. if (state.searchVal) {
  146. tableSelectIndex.value = 0
  147. }
  148. menuShow.list = lastArr
  149. console.log("menuShow.list", menuShow.list, tableSelectIndex.value)
  150. }
  151. const queryMenuConfigAction = () => {
  152. var data = {
  153. openId: getItem(StorageKeys.OpenId),
  154. systemType: source == "WECHAT" ? '6' : "9",
  155. loginSource: getItem("loginSource")
  156. };
  157. const options = {
  158. type: 2,
  159. data: data,
  160. method: "POST",
  161. showLoading: true,
  162. };
  163. return new Promise(async (resolve, reject) => {
  164. const res = await requestNew(queryMenuConfig, options,false, ()=>{
  165. console.log('---------------------我执行了!')
  166. load()
  167. });
  168. const data = res;
  169. console.log("dataqueryMenuConfigAction", data.menuList)
  170. resolve(data);
  171. }).catch((error) => {
  172. reject(error);
  173. });
  174. }
  175. const goToLogin = () => {
  176. uni.navigateTo({
  177. url: '/login/login',
  178. });
  179. }
  180. function toNext(url) {
  181. navTo(url);
  182. }
  183. </script>
  184. <style>
  185. page {
  186. height: 100%;
  187. background: white;
  188. }
  189. .wrapper {
  190. padding-top: 150rpx;
  191. display: flex;
  192. background: #01243A;
  193. flex-direction: column;
  194. height: calc(100% - 150rpx);
  195. }
  196. .search-box {
  197. margin: 50rpx 40rpx;
  198. height: 72rpx;
  199. border-radius: 36rpx;
  200. background: #f7f7f7;
  201. display: flex;
  202. justify-content: center;
  203. align-items: center;
  204. }
  205. .search-box .icon {
  206. width: 48rpx;
  207. height: 48rpx;
  208. margin: 0 20rpx;
  209. }
  210. .search-box .search {
  211. flex: 1;
  212. margin-right: 20rpx;
  213. height: 100%;
  214. padding: 0 10rpx;
  215. font-size: 28rpx;
  216. color: black;
  217. background: transparent;
  218. }
  219. .content {
  220. display: flex;
  221. flex: 1;
  222. flex-grow: 1;
  223. background: #fff;
  224. border-radius: 30rpx 30rpx 0 0;
  225. padding-top: 40rpx;
  226. }
  227. .left {
  228. width: 180rpx;
  229. border-right: 1px solid #dcdcdc;
  230. margin-right: 29rpx;
  231. }
  232. .left .menu-text {
  233. font-size: 26rpx;
  234. color: #666666;
  235. width: 120rpx;
  236. }
  237. .left .menu {
  238. padding-left: 15rpx;
  239. display: flex;
  240. align-items: center;
  241. margin: 20rpx 0 60rpx 0;
  242. }
  243. .left .active .menu-text {
  244. font-weight: bold;
  245. line-height: 32rpx;
  246. font-family: NotoSansHans, NotoSansHans;
  247. font-size: 28rpx;
  248. color: #01243A;
  249. }
  250. .left .border {
  251. width: 9rpx;
  252. height: 26rpx;
  253. border-radius: 4rpx;
  254. margin-right: 20rpx;
  255. }
  256. .left .on {
  257. border-radius: 4rpx;
  258. font-size: 28rpx;
  259. background: var(--background);
  260. background-size: 100% 100%;
  261. }
  262. .right {
  263. flex: 1;
  264. }
  265. .bg-blue {
  266. background: var(--background);
  267. }
  268. .bg-orange {
  269. background: var(--background);
  270. }
  271. .right .text-orange {
  272. color: #fd8362;
  273. }
  274. .rightListVue {
  275. height: 100%;
  276. }
  277. .login-content{
  278. display: flex;
  279. display: flex;
  280. flex-direction: column;
  281. align-items: center;
  282. justify-content: center;
  283. margin-top: 232rpx;
  284. }
  285. .tips{
  286. color: #999999;
  287. font-size: 30rpx;
  288. text-align: center;
  289. }
  290. .custom-btn{
  291. width: 120rpx;
  292. height: 68rpx;
  293. background: radial-gradient(at 0% 0%, #01243A 0%, #004576 100%);
  294. border-radius: 68rpx;
  295. font-size: 26rpx;
  296. color: #FFFFFF;
  297. line-height: 68rpx;
  298. margin: 32rpx auto;
  299. text-align: center;
  300. }
  301. </style>