13518219792

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

创新互联百度小程序教程:page-query-form查询类服务模板

page-query-form 查询类服务模板

从开发者工具 v2.25.1-rc 版本开始支持。

解释:本模板适用于成绩查询、证书查询等查询类服务项开发工作,模板内包含的组件丰富,覆盖大多数查询类服务项场景,开发者仅需通过调整组件属性以及排序即可快速完成前端开发工作。

示例

扫码体验

代码示例

请使用百度APP扫码

页面内容

模板包含两个页面:查询参数填写页、查询结果页。

查询参数填写页

包括信息输入操作常用组件,例如输入框、日期选择器、位置选择器等,同时结合政务查询类服务特性,模板内包含了弹窗组件,当用户进入服务页面时,可通过弹窗对用户进行强提醒,加强信息的触达效果,保障用户办理查询类服务时的使用体验。

页面路径:pages/index/index

代码示例

 
 
 
  1. s-if="{{showNoticeBar}}"
  2. text="{{noticeContent}}">
  3. data-id="iptOne"
  4. ipt-item-type="short"
  5. type="text"
  6. ipt-title="输入框"
  7. placeholder-content="请输入内容"
  8. ipt-value="{{model.iptOne.iptValue}}"
  9. bindkeyinput="bindInput"
  10. bindiptblur="bindBlur"
  11. bindiptclean="cleanRoad"
  12. ipt-error-info="{{model.iptOne.iptErrorInfo}}">
  13. placeholder="请选择选项"
  14. label-width="4em"
  15. range-key="type"
  16. errColor="#C40311"
  17. value="{{model.pickerOne.iptValue}}"
  18. bindchange="pickerOne"
  19. label="选择框"
  20. range="{{optionsOne}}">
  21. data-id="password"
  22. ipt-item-type="short"
  23. type="text"
  24. ipt-title="密码框"
  25. placeholder-content="请输入密码"
  26. ipt-value="{{model.password.iptValue}}"
  27. password="true"
  28. bindkeyinput="bindInput"
  29. bindiptblur="bindBlur"
  30. bindiptclean="cleanRoad"
  31. ipt-error-info="{{model.password.iptErrorInfo}}">
  32. data-id="idCard"
  33. ipt-item-type="short"
  34. type="idcard"
  35. ipt-title="身份证号"
  36. placeholder-content="请输入身份证号"
  37. ipt-value="{{model.idCard.iptValue}}"
  38. maxlength="18"
  39. bindkeyinput="bindInput"
  40. bindiptblur="bindBlur"
  41. bindiptclean="cleanRoad"
  42. ipt-error-info="{{model.idCard.iptErrorInfo}}">
  43. data-id="phone"
  44. ipt-item-type="short"
  45. type="number"
  46. maxlength="11"
  47. ipt-title="手机号"
  48. placeholder-content="请输入手机号"
  49. ipt-value="{{model.phone.iptValue}}"
  50. bindkeyinput="bindInput"
  51. bindiptblur="bindBlur"
  52. bindiptclean="cleanRoad"
  53. ipt-error-info="{{model.phone.iptErrorInfo}}">
  54. data-id="smsInput"
  55. type="number"
  56. label-width="4em"
  57. max-length="{{6}}"
  58. bindkeyinput="bindInput"
  59. bindiptblur="bindBlur"
  60. bindsmssend="smssend"
  61. placeholder-content="请输入短信验证码"
  62. ipt-value="{{model.smsInput.iptValue}}"
  63. ipt-error-color="#C40311"
  64. ipt-error-flag="{{model.smsInput.iptErrorInfo.errFlag}}">
  65. data-id="govCaptcha"
  66. type="number"
  67. ipt-area-width="4em"
  68. max-length="{{4}}"
  69. verify-img-url="{{model.govCaptcha.codeImg}}"
  70. bindkeyinput="bindInput"
  71. bindiptblur="bindBlur"
  72. bindrefreshimg="reloadImg"
  73. ipt-value="{{model.govCaptcha.iptValue}}"
  74. ipt-error-info="{{model.govCaptcha.iptErrorInfo.errFlag}}">
  75. data-id="pickerDate"
  76. placeholder="请选择日期"
  77. label-width="4em"
  78. mode="date"
  79. start="2020-01-01"
  80. end="2025-12-31"
  81. value="{{model.pickerDate.iptValue}}"
  82. bindchange="pickerDate"
  83. label="日期">
  84. placeholder="请选择所在地区"
  85. mode="region"
  86. label-width="4em"
  87. value="{{model.pickerRegion.iptValue}}"
  88. bindchange="pickerRegion"
  89. label="所在地区">
  90. button-size="large"
  91. button-text="查询"
  92. button-disabled="{{buttonDisabled}}"
  93. data-isValidata="true"
  94. button-color="#2772FB"
  95. bindtap="buttonImportant">
  96. button-size="large"
  97. button-text="辅助按钮"
  98. button-color="plain"
  99. bindtap="buttonTap">
  100. 温馨提示:
  101. 此板块为提示区,可用于提醒用户业务填写中的注意事项及要求
  102. 点击查看
 
 
 
  1. {
  2. "navigationBarTitleText": "标题文字",
  3. "navigationBarBackgroundColor": "#ffffff",
  4. "navigationBarTextStyle": "dark",
  5. "usingComponents": {
  6. "gov-picker": "@smt-ui/component-gov/src/picker",
  7. "gov-notice-bar": "@smt-ui/component-gov/src/notice-bar",
  8. "gov-sms-input": "@smt-ui/component-gov/src/sms-input",
  9. "gov-prompt": "@smt-ui/component-gov/src/prompt",
  10. "gov-captcha": "@smt-ui/component-gov/src/captcha",
  11. "gov-button": "@smt-ui/component-gov/src/button",
  12. "gov-input": "@smt-ui/component-gov/src/input"
  13. }
  14. }
  • 页面初始化。可进行办理前提示和初始化数据等操作

  • JS

 
 
 
  1. onLoad() {
  2. // 初始化图形验证码
  3. this.reloadImg();
  4. // 办理前提示
  5. swan.showModal({
  6. title: '提示',
  7. content: '此弹窗可在业务办理前对用户进行预先提醒',
  8. showCancel: false,
  9. confirmText: '我知道了'
  10. });
  11. }
  • 输入框事件。包含普通输入框、密码输入框、身份证输入框、手机号输入框、短信验证码输入框、图形验证码输入框。

  • JS

 
 
 
  1. /**
  2. * 输入框的 input 事件
  3. *
  4. * @param {Event} e 事件对象
  5. */
  6. bindInput(e) {
  7. // 将 input 输入的值赋给 model 中对应属性的 iptValue 字段, 用于后续校验和提交表单使用
  8. this.setData({
  9. ['model.' + e.currentTarget.dataset.id + '.iptValue']: e.detail.iptvalue
  10. });
  11. // 每次输入完成时判断查询按钮是否高亮显示
  12. this.buttonImportant({});
  13. }
  14. /**
  15. * 输入框的 blur 事件,失焦时通过 validata 方法对当前输入框的值进行校验
  16. *
  17. * @param {Event} e 事件对象
  18. */
  19. bindBlur(e) {
  20. let iptvalue = e.detail.iptvalue;
  21. let iptid = e.currentTarget.dataset.id;
  22. let rulse = this.data.model[iptid].rulse;
  23. this.validata(rulse, iptvalue, iptid);
  24. }
  25. /**
  26. * 点击输入框右侧清除按钮事件,短信验证码输入框、图形验证码输入框没有该事件
  27. *
  28. * @param {Event} e 事件对象
  29. */
  30. cleanRoad(e) {
  31. // 清空当前表单内数据
  32. this.setData({['model.' + e.currentTarget.dataset.id + '.iptValue']: ''});
  33. }
  • 选择器的 change 事件处理。包含普通选择器、日期选择器、地区选择器

  • JS

 
 
 
  1. /**
  2. * 普通选择器的 change 事件
  3. *
  4. * @param {Object} detail 事件对象信息
  5. */
  6. pickerOne({detail}) {
  7. // 将 picker 选中值赋给 model 中对应的属性
  8. this.setData('model.pickerOne.iptValue', detail.detail.value);
  9. // 选择完成时判断查询按钮是否高亮显示
  10. this.buttonImportant({});
  11. }
  12. /**
  13. * 时间选择器的 change 事件
  14. *
  15. * @param {Object} detail 事件对象信息
  16. */
  17. pickerDate({detail}) {
  18. // 将 picker 选中值赋给 model 中对应的属性
  19. this.setData('model.pickerDate.iptValue', detail.detail.value);
  20. // 选择完成时判断查询按钮是否高亮显示
  21. this.buttonImportant({});
  22. }
  23. /**
  24. * 地区选择器的 change 事件
  25. *
  26. * @param {Object} detail 事件对象信息
  27. */
  28. pickerRegion({detail}) {
  29. // 将 picker 选中值赋给 model 中对应的属性
  30. this.setData('model.pickerRegion.iptValue', detail.detail.value);
  31. // 选择完成时判断查询按钮是否高亮显示
  32. this.buttonImportant({});
  33. }
  • 点击图形验证码事件

  • JS

 
 
 
  1. /**
  2. * 图形验证码的点击事件,可以增加刷新图片验证码或者其他需要的操作
  3. */
  4. reloadImg() {
  5. swan.request({
  6. // 仅为示例,并非真实的接口地址
  7. url: 'http://www.baidu.com',
  8. success: res => {
  9. this.setData({
  10. // codeImg 字段根据业务自行调整
  11. 'model.govCaptcha.codeImg': res.data.codeImg
  12. })
  13. },
  14. fail: err => {
  15. // 接口异常的处理代码
  16. }
  17. })
  18. }
  • 获取手机验证码事件

  • JS

 
 
 
  1. /**
  2. * 手机号验证码组件点击获取验证码的事件
  3. */
  4. smssend() {
  5. // 该方法模拟收到短信验证码的toast效果,实际场景请使用开发者自己的短信验证码服务
  6. swan.showToast({
  7. title: '验证码:123456',
  8. icon: 'none'
  9. });
  10. }
  • 页面下方“温馨提示”的“点击查看”的事件

  • JS

 
 
 
  1. /**
  2. * 页面下方“温馨提示”的 “点击查看” 事件处理
  3. */
  4. toView() {
  5. // 此处仅为示例,您可以自定义该事件的逻辑,比如跳转到某个页面等
  6. swan.navigateTo({url: '/pages/index/index'});
  7. }
  • 查询按钮点击事件

  • JS

 
 
 
  1. /**
  2. * 查询按钮点击事件
  3. *
  4. * @param {Event} e 事件对象
  5. */
  6. buttonImportant(e) {
  7. // 判断表单是否全部填写了
  8. for (let i in this.data.model) {
  9. if (!String(this.data.model[i].iptValue).trim()) {
  10. return;
  11. }
  12. }
  13. // 如果表单的必填项都已填写则查询按钮高亮
  14. this.setData({buttonDisabled: false});
  15. // 只有手动点击查询按钮的时候才会执行校验,通过按钮组件的 data-isValidata 属性控制是否需要走校验逻辑
  16. if (e.currentTarget && e.currentTarget.dataset.isValidata) {
  17. for (let i in this.data.model) {
  18. let itemData = this.data.model[i];
  19. if (itemData.iptErrorInfo) {
  20. if (this.validata(itemData.rulse, itemData.iptValue, i, true)) {
  21. return;
  22. }
  23. }
  24. }
  25. // 此处表单已校验通过,您可以自定义一些自己的逻辑,比如跳转到查询结果页模板
  26. swan.navigateTo({
  27. url: '/@smt-ui-template-gov-query-form/pages/result/result'
  28. });
  29. }
  30. }

查询结果页

页面用于承载查询结果,将查询结果信息结构化呈现,便于用户阅读理解。
页面路径:pages/result/result

代码示例

  • SWAN
  • JSON
  • JS
 
 
 
  1. s-if="{{statePageType}}"
  2. class="page-status"
  3. icon="{{statePageConfig[statePageType].icon}}"
  4. title="{{statePageConfig[statePageType].title}}"
  5. desc="{{statePageConfig[statePageType].desc}}"
  6. showBtn="{{statePageConfig[statePageType].showBtn}}"
  7. smtreloading="{{reLoad}}"
  8. loading="{{statePageType === 'loading'}}"
  9. >
  10. label-width="6em"
  11. label="{{item.name}}"
  12. gov-label="list-label"
  13. border
  14. >
  15. s-for="ele in item.value"
  16. bindtap="callPhone"
  17. data-phoneNum="{{ele}}"
  18. >{{ele}}
  19. s-else
  20. text="{{item.value}}"
  21. line="{{item.line}}"
  22. gov-text-collapse-content="list-text"
  23. >
  24. 温馨提示:
  25. 这里是温馨提示这里是温馨提示这里是温馨提示这里是温馨提示这里是温馨提示这里是温馨提示
  26. 点击查看
 
 
 
  1. {
  2. "navigationBarTitleText": "查询结果",
  3. "navigationBarBackgroundColor": "#ffffff",
  4. "navigationBarTextStyle": "dark",
  5. "usingComponents": {
  6. "gov-page-title":"@smt-ui/component-gov/src/page-title",
  7. "gov-list-item": "@smt-ui/component-gov/src/list-item",
  8. "gov-text-collapse": "@smt-ui/component-gov/src/text-collapse",
  9. "smt-page-status": "@smt-ui/component/src/page-status",
  10. "gov-prompt": "@smt-ui/component-gov/src/prompt"
  11. }
  12. }
 
 
 
  1. Page({
  2. data: {
  3. // warning 服务开小差、noContent 未查询到信息、noNetwork 无网络、不显示错误页则为空字符串
  4. statePageType: 'loading'
  5. },
  6. onLoad() {
  7. // 使用定时器模拟请求,模拟 loading 显示两秒钟
  8. setTimeout(() => {
  9. this.data.statePageType = '';
  10. }, 2000)
  11. },
  12. /**
  13. * 点击电话调起拨号
  14. *
  15. * @param {Event} e 事件对象
  16. */
  17. callPhone(e) {
  18. swan.makePhoneCall({
  19. phoneNumber: e.currentTarget.dataset.phoneNum
  20. });
  21. },
  22. /**
  23. * 页面下方“温馨提示”的 “点击查看” 事件处理
  24. */
  25. toView() {
  26. swan.showToast({
  27. title: '点击查看',
  28. icon: 'none'
  29. });
  30. }
  31. });

npm 依赖

名称 版本号
@smt-ui/component-govlatest
@smt-ui/componentlatest

Bug & Tip

  • Tip:该模板使用了 ES6 语法,需要开启开发者工具的增强编译,操作步骤参看开启说明;同时也需开启上传代码时样式自动补全。
  • Tip:以上代码示例为纯客户端代码,可直接在模拟器和真机预览。
  • Tip:模板中使用的是测试数据,你需要从接口中获取真实的数据。

本文题目:创新互联百度小程序教程:page-query-form查询类服务模板
URL标题:http://cdbrznjsb.com/article/dhoddsc.html
  • 网站建设专属方案

  • 网站定制化设计

  • 7X24小时服务

  • N对管家服务

让你的专属顾问为你服务