帖子
帖子
用户
博客
课程
123下一页
返回列表 发新帖
这边发给楼上给给看下,在帖子里回复你
283
帖子
4
勋章
4927
Y币
scroll-view做循环,不卡才怪
0
帖子
2
勋章
1006
Y币
本帖最后由 至高吾·尚 于 2022-11-27 22:13 编辑
ColdKiller · 2022-11-22 19:18已简化demo上传,请技术人员帮忙看下啥问题,万分感谢~~~~

你好,下载了你的demo,运行报错,简单看了一下,demo存在一些错误,比如引用路径错误,引用文件缺失等问题,还需要麻烦你自己提供一个可以运行的demo上来,否则无法运行,技术很难理解你的项目的需求点,问题点,没法进一步的帮您解决问题。个人建议您精简demo以后,先本地运行下,OK后再发上来,避免我们增加反复沟通的成本。或者您可以提供一下您这边想实现的需求目标,最好有一个UI样式图和需求业务逻辑的介绍,我们这边也可以看看是不是可以给您提供一个对应的示范demo

WX20221125-032446@2x.png
100
帖子
2
勋章
1960
Y币
至高吾·尚 · 2022-11-25 03:29你好,下载了你的demo,运行报错,简单看了一下,demo存在一些错误,比如引用路径错误,引用文件缺失等问题,还需要麻烦你自己提供一个可以运行的demo上来,否则无法运行,技术很难理解你的项目的需求点,问题点, ...

你好,demo已调整重新上传,之前上传的demo确实有引用文件缺失了。循环卡顿问题还请麻烦核实一下~
AvmTest.zip 下载附件
2022-11-29 14:16上传7.01 MB下载次数: 24
这边把问题转给开发看了,等下开发回复
100
帖子
2
勋章
1960
Y币
技术咨询-特特 · 2022-12-6 17:15这边把问题转给开发看了,等下开发回复

好的 辛苦了
0
帖子
2
勋章
1006
Y币
本帖最后由 至高吾·尚 于 2022-12-7 14:12 编辑

你好,我看了提供的demo源码,并了解了实际的业务需求,现提供两种解决方案:

方案1:
将UIActionSelector.open接口中使用的datas数据源,由动态生成的对象,转化为引用静态的json文件,这样就避免了每次引用该子组件时,都先动态3层遍历的去计算datas的数据源,也就规避掉了你现在反馈的问题;
QQ20221207-134255@2x.png

方案2:
将UIActionSelector模块为UICustomPicker模块,该模块支持自定义每一个层级内容,各个层级之间的数据源是解耦的,这样就不用在最开始模块初始化的时候将全部的3层进行深度遍历了,只需要计算当前的层级就可以了。具体提供给你一个《30天,App开发从0到1》书籍中的一个时间选择器案例代码供你参考(见附件)
QQ20221207-140048.png
book_2_8_1.zip 下载附件
2022-12-7 14:01上传15.44 KB下载次数: 19
100
帖子
2
勋章
1960
Y币
至高吾·尚 · 2022-12-7 14:02你好,我看了提供的demo源码,并了解了实际的业务需求,现提供两种解决方案:

方案1:

好的,非常感谢技术人员的帮助。但是针对方案一的建议,已经尝试过把1950-2022年度的数据写入json文件,然后当页面载入的时候从这个json文件读取数据,仍然会出现卡顿的情况出现。方案二还在研究过程中。
100
帖子
2
勋章
1960
Y币
至高吾·尚 · 2022-12-7 14:02你好,我看了提供的demo源码,并了解了实际的业务需求,现提供两种解决方案:

方案1:

针对方案二,UICustomPicker组件使用存在样式和展示问题:
(1)时间展示范围选择的是1950-2022,结果展示时间不连续,分时间段展示;
(2)组件hide方法存在问题,使用过程中无效,且组件会跟着页面上下滚动,而不是定位到所需要的位置。
  1. <template name="calendar-date">
  2.         <view>
  3.                 <text style="display:none;">{{getDate}}</text>
  4.                 <a-cell class="a-field" is-link arrowDirection="down" :required="required" :title="title" :__last="__last"
  5.                         @click="chooseDate()">
  6.                         <template _slot="value" class="field__body">
  7.                                 <text :class="selectDate?'field__value':'field__placeholder'">{{selectDate?selectDate:placeholder}}</text>
  8.                         </template>
  9.                 </a-cell>
  10.         </view>
  11. </template>

  12. <script>
  13. import { syncModel } from "./avm-ui/utils";
  14. export default {
  15.         name: 'calendar-date',
  16.         install() {
  17.                 if (this.props["$value"]) {
  18.                         syncModel.call(this);
  19.                 }
  20.         },
  21.         computed: {
  22.                 getDate() {
  23.                         if (this.value) {
  24.                                 this.data.selectDate = this.value;
  25.                                 this.initDateIndex();
  26.                         } else {
  27.                                 this.data.selectDate = "";
  28.                         }
  29.                         return this.value
  30.                 },
  31.         },
  32.         props: {
  33.                 value: {
  34.                         default: () => ""
  35.                 },
  36.                 title: {
  37.                         default: () => ""
  38.                 },
  39.                 required: {
  40.                         default: () => false
  41.                 },
  42.                 __last: {
  43.                         default: () => false
  44.                 },
  45.                 placeholder: {
  46.                         default: () => ""
  47.                 },
  48.                 readonly: {
  49.                         default: () => false
  50.                 },
  51.                 clearAble: {
  52.                         default: () => false
  53.                 },
  54.         },
  55.         data() {
  56.                 return {
  57.                         selectDate: "",
  58.                         calendarData: [],
  59.                         actives: [0, 0, 0],
  60.                         vPickerId: null,
  61.                         oSelectedData: null
  62.                 }
  63.         },
  64.         methods: {
  65.                 initDateIndex(){
  66.                         let myDate = new Date();
  67.                         let nowYear = myDate.getFullYear();
  68.                         let year_index = 0;
  69.                         let month_index = 0;
  70.                         let day_index = 0;
  71.                         if (this.data.selectDate) {
  72.                                 let tmpDate = new Date(this.data.selectDate);
  73.                                 let tmpYear = tmpDate.getFullYear();
  74.                                 let tmpMonth = tmpDate.getMonth() + 1;
  75.                                 let tmpDay = tmpDate.getDate();
  76.                                 year_index = nowYear - tmpYear;
  77.                                 month_index = tmpMonth - 1;
  78.                                 day_index = tmpDay - 1;
  79.                         } else {
  80.                                 let tmpDate = new Date(myDate);
  81.                                 let tmpYear = tmpDate.getFullYear();
  82.                                 let tmpMonth = tmpDate.getMonth() + 1;
  83.                                 let tmpDay = tmpDate.getDate();
  84.                                 year_index = nowYear - tmpYear;
  85.                                 month_index = tmpMonth - 1;
  86.                                 day_index = tmpDay - 1;
  87.                         }
  88.                         this.data.actives = [year_index, month_index, day_index];
  89.                 },
  90.                 initDateData(){
  91.                         let tNow = new Date();
  92.                         let tYear = tNow.getFullYear();  // 获取当前年份
  93.                         let tMonth = tNow.getMonth();    // 获取当前月份
  94.                         let tDate = tNow.getDate();      // 获取当前日期
  95.                         let tMinYear = 1950;    // 可选最小时间,100年前
  96.                         let tMaxYear = tYear;    // 可选最大时间,100年后
  97.                         let that = this;
  98.                         var UICustomPicker = api.require('UICustomPicker');
  99.                         UICustomPicker.open({
  100.                                 rect: {
  101.                                         x: 30,
  102.                                         y: api.frameHeight / 2 - 170,
  103.                                         w: api.frameWidth - 60,
  104.                                         h: 135
  105.                                 },
  106.                                 styles: {
  107.                                         bg: 'rgba(61,61,61,0.0)',        //(可选项)字符串类型;选中内容区域的背景,支持 rgb,rgba,#,图片路径(本地路径,fs://、widget://);默认:'rgba(0,0,0,0)'
  108.                                         normalColor: '#959595',     //(可选项)字符串类型;未选中内容的字体颜色,支持 rgb,rgba,#;默认:'#959595'
  109.                                         normalSize:15,              //(可选项)数字类型;未选中内容字体大小;默认:15
  110.                                         selectedColor: '#3685dd',   //(可选项)字符串类型;选中内容的字体颜色,支持 rgb,rgba,#;默认:'#3685dd'
  111.                                         disableSelectColor: '#EDEDED',//(可选项)字符串类型;不可选中项的字体颜色,支持 rgb,rgba,#;默认:'#EDEDED'
  112.                                         selectedSize: 28,           //(可选项)数字类型;选中内容的字体大小;默认:36.0
  113.                                         tagColor: '#3685dd',        //(可选项)字符串类型;内容标签的字体颜色,支持 rgb,rgba,# ;默认:'#3685dd'
  114.                                         tagSize: 12,                //(可选项)数字类型;内容标签的字体大小;默认:12
  115.                                         tagMarginR:0,              //(可选项)数字类型;标签距离当前picker的右边框的距离;默认:0
  116.                                         pickersWidth:[33, 33, 33]   //(可选项)数组类型;picker所占模块宽度的百分比,不传时均分模块宽度,数组长度等于data数组的长度
  117.                                 },
  118.                                 data: [{
  119.                                         tag: '年',
  120.                                         scope: tMinYear + '-' + tMaxYear
  121.                                 }, {
  122.                                         tag: '月',
  123.                                         scope: '1-12'
  124.                                 }, {
  125.                                         tag: '日',
  126.                                         scope: '1-31'
  127.                                 }],
  128.                                 autoHide: false,
  129.                                 loop: true,
  130.                                 rows: 3,
  131.                                 fixedOn: api.frameName,
  132.                                 fixed: true
  133.                         }, function(ret, err) {
  134.                                 if (ret) {
  135.                                         if('number' == typeof ret.id) {
  136.                                                 that.data.vPickerId = ret.id;  // 记录当前模块的ID
  137.                                         }
  138.                                         if('show' === ret.eventType) {
  139.                                                 // 设置当前时间为默认值
  140.                                                 var tDefault = [tYear,tMonth+1,tDate];
  141.                                                 that.fnSetSelectedValue(tDefault);
  142.                                         }
  143.                                         if('selected' === ret.eventType) {
  144.                                                 //判断选择值的合法性
  145.                                                 let sDate = that.fnCheckSelectedValue(ret.data);
  146.                                                 if(sDate) {
  147.                                                         let nDate = new Date(sDate);
  148.                                                         let year = nDate.getFullYear();
  149.                                                         let month = nDate.getMonth();
  150.                                                         if (month && month.toString().length == 1) {
  151.                                                                 month = "0" + month;
  152.                                                         }
  153.                                                         let day = nDate.getDate();
  154.                                                         if (day && day.toString().length == 1) {
  155.                                                                 day = "0" + day;
  156.                                                         }
  157.                                                         let date = year + "-" + month + "-" + day;
  158.                                                         that.data.selectDate = date;
  159.                                                         that.setValue(date);
  160.                                                         that.hideDate();
  161.                                                         that.fire('selectDate', {
  162.                                                                 date: date
  163.                                                         });
  164.                                                 }
  165.                                         }
  166.                                 } else {
  167.                                         that.clearDate();
  168.                                 }
  169.                         });                               
  170.                 },
  171.                 initDateIndex() {
  172.                         let myDate = new Date();
  173.                         let nowYear = myDate.getFullYear();
  174.                         let year_index = 0;
  175.                         let month_index = 0;
  176.                         let day_index = 0;
  177.                         if (this.data.selectDate) {
  178.                                 let tmpDate = new Date(this.data.selectDate);
  179.                                 let tmpYear = tmpDate.getFullYear();
  180.                                 let tmpMonth = tmpDate.getMonth() + 1;
  181.                                 let tmpDay = tmpDate.getDate();
  182.                                 year_index = nowYear - tmpYear;
  183.                                 month_index = tmpMonth - 1;
  184.                                 day_index = tmpDay - 1;
  185.                         } else {
  186.                                 let tmpDate = new Date(myDate);
  187.                                 let tmpYear = tmpDate.getFullYear();
  188.                                 let tmpMonth = tmpDate.getMonth() + 1;
  189.                                 let tmpDay = tmpDate.getDate();
  190.                                 year_index = nowYear - tmpYear;
  191.                                 month_index = tmpMonth - 1;
  192.                                 day_index = tmpDay - 1;
  193.                         }
  194.                         this.data.actives = [year_index, month_index, day_index];
  195.                 },
  196.                 //判断是否为闰年
  197.                 isLeapYear(year) {
  198.                         if ((year % 4 === 0) && (year % 100 !== 0 || year % 400 === 0)) {
  199.                                 return true
  200.                         } else {
  201.                                 return false
  202.                         }
  203.                 },
  204.                 //计算每个月的天数
  205.                 getDayNumByYearMoth(year, month) {
  206.                         let day = 1;
  207.                         switch (month) {
  208.                                 case 1:
  209.                                 case 3:
  210.                                 case 5:
  211.                                 case 7:
  212.                                 case 8:
  213.                                 case 10:
  214.                                 case 12:
  215.                                         day = 31;
  216.                                         break
  217.                                 case 4:
  218.                                 case 6:
  219.                                 case 9:
  220.                                 case 11:
  221.                                         day = 30;
  222.                                         break;
  223.                                 case 2:
  224.                                         day = this.isLeapYear(year) ? 29 : 28;
  225.                                         break;
  226.                                 default:
  227.                         }
  228.                         return day
  229.                 },
  230.                 chooseDate() {
  231.                         if (this.readonly) {
  232.                                 return
  233.                         }
  234.                         this.initDateData();
  235.                 },
  236.                 /**
  237.                  * 判断选择值的合法性
  238.                  * @param  {Array} pData 日期选择器选择后的回调数据
  239.                  * @return {void}
  240.                  */
  241.                 fnCheckSelectedValue(pData) {
  242.                         if('[object Array]' !== Object.prototype.toString.call(pData)) {
  243.                                   return;
  244.                         }
  245.                         //判断特殊日期
  246.                         //获取月份进行判断
  247.                         let tData = pData;
  248.                         switch (tData[1]) {
  249.                                   case '2':
  250.                                             //判断是否为闰年
  251.                                             let tNum = '28';
  252.                                             if(this.isLeapYear(tData[0])){
  253.                                                       tNum = '29';
  254.                                             }
  255.                                             if( parseInt(tData[2]) > parseInt(tNum) ){
  256.                                                       tData[2] = tNum;
  257.                                                       this.fnSetSelectedValue(tData);
  258.                                             }
  259.                                             else {
  260.                                                       this.data.oSelectedData = tData;
  261.                                             }
  262.                                             break;
  263.                                   case '4':
  264.                                   case '6':
  265.                                   case '9':
  266.                                   case '11':
  267.                                             if( tData[2] == '31') {
  268.                                                       tData[2] = '30';
  269.                                                       this.fnSetSelectedValue(tData);
  270.                                             }
  271.                                             else {
  272.                                                       this.data.oSelectedData = tData;
  273.                                             }
  274.                                             break;
  275.                                   default:
  276.                                             this.data.oSelectedData = tData;
  277.                         }
  278.                 },
  279.                 /**
  280.                  * 主动设置选择器的选择值
  281.                  * @param  {Array} pData 日期选择器选择后的回调数据
  282.                  * @return {void}
  283.                  */
  284.                 fnSetSelectedValue(pData) {
  285.                     if('[object Array]' !== Object.prototype.toString.call(pData)) {
  286.                         return;
  287.                     }
  288.                         var UICustomPicker = api.require('UICustomPicker');
  289.                     UICustomPicker.setValue({
  290.                         id: this.data.vPickerId,
  291.                         data: pData
  292.                     });
  293.                     this.data.oSelectedData = pData;
  294.                 },
  295.                 showDate() {
  296.                         let that = this;
  297.                         var UICustomPicker = api.require('UICustomPicker');
  298.                         UICustomPicker.show({
  299.                                 id: that.data.vPickerId
  300.                         });
  301.                 },
  302.                 hideDate() {
  303.                         let that = this;
  304.                         var UICustomPicker = api.require('UICustomPicker');
  305.                         UICustomPicker.hide({
  306.                                 id:  that.data.vPickerId
  307.                         });
  308.                 },
  309.                 setDate(){
  310.                         let that = this;
  311.                         var UICustomPicker = api.require('UICustomPicker');
  312.                         UICustomPicker.setValue({
  313.                                 id: that.data.vPickerId,
  314.                                 data: that.data.actives
  315.                         });
  316.                 },
  317.                 setValue(value) {
  318.                         if (this.$model) {
  319.                                 this.$model.value = value;
  320.                         }
  321.                 },
  322.                 clearDate() {
  323.                         this.data.selectDate = "";
  324.                         this.setValue("");
  325.                         this.fire('selectDate', {
  326.                                 date: ""
  327.                         });
  328.                 }
  329.         }
  330. }
  331. </script>
  332. <style scoped>
  333. .field__body {
  334.         flex: 1;
  335. }
  336. .field__control {
  337.         background-color: red;
  338.         display: block;
  339.         box-sizing: border-box;
  340.         color: #323233;
  341.         border: none;
  342.         font-size: 14px;
  343.         height: 24px;
  344.         line-height: 24px;
  345.         width: 100%;
  346.         flex-shrink: 0;
  347.         background: transparent;
  348. }

  349. .field--disabled {
  350.         cursor: not-allowed;
  351.         opacity: 0.3;
  352. }

  353. .field__control-center {
  354.         text-align: center;
  355. }

  356. .field__control-right {
  357.         text-align: right;
  358. }

  359. .field__control--error {
  360.         color: #ee0a24;
  361. }

  362. .field__error-msg {
  363.         color: #ee0a24;
  364.         font-size: 12px;
  365. }
  366. .field__value {
  367.         font-size: 14px;
  368.         color: #323233;
  369.         line-height: 24px;
  370. }
  371. .field__placeholder {
  372.         font-size: 14px;
  373.         color: #bbb;
  374.         line-height: 24px;
  375. }
  376. </style>
复制代码



QQ截图20221209154839.png
QQ截图20221209154829.png
现在你的问题解决没,如果还有问题,继续发个帖子,把旧帖子链接附上
123下一页
您需要登录后才可以回帖 登录

本版积分规则