addressBook.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <template>
  2. <view>
  3. <view @tap="closeFrame">
  4. <cu-custom bgColor="bg-gradual-sisBlack" :isBack="true">
  5. <block slot="backText">
  6. <view style="height: 80rpx;line-height: 80rpx;color: silver;">返回</view>
  7. </block>
  8. <block slot="content">
  9. <view style="color: silver;">聊天通讯</view>
  10. </block>
  11. </cu-custom>
  12. </view>
  13. <!-- 搜索标签 -->
  14. <view class="cu-bar bg-white search fixed" :style="[{top:CustomBar + 'px'}]"> <!-- :style="[{top:CustomBar + 'px'}]" -->
  15. <view class="search-form round" @touchstart="accordingTo">
  16. <text class="cuIcon-search"></text>
  17. <input type="text" placeholder="输入搜索的关键词" confirm-type="search" v-model="search"></input>
  18. </view>
  19. <view class="action">
  20. <button class="cu-btn bg-gradual-sisBlack shadow-blur round" @click="accordingOut">取消</button>
  21. </view>
  22. </view>
  23. <!-- 搜索列表 -->
  24. <view class="search-content " ref="search" >
  25. <block>
  26. <view class="cu-list menu-avatar no-padding mar_t" >
  27. <!-- <view class="cu-avatar">{{item.name}}</view> 字母开头显示 -->
  28. <!-- 将汉字以当前字母开头的遍历 -->
  29. <view class="cu-item " v-for="item in userListData" >
  30. <view v-if="item.remak1==1">
  31. <view class="content" @click="go(userid,lastUserName,items.nickname,items.id,1)">
  32. <view class="text-grey">{{item.username}}({{item.remak2}})<!-- <text class="text-abc">{{items.name}}</text>君 --></view>
  33. <view class="text-gray text-sm">
  34. 有条消息
  35. </view>
  36. </view>
  37. <!-- 在线离线标识 -->
  38. <text class="cuIcon-radioboxfill text-green" style="margin-right: 3px;">在线</text>
  39. </view>
  40. <view v-if="item.remak1==0">
  41. <view class="content" @click="go(userid,lastUserName,item.nickname,item.id,0)">
  42. <view class="text-grey">{{item.username}}({{item.remak2}})<!-- <text class="text-abc">{{items.name}}</text>君 --></view>
  43. <view class="text-gray text-sm">
  44. 有条消息
  45. </view>
  46. </view>
  47. <text class="cuIcon-radioboxfill text-gray" style="margin-right: 3px;">离线</text>
  48. </view>
  49. </view>
  50. </view>
  51. <!-- <view :class="'indexItem-' + item.name" :id="'indexes-' + item.name" :data-index="item.name">
  52. <view class="padding"></view>
  53. <view class="cu-list menu-avatar no-padding" >
  54. <view class="cu-item" @tap="common.navTo('/components/mine/addressBook/chat?name='+item+'&send='+send+'&receive='+receive+'&sendname='+sendname+'&receivename='+receivename)">
  55. <view class="cu-avatar round lg"></view>
  56. <view class="content" >
  57. <view class="text-grey">{{item.name}}</view>
  58. </view>
  59. </view>
  60. </view>
  61. </view> -->
  62. </block>
  63. </view>
  64. <!-- 通讯列表 -->
  65. <scroll-view scroll-y class="indexes" :scroll-into-view="'indexes-'+ listCurID" :style="[{height:'calc(100vh - '+ CustomBar + 'px - 50px)'}]"
  66. :scroll-with-animation="true" :enable-back-to-top="true" v-if="play">
  67. <!-- <block v-for="(item,index) in list" :key="index"> -->
  68. <!-- 控制侧导航栏 -->
  69. <!-- <view :class="'indexItem-' + item.name" :id="'indexes-' + item.name" :data-index="item.name"> -->
  70. <!-- <view class="padding">{{item.name}}</view> -->
  71. <view class="cu-list menu-avatar no-padding" >
  72. <!-- <view class="cu-avatar">{{item.name}}</view> 字母开头显示 -->
  73. <!-- 将汉字以当前字母开头的遍历 -->
  74. <view class="cu-item" v-for="(items,sub) in userList" :key="sub" >
  75. <view v-if="items.remak1==1">
  76. <view class="content" @click="go(userid,lastUserName,items.nickname,items.id,1)">
  77. <view class="text-grey">{{items.username}}({{items.remak2}})<!-- <text class="text-abc">{{items.name}}</text>君 --></view>
  78. <view class="text-gray text-sm">
  79. 有{{items.remak1}}条消息
  80. </view>
  81. </view>
  82. <!-- 在线标识 -->
  83. <text class="cuIcon-radioboxfill text-green" style="margin-right: 3px;">在线</text>
  84. </view>
  85. <view v-if="items.remak1==0">
  86. <view class="content" @click="go(userid,lastUserName,items.nickname,items.id,0)">
  87. <view class="text-grey">{{items.username}}({{items.remak2}})<!-- <text class="text-abc">{{items.name}}</text>君 --></view>
  88. <view class="text-gray text-sm">
  89. 有{{items.remak1}}条消息
  90. </view>
  91. </view>
  92. <!-- 离线标识 -->
  93. <text class="cuIcon-radioboxfill text-gray" style="margin-right: 3px;">离线</text>
  94. </view>
  95. </view>
  96. </view>
  97. <!-- </view>
  98. </block> -->
  99. </scroll-view>
  100. <!-- 侧导航栏 -->
  101. <!-- <view class="indexBar" :style="[{height:'calc(100vh - ' + CustomBar + 'px - 50px)'}]">
  102. <view class="indexBar-box" @touchstart="tStart" @touchend="tEnd" @touchmove.stop="tMove">
  103. <view class="indexBar-item" v-for="(item,index) in list" :key="index" :id="index" @touchstart="getCur" @touchend="setCur"> {{item.name}}</view>
  104. </view>
  105. </view> -->
  106. <!--选择显示 keyword-->
  107. <view v-show="!hidden" class="indexToast">
  108. <!-- {{listCur}} -->
  109. </view>
  110. <initial ref="initial"></initial>
  111. </view>
  112. </template>
  113. <script>
  114. import pinyin from './index.js';
  115. import initial from './InitializeThe.vue';
  116. export default {
  117. components: {
  118. initial: initial
  119. },
  120. data() {
  121. return {
  122. userid:'',
  123. lastUserName:'',
  124. StatusBar: this.StatusBar,
  125. CustomBar: this.CustomBar,
  126. listCurID: '',
  127. list: [],
  128. listCur: '',
  129. send:'1',
  130. receive:'2',
  131. hidden: true,
  132. play:true,
  133. sendname:'ming',
  134. receivename:'fang',
  135. search:'',
  136. timer: null,
  137. userList:{
  138. id:'',
  139. nickname:'',
  140. password:'',
  141. remak1:'',
  142. username:'',
  143. remak2:'',
  144. },
  145. biaos:2,
  146. socketTask_getUserList:'',
  147. };
  148. },
  149. created: function() {
  150. this.getUserList();
  151. /* this.pinyin(); */
  152. },
  153. onLoad() {
  154. this.getUserList();
  155. let list = [{}];
  156. for (let i = 0; i < 26; i++) {
  157. list[i] = {};
  158. list[i].name = String.fromCharCode(65 + i);
  159. }
  160. this.list = list;
  161. this.listCur = list[0];
  162. },
  163. onReady() {
  164. let that = this;
  165. /* uni.createSelectorQuery().select('.indexBar-box').boundingClientRect(function(res) {
  166. that.boxTop = res.top
  167. }).exec();
  168. uni.createSelectorQuery().select('.indexes').boundingClientRect(function(res) {
  169. that.barTop = res.top
  170. }).exec(); */
  171. /*
  172. this.pinyin(); */
  173. },
  174. computed: {
  175. backStageIp: function() {
  176. return this.$store.state.wholeSituationBackStageIp;
  177. },
  178. backStagePort: function() {
  179. return this.$store.state.wholeSituationBackStagePort;
  180. },
  181. windpowerstationNameToId: function() {
  182. return this.$store.state.windpowerstationNameToId;
  183. },
  184. userListData: function() {
  185. var search = this.search;
  186. if(!this.search){
  187. return [];
  188. }
  189. else if (search) {
  190. return this.userList.filter(function(userList) {
  191. return Object.keys(userList).some(function(key) {
  192. return String(userList[key]).toLowerCase().indexOf(search) > -1
  193. })
  194. })
  195. }
  196. return this.products;
  197. },
  198. hasNoData () {
  199. return !this.list.length
  200. }
  201. },
  202. methods: {
  203. go(userid,lastUserName,nickname,id,bool){
  204. let _this=this;
  205. /* if(bool==0){
  206. window.location.href="https://192.168.1.102:4397/websocket/usercontroller/viewoffline?send="+userid+"&receive="+id+"&sendname="+lastUserName+"&receivename="+nickname;
  207. }
  208. if(bool==1){
  209. window.location.href="https://192.168.1.102:4397/websocket/usercontroller/view?send="+userid+"&receive="+id+"&sendname="+lastUserName+"&receivename="+nickname;
  210. } */
  211. this.child(id,bool);
  212. /*
  213. let _this=this;
  214. if(bool==0){
  215. window.location.href="https://192.168.1.102:4397/websocket/usercontroller/viewoffline?send="+userid+"&receive="+id+"&sendname="+lastUserName+"&receivename="+nickname;
  216. }
  217. if(bool==1){
  218. window.location.href="https://192.168.1.102:4397/websocket/usercontroller/view?send="+userid+"&receive="+id+"&sendname="+lastUserName+"&receivename="+nickname;
  219. }
  220. */
  221. },
  222. child(id){
  223. this.$refs.initial.childMethod(id);
  224. },
  225. accordingOut(){
  226. this.play=true;
  227. this.search='';
  228. },
  229. accordingTo(){
  230. this.play=false;
  231. },
  232. pinyin(str){
  233. var l = pinyin.getSpell(str).substring(0,1);
  234. console.log(l);
  235. },
  236. /* handleCityClick (city) {
  237. this.changeCity(city)
  238. this.$router.push('/')
  239. }, */
  240. closeFrame: function() {
  241. this.count = this.count + 1;
  242. if (this.isFrameShow) {
  243. this.isFrameShow = false;
  244. this.sanJiao = 'sanJiaoDown';
  245. }
  246. },
  247. async getUserList() {
  248. let _this = this;
  249. // 创建一个this.socketTask对象【发送、接收、关闭socket都由这个对象操作】
  250. this.socketTask_getUserList = uni.connectSocket({
  251. // 【非常重要】必须确保你的服务器是成功的,如果是手机测试千万别使用ws://127.0.0.1:9099【特别容易犯的错误】
  252. url: 'ws://' + this.backStageIp + ':' + this.backStagePort + '/websocket/pageNumber_4/functionNumber_3/all',
  253. success(data) {
  254. console.log(data);
  255. }
  256. });
  257. /* let windpowerstationid = uni.getStorageSync('windpowerstationName'); */
  258. // 消息的发送和接收必须在正常连接打开中,才能发送或接收【否则会失败】
  259. this.socketTask_getUserList.onOpen(res => {
  260. console.log('WebSocket连接正常打开中...!');
  261. this.is_open_socket = true;
  262. // 注:只有连接正常打开中 ,才能正常收到消息
  263. this.socketTask_getUserList.onMessage(res => {
  264. console.log("收到服务器内容:" + res.data);
  265. /* _this.windpowerstationdetail.getUserList = JSON.parse(res.data); */
  266. _this.userList = JSON.parse(res.data);
  267. _this.lastUserName = uni.getStorageSync('gyeeusername');
  268. _this.userid = uni.getStorageSync('userid');
  269. });
  270. });
  271. },
  272. //获取文字信息
  273. getCur(e) {
  274. this.hidden = false;
  275. this.listCur = this.list[e.target.id].name;
  276. },
  277. setCur(e) {
  278. this.hidden = true;
  279. this.listCur = this.listCur
  280. },
  281. //滑动选择Item
  282. tMove(e) {
  283. let y = e.touches[0].clientY,
  284. offsettop = this.boxTop,
  285. that = this;
  286. //判断选择区域,只有在选择区才会生效
  287. if (y > offsettop) {
  288. let num = parseInt((y - offsettop) / 20);
  289. this.listCur = that.list[num].name
  290. };
  291. },
  292. //触发全部开始选择
  293. tStart() {
  294. this.hidden = false
  295. },
  296. //触发结束选择
  297. tEnd() {
  298. this.hidden = true;
  299. this.listCurID = this.listCur
  300. },
  301. indexSelect(e) {
  302. let that = this;
  303. let barHeight = this.barHeight;
  304. let list = this.list;
  305. let scrollY = Math.ceil(list.length * e.detail.y / barHeight);
  306. for (let i = 0; i < list.length; i++) {
  307. if (scrollY < i + 1) {
  308. that.listCur = list[i].name;
  309. that.movableY = i * 20
  310. return false
  311. }
  312. }
  313. }
  314. },
  315. }
  316. </script>
  317. <style>
  318. body {
  319. font-family: '方正兰亭细黑_GBK';
  320. font-size: 20px;
  321. color: silver;
  322. background: #000;
  323. }
  324. @font-face {
  325. font-family: '方正兰亭细黑_GBK';
  326. src: url(../../../static/fzltxh.TTF);
  327. }
  328. page {
  329. background-color: #1f1f1f;
  330. font-family: '方正兰亭细黑_GBK';
  331. overflow-x: hidden;
  332. }
  333. .indexes {
  334. position: relative;
  335. }
  336. .indexBar {
  337. position: fixed;
  338. right: 0px;
  339. bottom: 0px;
  340. padding: 20upx 20upx 20upx 60upx;
  341. display: flex;
  342. align-items: center;
  343. }
  344. .indexBar .indexBar-box {
  345. width: 40upx;
  346. height: auto;
  347. background: #fff;
  348. display: flex;
  349. flex-direction: column;
  350. box-shadow: 0 0 20upx rgba(0, 0, 0, 0.1);
  351. border-radius: 10upx;
  352. }
  353. .indexBar-item {
  354. flex: 1;
  355. width: 40upx;
  356. height: 40upx;
  357. display: flex;
  358. align-items: center;
  359. justify-content: center;
  360. font-size: 24upx;
  361. color: #888;
  362. }
  363. movable-view.indexBar-item {
  364. width: 40upx;
  365. height: 40upx;
  366. z-index: 9;
  367. position: relative;
  368. }
  369. movable-view.indexBar-item::before {
  370. content: "";
  371. display: block;
  372. position: absolute;
  373. left: 0;
  374. top: 10upx;
  375. height: 20upx;
  376. width: 4upx;
  377. background-color: #f37b1d;
  378. }
  379. .indexToast {
  380. position: fixed;
  381. top: 0;
  382. right: 80upx;
  383. bottom: 0;
  384. background: rgba(0, 0, 0, 0.5);
  385. width: 100upx;
  386. height: 100upx;
  387. border-radius: 10upx;
  388. margin: auto;
  389. color: #fff;
  390. line-height: 100upx;
  391. text-align: center;
  392. font-size: 48upx;
  393. }
  394. .bg-white{
  395. background-color: #242424;
  396. }
  397. .cu-list,.menu-avatar>.cu-item {
  398. background-color: #242424;
  399. }
  400. .cu-avatar{
  401. height: 20px;
  402. width: 20px;
  403. }
  404. .mar_t{
  405. margin-top: 50px;
  406. }
  407. .text-grey{
  408. margin-top: -10px;
  409. }
  410. </style>