page-singlepage-form 办理类服务(单流程)模板

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

解释:办理类服务(单流程)模板、通常用来完成简单表单的填写提交工作。本模板包含多个组件,可根据实际需要进行增删,支持代码的二次开发满足个性化诉求。

示例

扫码体验

代码示例

百度智能小程序

请使用百度APP扫码

页面内容

模板包含两个页面:表单页提交状态页(成功 / 失败)

表单页

页面包含常用的表单组件,如日期选择、三级联动选择、地理位置选择、手机号输入、长文本输入、图片上传等。

页面路径:index/index

page-singlepage-form 办理类服务(单流程)模板 - 图2

page-singlepage-form 办理类服务(单流程)模板 - 图3

代码示例
以下为部分代码示例注解

  • SWAN
  • JSON
  1. <!-- 页面加载, 错误页面 -->
  2. <smt-page-status s-if="isPageLoading || pageResult"
  3. class="content"
  4. loading="{{isPageLoading}}"
  5. icon="{{errorConfig[pageResult].icon}}"
  6. title="{{errorConfig[pageResult].title}}"
  7. desc="{{errorConfig[pageResult].desc}}"
  8. showBtn="{{errorConfig[pageResult].showBtn}}"
  9. bind:smtreloading="check">
  10. </smt-page-status>
  11. <!-- 办理类服务(单流程)模板 -->
  12. <view s-else class="{{isFullScreen ? 'iphonexs': 'normal'}}">
  13. <view class="thick-divid">
  14. <gov-page-title title="标题一" size="middle" hasBorder></gov-page-title>
  15. <!--
  16. gov-input 输入框
  17. 1. ipt-item-type: short/long 标题可是四字或六字
  18. 在一个表单内,建议使用一致的标题宽度设置
  19. 2.ipt-value= "{{formData.key}}" //
  20. ipt-name="key"
  21. ipt-error-info="{{errorInfp.key+Error}}"
  22. 三项必配置,且key要一致
  23. 3. 输入框中清除事件 iptKeyClean, input事件 iptKeyInput
  24. -->
  25. <gov-input
  26. type="idcard"
  27. ipt-item-type="idcard"
  28. ipt-title="身份证号"
  29. maxlength="18"
  30. ipt-value="{{formData.idcard}}"
  31. iptErrorInfo="{{errorInfo.idcardError}}"
  32. ipt-name="idcard"
  33. ipt-item-width="100%"
  34. placeholder-content="请输入"
  35. bindiptclean="iptKeyClean"
  36. bindkeyinput="iptKeyInput"
  37. bindiptblur="iptblursfz">
  38. </gov-input>
  39. <gov-input
  40. type="number"
  41. ipt-item-type="phone"
  42. ipt-title="手机号"
  43. maxlength="11"
  44. ipt-value="{{formData.phone}}"
  45. ipt-error-info="{{errorInfo.phoneError}}"
  46. ipt-name="phone"
  47. ipt-item-width="100%"
  48. placeholder-content="请输入"
  49. bindiptclean="iptKeyClean"
  50. bindkeyinput="iptKeyInput"
  51. bindiptblur="iptblursjh">
  52. </gov-input>
  53. <gov-picker
  54. label="日期"
  55. mode=date
  56. placeholder="请选择"
  57. labelWidth="4em"
  58. data-value="date"
  59. start="{{startDate}}"
  60. end="{{endDate}}"
  61. errStatus="{{errorInfo.dateError}}"
  62. value="{{formData.date}}"
  63. bindchange="handleChange1">
  64. </gov-picker>
  65. <gov-picker
  66. label="所在位置"
  67. mode="location"
  68. placeholder="请选择"
  69. labelWidth="4em"
  70. noborder="{{true}}"
  71. display-type="{{false}}"
  72. errStatus="{{errorInfo.placeError}}"
  73. locationName="{{formData.place}}"
  74. bindchoosesuccess="choosesuccess"
  75. bindchoosefail="choosefail">
  76. </gov-picker>
  77. </view>
  78. <view class="thick-divid">
  79. <gov-page-title title="标题二" size="middle" hasBorder></gov-page-title>
  80. <gov-input
  81. type="text"
  82. ipt-item-type="short"
  83. ipt-title="输入框"
  84. ipt-value="{{formData.iptone}}"
  85. ipt-error-info="{{errorInfo.iptoneError}}"
  86. ipt-name="iptone"
  87. ipt-item-width="100%"
  88. placeholder-content="请输入"
  89. bindiptclean="iptKeyClean"
  90. bindkeyinput="iptKeyInput">
  91. </gov-input>
  92. <gov-input
  93. type="text"
  94. ipt-item-type="short"
  95. ipt-title="输入框"
  96. ipt-value="{{formData.ipttwo}}"
  97. ipt-error-info="{{errorInfo.ipttwoError}}"
  98. ipt-notic-info="{{noticInfo.iptNoticInfo}}"
  99. ipt-name="ipttwo"
  100. ipt-item-width="100%"
  101. placeholder-content="请输入"
  102. bindiptclean="iptKeyClean"
  103. bindkeyinput="iptKeyInput">
  104. </gov-input>
  105. <gov-picker
  106. mode="selector"
  107. range="{{options.singPicker}}"
  108. label="选择框"
  109. labelWidth="4em"
  110. bindchange="handleChange3"
  111. value="{{formData.sltsingle}}"
  112. rangeKey="name"
  113. errStatus="{{errorInfo.sltsingleError}}"
  114. placeholder="请选择">
  115. </gov-picker>
  116. <gov-cascade
  117. range="{{options.cascader}}"
  118. label="选择框"
  119. value="{{formData.sltdouble}}"
  120. rangeKey="name"
  121. labelWidth="4em"
  122. noborder="{{true}}"
  123. bindchange="cacadaChange"
  124. tips="{{['请选择', '请选择', '请选择']}}"
  125. errStatus= "{{errorInfo.sltdoubleError}}"
  126. placeholder="{{['请选择', '请选择', '请选择']}}">
  127. </gov-cascade>
  128. </view>
  129. <view class="thick-divid">
  130. <gov-page-title title="单选标题" size="middle" hasBorder></gov-page-title>
  131. <view class="radios">
  132. <gov-radio-group
  133. options="{{options.radiosValue}}"
  134. inline="{{false}}"
  135. activeColor="#2772fb"
  136. option-key="name"
  137. bindchange="radioChange"
  138. groupStyle="{{border}}"
  139. value="{{formData.radios}}">
  140. </gov-radio-group>
  141. </view>
  142. </view>
  143. <view class="thick-divid">
  144. <gov-page-title title="多选标题" size="middle" hasBorder></gov-page-title>
  145. <view class="checkboxs">
  146. <gov-checkbox-group
  147. inline="{{false}}"
  148. option-key="name"
  149. activeColor="#2772fb"
  150. options="{{options.checkboxsValue}}"
  151. bindchange="checkboxChange"
  152. gov-checkbox-group="border"
  153. value="{{formData.checkbox}}">
  154. </gov-checkbox-group>
  155. <gov-checkbox
  156. bindchange="noHas"
  157. activeColor="#2772fb"
  158. value="{{formData.nochecked}}">
  159. 不含以上情况
  160. </gov-checkbox>
  161. </view>
  162. </view>
  163. <view class="thick-divid">
  164. <gov-textarea
  165. gov-textarea-wrap="textarea-wrap"
  166. gov-textarea-element="textarea-element"
  167. bindinput="iptTextarea"
  168. placeholder="请输入"
  169. head="长文本输入框标题"
  170. value="{{formData.textBox}}"
  171. maxlength="100">
  172. </gov-textarea>
  173. </view>
  174. <view>
  175. <view class="upload-title">
  176. <gov-page-title
  177. title="上传照片标题"
  178. size="middle"
  179. hasBorder>
  180. </gov-page-title>
  181. </view>
  182. <gov-upload
  183. count="5"
  184. gov-tips="tips"
  185. binddelete="clickDelete"
  186. binduploadsuccess="uploadsuccess"
  187. bindurlempty="urlempty"
  188. bindpreviewfail="previewfail"
  189. tips="最多支持5张图片,单张体积10M一下"
  190. imageList="{{formData.imageList}}"
  191. limitSize="10">
  192. </gov-upload>
  193. </view>
  194. <view class="wen">
  195. <gov-prompt>
  196. <view slot="title">温馨提示:</view>
  197. <view slot="content">此板块为提示区,可用户提醒用户业务填写中的注意事项及要求<view class="prompt-view" bindtap="toView">点击查看</view>
  198. </view>
  199. </gov-prompt>
  200. </view>
  201. <view class="btn">
  202. <gov-ga-button
  203. button-size="large"
  204. button-text="提交"
  205. button-color="default"
  206. bindtap="submit">
  207. </gov-ga-button>
  208. <view s-if="{{isFullScreen}}" class="{{isFullScreen ? 'iphonex-safe-height': 'normal-height'}}"></view>
  209. </view>
  210. </view>
  1. {
  2. "navigationBarTitleText": "办理类服务(单流程)模板",
  3. "backgroundColor": "#fff",
  4. "navigationBarBackgroundColor": "#fff",
  5. "navigationBarTextStyle": "black",
  6. "usingComponents": {
  7. "gov-picker": "@smt-ui/component-gov/src/picker",
  8. "gov-upload": "@smt-ui/component-gov/src/upload",
  9. "gov-prompt": "@smt-ui/component-gov/src/prompt",
  10. "gov-input": "@smt-ui/component-gov/src/input",
  11. "gov-ga-button": "@smt-ui/component-gov/src/button",
  12. "gov-cascade": "@smt-ui/component-gov/src/cascade",
  13. "gov-textarea": "@smt-ui/component-gov/src/textarea",
  14. "smt-page-status":"@smt-ui/component/src/page-status",
  15. "gov-page-title": "@smt-ui/component-gov/src/page-title",
  16. "gov-checkbox": "@smt-ui/component-gov/src/checkbox",
  17. "gov-radio-group": "@smt-ui/component-gov/src/radio-group",
  18. "gov-checkbox-group": "@smt-ui/component-gov/src/checkbox-group"
  19. }
  20. }
  • 获取页面数据

  • JS

  1. /**
  2. * 发送请求
  3. *
  4. * @param {Object} data 请求接口参数
  5. */
  6. getDetail(data) {
  7. //【需替换】:获取内容详情所需要的数据,请修改 url 字段为真实的请求地址,该接口仅做示例
  8. let params = {
  9. url: 'https://www.ceshi.com',
  10. method: 'GET',
  11. data,
  12. success: res => {
  13. // 接口正常返回处理逻辑
  14. if (+res.code === 0) {
  15. if (Object.keys(res.data).length) {
  16. this.setData({
  17. // merge 本地数据和异步数据赋值给 options
  18. options: {...this.data.options, ...res.data}
  19. }, () => {
  20. this.setData({
  21. isPageLoading: false,
  22. pageResult: ''
  23. });
  24. });
  25. }
  26. else {
  27. // 没有数据
  28. this.setData({
  29. isPageLoading: false,
  30. pageResult: 'noData'
  31. });
  32. }
  33. }
  34. else {
  35. // 接口异常处理逻辑
  36. this.setData({
  37. isPageLoading: false,
  38. pageResult: 'warning'
  39. });
  40. }
  41. },
  42. fail: err => {
  43. // 接口异常处理逻辑
  44. this.setData({
  45. isPageLoading: false,
  46. pageResult: 'warning'
  47. });
  48. }
  49. };
  50. swan.request(params);
  51. }
  • 点击提交按钮触发事件

  • JS

  1. /**
  2. * 点击提交按钮触发事件
  3. */
  4. submit() {
  5. // 输入框,选择框根据错误状态 判断toast文案
  6. // 多选,单选,长文本,上传照片根据value值 判断toast文案
  7. const formData = this.data.formData;
  8. // 错误信息整理 设置error状态
  9. let errorInfo = {
  10. // checkIdcard、checkPhone、checkEmpty校验方法的详细说明可看 utils.js
  11. idcardError: checkIdcard(formData.idcard),
  12. phoneError: checkPhone(formData.phone),
  13. dateError: !formData.date,
  14. placeError: !formData.place,
  15. iptoneError: checkEmpty(formData.iptone, '请输入输入框一'),
  16. ipttwoError: checkEmpty(formData.ipttwo, '请输入输入框二'),
  17. sltsingleError: formData.sltsingle < 0,
  18. sltdoubleError: formData.sltdouble.length !== 3
  19. };
  20. this.setData({errorInfo}, () => {
  21. if (this.showCurToast()) {
  22. let that = this;
  23. let params = JSON.stringify(that.parameter());
  24. swan.showModal({
  25. title: '信息确认信息',
  26. content: '请确认填写的信息无误,提交后不支持修改',
  27. confirmText: '确认提交',
  28. confirmColor: '#108EE9',
  29. cancelText: '返回修改',
  30. cancelColor: '#999',
  31. success(res) {
  32. // 此处可自定义业务逻辑
  33. if (res.confirm) {
  34. swan.redirectTo({
  35. url: `../result/result?result=${params}`
  36. });
  37. }
  38. }
  39. });
  40. }
  41. });
  42. }

提交状态页

用于展示表单提交结果。

页面路径:result/result

page-singlepage-form 办理类服务(单流程)模板 - 图4

page-singlepage-form 办理类服务(单流程)模板 - 图5

代码示例

  • SWAN
  • JSON
  1. <smt-page-status s-if="isPageLoading || errorPage"
  2. class="content"
  3. loading="{{isPageLoading}}"
  4. icon="{{errorConfig[errorPage].icon}}"
  5. title="{{errorConfig[errorPage].title}}"
  6. desc="{{errorConfig[errorPage].desc}}"
  7. showBtn="{{errorConfig[errorPage].showBtn}}"
  8. bind:smtreloading="check">
  9. </smt-page-status>
  10. <view s-else class='wrap'>
  11. <gov-page-result
  12. iconName="{{icon.iconName}}"
  13. iconColor="{{icon.iconColor}}"
  14. gov-main-btn="gov-main-btn"
  15. gov-ext-info-text="gov-ext-info-text"
  16. title="{{pageResult.title}}"
  17. desc="{{pageResult.desc}}"
  18. main-btn-text="回到首页"
  19. sub-btn-text="辅助按钮"
  20. bind:goback="goBack"
  21. bind:viewdetails="viewDetails">
  22. <view slot="suppl-cont" class="list" s-if="{{pageResult.list}}">
  23. <view s-for="pageResult.list trackBy item" class='every'>
  24. <text>{{item.title}}</text>
  25. <text>{{item.sub}}</text>
  26. </view>
  27. </view>
  28. </gov-page-result>
  29. </view>
  1. {
  2. "navigationBarTitleText": "结果页",
  3. "backgroundColor": "#fff",
  4. "navigationBarBackgroundColor": "#fff",
  5. "navigationBarTextStyle": "black",
  6. "usingComponents": {
  7. "ga-button": "@smt-ui/component-gov/src/button",
  8. "smt-page-status": "@smt-ui/component/src/page-status",
  9. "gov-page-result": "@smt-ui/component-gov/src/page-result"
  10. }
  11. }
  • 页面初始化

  • JS

  1. /**
  2. * 页面加载时触发
  3. *
  4. * @param {Object} options 提交页面传的参数
  5. * @param {string} options.result 传的数据
  6. */
  7. onLoad(options) {
  8. this.setData({
  9. // 页面需要展示的数据,依赖server端返回
  10. pageResult: '',
  11. options: JSON.parse(options.result)
  12. });
  13. let icon;
  14. if (pageResult.data.type !== 'success') {
  15. icon = {
  16. iconName: 'warning-o',
  17. iconColor: '#c40311'
  18. };
  19. this.setData({icon});
  20. }
  21. }
  • 点击“返回首页”按钮触发事件

  • JS

  1. /**
  2. * 返回首页
  3. */
  4. goBack() {
  5. //【需替换】:请为 url 设置真实的首页路径
  6. swan.redirectTo({
  7. url: ''
  8. });
  9. }
  • 点击“辅助按钮”按钮触发事件

  • JS

  1. /**
  2. * 辅助按钮
  3. */
  4. viewDetails() {
  5. //【需替换】:请为 url 设置真实的跳转页面路径
  6. swan.redirectTo({
  7. url: ''
  8. });
  9. }

npm 依赖

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

Bug & Tip

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