vue 按A-Z字母排序数据

<template><!-- 选择游戏 --><div class="game" :class="{'game__spacing': selectedGame.length > 0}"><!-- 搜索 --><div @click="searchGame" class="game__search"><div class="game__search-box"><span class="game__search-icon"></span><input@keyup="searchGame"ref="searchInput"v-focusclass="game__search-input"type="text"placeholder="搜索"v-model="searchGameName"></div></div><!-- 游戏名称列表 --><ul><li @click="handleOtherGame" class="game__block"><div class="game__item">其他游戏</div></li><!-- 热门游戏 --><li class="game__block"><div @click="handleGame(item)"v-for="(item,index) in hotGameList":key="'hot'+index"class="game__item":class="{'selected' : judgSelectedGame(item)}">{{item.app_name}}</div></li><li v-for="(item,key,idx) in gameList":key="idx"class="game__block"><div class="game__head" :class="{'selected': selectGameIndex === idx}">{{key}}</div><div @click="handleGame(member)"v-for="(member,index) in item":key="index"class="game__item":class="{'selected' : judgSelectedGame(member)}">{{member.app_name}}</div></li></ul><!-- 悬浮字符 --><ul class="game__pop-key"><li @click="handleKey(0, 'search')" class="game__pop-key-con"><i class="game__pop-key-search"></i></li><li @click="handleKey(1, 'hot')" class="game__pop-key-con"><i class="game__pop-key-hot"></i></li><li @click="handleKey(idx, 'list')"v-for="(item,key,idx) in gameList":key="'key'+idx"class="game__pop-key-con":class="{'selected':selectGameIndex === idx}"><div class="game__pop-key-box">{{key}}</div></li></ul><!-- 悬浮底部按钮 --><div v-if="selectedGame.length > 0" class="game__footer bottom-container"><ui-button @click="handleCancel" class="demo-button__small" :inline="true" :primary="false">取消</ui-button><ui-button @click="handelDefine" class="demo-button__small" :inline="true">确认</ui-button></div></div>
</template><script>
import { makePy } from "../assets/js/pinying"//导入插件获取所有城市中文的大写首字母
export default {name: 'SelectGame',components: {},data() {return{pageStatus: 'loading', //初始载入searchGameName: '', // 搜索名称games: [], //游戏数据gameList: [], //游戏列表hotGameList: [], //热门游戏selectGameIndex: 0, //当前游戏列表字符索引offsetTopArr: [], //所有字符head的offsetTopselectedGame: [], //}},computed: {},directives: {focus: {// 指令的定义inserted: function(el) {el.focus();}}},created() {this.initData();},mounted() {this.initGameData();window.addEventListener("scroll", this.pageScroll);},methods: {/*** 初始化页面数据*/initData() {let data = {gameList: [{id: "0", app_name: "爱心觉罗"},{id: "1", app_name: "地下城与勇士"},{id: "2", app_name: "穿越火线"},{id: "17", app_name: "QQ飞车"},{id: "1261", app_name: "QQ飞车手游"},{id: "214", app_name: "使命召唤"},{id: "232", app_name: "炫舞时代"},{id: "236", app_name: "流放之路"},{id: "237", app_name: "灵山奇缘"},{id: "1124", app_name: "欢乐麻将"},{id: "1183", app_name: "奇迹暖暖"},{id: "1104", app_name: "天天爱消除"},{id: "1194", app_name: "穿越火线(手游)"},{id: "1243", app_name: "魂斗罗"},{id: "1266", app_name: "拳皇命运"},{id: "10006", app_name: "部落冲突"},{id: "20063", app_name: "FIFAonline3"},],hotGame: [{id: "3", app_name: "穿越火线"},{id: "4", app_name: "王者荣耀"},{id: "5", app_name: "和平精英"}]}this.pageStatus = 'normal';this.games = data.gameList;this.picGameData(data.gameList);this.hotGameList = data.hotGame;this.selectedGame = this.$storage.get(this.$storage.keys.SELECT_GAME) ? this.$storage.get(this.$storage.keys.SELECT_GAME) : [];},/*** 格式化游戏字母排序* @param data 后台获取的游戏列表*/picGameData(data) {let gameList = [];data.map((item) => {//遍历数组,拿到城市名称let fristName = makePy(item.app_name)[0].substring(0, 1); //这里截取首字母的第一位//取全部城市的首字母if (!gameList[fristName]) {gameList[fristName] = [];}gameList[fristName].push(item)});this.gameList = Utils.kSort(gameList); //根据首字母键值对给原数据按首字母分类},/*** 获取所有锚点元素的 offsetTop*/initGameData() {let headContent = document.querySelectorAll('.game__head'); // 获取所有字符锚点元素let offsetTopArr = [];headContent.forEach(item => {this.offsetTopArr.push(item.offsetTop);})},/*** 点击开始搜索游戏*/searchGame () {this.$nextTick( () => {this.$refs.searchInput.focus();})let gameList = this.games;if (this.searchGameName !== '') {gameList = this.games.filter((item) => {return item.app_name.indexOf(this.searchGameName) !== -1})}this.picGameData(gameList);},/*** 点击其他游戏搜索*/handleOtherGame() {this.dialog = this.$createDialog({type: 'comment',showClose: true,title: '填写游戏名称',prompt: {value: '',placeholder: '请输入游戏名称,游戏名之间用","隔开...',maxlength: 200,indicator: 'indicator',autoExpand: true},confirmBtn: {text: '提交',active: true,disabled: true,href: 'javascript:;'},onConfirm: (e, promptValue) => {let list = [];list = promptValue.toString().split(',');this.$storage.set(this.$storage.keys.SELECT_GAME, list); // this.$router.go(-1);}});this.dialog.show();},/*** 点击选择游戏* @param item 游戏名称item*/handleGame(item) {if (this.judgSelectedGame(item)) {return}this.selectedGame.push(item.app_name);},/*** 判断是否选择了游戏* @param item 游戏名称item*/judgSelectedGame(item) {console.log('judg')let count = 0;this.selectedGame.map(it => {if (it === item.app_name) {count = 1;}})return count > 0 ? true : false;},/*** 页面滚动监听*/pageScroll() {// let scrollTop = $(window).scrollTop(); // 获取当前文档流的 scrollTop// // 定义当前点亮的导航下标// let keyIndex = 0;// this.offsetTopArr.map((item, index) => {//     if (scrollTop >= item - 100) {//         keyIndex = index//     }// })// this.selectGameIndex = keyIndex;},/*** 点击字符搜索游戏* @param index 字母序列索引* @param type 区分字母和图标*/handleKey(index, type) {if (type == 'search'){console.log('search')this.selectGameIndex = 0;$(window).scrollTop(0);this.$nextTick( () => {this.$refs.searchInput.focus();})return}if (type == 'search'){this.selectGameIndex = 0;$(window).scrollTop(0);return} let scrollTop = $(window).scrollTop(); // 获取当前文档流的 scrollTopthis.selectGameIndex = index;let targetOffsetTop = this.offsetTopArr[index];$(window).scrollTop(targetOffsetTop);},/*** 点击取消*/handleCancel() {this.selectedGame = [];},/*** 点击确认*/handelDefine() {this.$storage.set(this.$storage.keys.SELECT_GAME, this.selectedGame);this.$router.go(-1);}},beforeDestroy() {window.removeEventListener("scroll", this.pageScroll);}
}
</script><style lang="less" scoped>
@import "~@/assets/css/mixin.less";
@import "~@/assets/css/varibles.less";
@imgUrl: "../assets/img";
input {outline: none;caret-color: #2caf7d;outline-color: invert;outline-style: none;outline-width: 0px;border: none;border-style: none;text-shadow: none;-webkit-appearance: none;-webkit-user-select: text;outline-color: transparent;box-shadow: none;
}
input::-webkit-input-placeholder {color: #989898;
}
/deep/ .ui-cell::before {left: 0rem;
}
.game{min-height: 100vh;padding-bottom: 0.2rem;
}
.game__spacing{padding-bottom: 1.5rem;
}
.game__search{background: #fff;padding: 0.2rem 0.36rem;
}
.game__search-box{height: 0.6rem;background-color: #f0f5f6;border-radius: 0.3rem;.flex-second;padding: 0 0.3rem;
}
.game__search-icon{width: 0.31rem;height: 0.3rem;background: url('@{imgUrl}/search.png') no-repeat center center;background-size: 0.31rem 0.3rem;margin-right: 0.2rem;
}
.game__search-input{flex: 1;height: 0.6rem;background-color: #f0f5f6;border-radius: 0.3rem;
}
.game__block{background: #fff;
}
.game__head{height: 0.64rem;background-color: #f0f5f6;padding: 0 0.38rem;font-size: @fz28;color: #888888;.flex-second;
}
.game__head.selected{color: #01d5d8;
}
.game__item{height: 1rem;.flex-second;padding: 0 0.38rem;font-size: @fz28;color: #000;.line-one(top);
}
.game__item.selected{position: relative;&::before{content: '';width: 0.3rem;height: 0.22rem;background: url('@{imgUrl}/select.png') no-repeat center center;background-size: 0.3rem 0.22rem;position: absolute;top: 50%;right: 1rem;transform: translateY(-50%);}
}
.game__pop-key{position: fixed;top: 50%;right: 0rem;transform: translateY(-50%);
}
.game__pop-key-search{width: 0.3rem;height: 0.3rem;background: url('@{imgUrl}/pop-search.png') no-repeat center center;background-size: 0.16rem 0.16rem;
}
.game__pop-key-hot{width: 0.3rem;height: 0.3rem;background: url('@{imgUrl}/pop-start.png') no-repeat center center;background-size: 0.16rem 0.16rem;
}
.game__pop-key-con{.flex-center;width: 1rem;height: 0.46rem;
}
.game__pop-key-box{width: 0.3rem;height: 0.3rem;font-size: 0.18rem;color: #333;.flex-center;padding-top: 0.04rem;
}
.selected .game__pop-key-box{background-image: linear-gradient(0deg, #47d998 0%, #01d5d8 100%);color: #fff;border-radius: 50%;
}
.game__footer{position: fixed;bottom: 0;left: 0;width: 100%;background-color: #ffffff;box-shadow: 0px -10px 16px 0px rgba(174, 174, 192, 0.1);padding: 0.31rem 0.36rem;.flex-second;justify-content: space-between;
}
@media only screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) {.game__spacing{padding-bottom: 1.9rem;}
}
</style>
utils.jsfunction kSort (obj) {let keys = Object.keys(obj).sort(),sortedObj = {};for (var i in keys) {sortedObj[keys[i]] = obj[keys[i]];}return sortedObj;
}export default {kSort
}

pinying:https://gitee.com/dou_i_jiang/file_download

Mint UI实现A-Z字母排序的城市选择列表:http://www.uxys.com/html/Vue/20191228/26616.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/401478.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

用rem来做响应式开发

电脑版的商城昨晚做完了&#xff0c;今天赶着做手机端的&#xff0c;提到手机端的网站第一个想到的就是要 适应不同手机屏幕的宽度&#xff0c;保证在不同手机上都能正常显示给用户&#xff0c;我之前做这类网站都是无脑引进bootstrap的。但前一个项目做完之后我发现bootstrap虽…

c 连接mysql

apt-get install libmysqlclient-dev mysql 使用的是xampp 需要指定sock 源码&#xff1a;main.c #if defined(_WIN32) || defined(_WIN64) //为了支持windows平台上的编译 #include <windows.h> #endif #include <stdio.h> #include <stdlib.h> #include &…

Java 编程下 Eclipse 如何设置单行代码显示的最大宽度

Eclipse 下一行代码的默认宽度是 80 &#xff0c; 稍长一点的一行代码就会自动换行&#xff0c;代码可读性较差&#xff0c;我们可以自己在 Eclipse 对代码宽度进行设置。 设置路径为&#xff1a;【Window】→【Preferences】→【Java】→【Code Style】→【Formatter】&#x…

前端公共reset.css模板

简介学习地址&#xff1a; https://meyerweb.com/eric/tools/css/reset/重置样式表的目的是减少浏览器在默认行高&#xff0c;标题的边距和字体大小等方面的不一致。重置样式特意是非常通用的/* http://meyerweb.com/eric/tools/css/reset/ v2.0 | 20110126License: none (publ…

基于VMWare配置VxWorks开发环境

常规VxWorks的开发环境都是基于目标开发板或目标机来构建的&#xff0c;但并非所有人都具备这样的条件&#xff0c;所以本文主要介绍如何基于vmware来构建VxWorks开发环境。Step 1. 安装vmware 首先需要安装vmware, 版本没有什么限制&#xff0c;我装的是vmware 8.0&#xff0c…

plan

工作&#xff1a; plan A 确定用什么环境和工具进行开发&#xff0c;并让老杨了解。 如何支持骨骼动画模型&#xff0c;这是最关键部分。 交互和用户体验方面进行完善。 plan B 太极拳网站 前台&#xff1a;silverlight4.0 后台&#xff1a;java 数据库&#xff1a;mysql 生活…

keepalived实现高可用nginx反向代理的简单案例

写在前面&#xff1a;如果此文有幸被某位朋友看见并发现有错的地方&#xff0c;希望批评指正。如有不明白的地方&#xff0c;愿可一起探讨。案例拓扑图安装keepalived和nginx安装keepalived# yum -y install keepalived创建nginx用户组及nginx用户# groupadd -r nginx # userad…

Vue 父子组件双向绑定传值

最简单的双向绑定&#xff08;单文件中&#xff09;就是表单元素的v-model了&#xff0c;如果同时设置v-model和value&#xff0c;value属性无效。 自定义v-model&#xff1a;&#xff08;不推荐&#xff09; child: <template><h1>{{ msg }}</h1> </te…

java逻辑运算符

// | 或 & 与 int x3; System.out.println(x>2&x<5); // ||短路或 &&短路与 区别短路逻辑表达式判断第一个表达式&#xff0c;如果出结果直接返回true/false &#xff0c;而非短路直到逻辑运算式全部运行完毕才返回&#xff1b; System.out.println…

json--js

json对象与js对象的转换&#xff1a; json2.js var jsObj{a:"1",b:"2" }var jsonObjJSON.stringify(jsObj); var aJSON.parse(jsonObj).a; alert(a);1. JSON.stringify 将js对象转为json 2. JSON.parse 将json对象转为js转载于:https://www.cnblogs.…

给easyui datagrid 添加mouseover和mouseout事件

http://www.loststop.com/archive/soft-and-internet/3819.html http://www.loststop.com/easyui/demo/datagrid6.html

关于自定义控件,可以编译通过,但是用时提示无法创建新实例。

上网查询发现 这种错误通常是控件中使用的配置信息存在于配置文件里&#xff0c;而在程序没有运行时&#xff0c;获取不到配置信息造成的。 例如&#xff1a; 错误用法&#xff1a; string strUri Application.Current.Resources["WcfServiceUrl"].ToString();//引发…

leetcode 3Sum C++

荒废好久没更新了&#xff0c;时间过得很快&#xff0c;转眼就2017年了&#xff0c;经历了苦闷的科研阶段&#xff0c;发了论文顺利毕业&#xff1b;也经过三地辗转奔波来去的找工作&#xff0c;最终还是犹犹豫豫选择了自己知道以后可能会后悔的&#xff0c;果然就后悔了。所以…

JavaScript 函数循环、延时、节流、防抖

函数循环(setInterval) 间隔指定的毫秒数不停地执行指定的代码 <button onclick"myStartFunction()">开始</button> <button onclick"myStopFunction()">停止</button><script> var myVar null; //全局function myTimer…

bash知识点:文件测试

bash知识点&#xff1a;文件测试&#xff08;测试文件是否存在&#xff0c;文件是某种类型&#xff09;单目测试-e file:测试文件是是否存在-a file&#xff1a;测试文件是是否存在-f file&#xff1a;测试是否为普通文件,是为真&#xff0c;否则为假-d file&#xff1a;测试是…

MVC 4 教程

MVC4 前件&#xff1a;visual studio 10 sp1 http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4 &#xff08;by Rick Anderson&#xff09; Music Store (by Jon Galloway) http://www.asp.net/mvc/tutorials/mvc-music-sto…

Linux下java/bin目录下的命令集合

Linux下JAVA命令&#xff08;1.7.0_79&#xff09; 命令 详解 参数列表 示例 重要程度 资料 appletviewer Java applet 浏览器。appletviewer 命令可在脱离万维网浏览器环境的情况下运行 applet。 Usage: appletviewer <options> url(s) where <options> …

火车采集小结

采集一个页面全部内容的正则&#xff1a;^(?<content>[\s\S]*?)$转载于:https://www.cnblogs.com/afish/p/3984680.html

vscode 开发常用

设置缩进空格&#xff1a;2个| 4个 文件–》首选项–》设置 代码缩进对齐 &#xff1a; Ctrl [ 和 Ctrl ] 实现文本的向左移动或者向右移动&#xff1b; Shift Alt F 实现代码的对齐

新手应该如何Javascript,JDom,JQuery,DWZ。。

作为web前端程序员来说想必这些东西大家都很熟悉了...但是作为初学者来说,如何学习 是一个很重要的问题,其实这些东西并不难,只是我们在学习的时候没有理清楚他们之间的概念导致我们盲目的学习, 以我自己为例子&#xff0c;希望能帮助到大家的学习。 在这之前我假设大家理解了…