standard.html 22.7 KB
<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>开发规范 | 买买买文档平台</title>
    <meta name="description" content="买买买文档平台">
    
    
    <link rel="preload" href="/assets/css/0.styles.f8cb2318.css" as="style"><link rel="preload" href="/assets/js/app.0904f644.js" as="script"><link rel="preload" href="/assets/js/2.427d44e8.js" as="script"><link rel="preload" href="/assets/js/19.6c3f7bfe.js" as="script"><link rel="prefetch" href="/assets/js/10.8c73025f.js"><link rel="prefetch" href="/assets/js/11.1b42eaf3.js"><link rel="prefetch" href="/assets/js/12.8bf95c83.js"><link rel="prefetch" href="/assets/js/13.51859cb3.js"><link rel="prefetch" href="/assets/js/14.73c2e592.js"><link rel="prefetch" href="/assets/js/15.a67061f1.js"><link rel="prefetch" href="/assets/js/16.44670fb1.js"><link rel="prefetch" href="/assets/js/17.8d2d00c7.js"><link rel="prefetch" href="/assets/js/18.c659d37f.js"><link rel="prefetch" href="/assets/js/20.93aca071.js"><link rel="prefetch" href="/assets/js/21.ac99609a.js"><link rel="prefetch" href="/assets/js/22.083721e6.js"><link rel="prefetch" href="/assets/js/23.343fd500.js"><link rel="prefetch" href="/assets/js/24.45b0061a.js"><link rel="prefetch" href="/assets/js/3.65af1edd.js"><link rel="prefetch" href="/assets/js/4.088a2843.js"><link rel="prefetch" href="/assets/js/5.9cabb112.js"><link rel="prefetch" href="/assets/js/6.f8071ef7.js"><link rel="prefetch" href="/assets/js/7.37077388.js"><link rel="prefetch" href="/assets/js/8.5583bb10.js"><link rel="prefetch" href="/assets/js/9.62c26b7f.js">
    <link rel="stylesheet" href="/assets/css/0.styles.f8cb2318.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/logo.png" alt="买买买文档平台" class="logo"> <span class="site-name can-hide">买买买文档平台</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">查询导览</a></div><div class="nav-item"><a href="/product/" class="nav-link">项目清单</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="团队文档" class="dropdown-title"><span class="title">团队文档</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/team/frontend/" class="nav-link router-link-active">前端</a></li><li class="dropdown-item"><!----> <a href="/team/ios/" class="nav-link">IOS端</a></li><li class="dropdown-item"><!----> <a href="/team/android/" class="nav-link">安卓端</a></li><li class="dropdown-item"><!----> <a href="/team/backend/" class="nav-link">服务端</a></li><li class="dropdown-item"><!----> <a href="/team/quality/" class="nav-link">测试端</a></li><li class="dropdown-item"><!----> <a href="/team/design/" class="nav-link">产品设计</a></li></ul></div></div><div class="nav-item"><a href="/project/" class="nav-link">项目管控</a></div><div class="nav-item"><a href="/adm/" class="nav-link">行政管理</a></div><div class="nav-item"><a href="/util/" class="nav-link">协作工具</a></div><div class="nav-item"><a href="/guide/" class="nav-link">文档写作平台入门介绍</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">查询导览</a></div><div class="nav-item"><a href="/product/" class="nav-link">项目清单</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="团队文档" class="dropdown-title"><span class="title">团队文档</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/team/frontend/" class="nav-link router-link-active">前端</a></li><li class="dropdown-item"><!----> <a href="/team/ios/" class="nav-link">IOS端</a></li><li class="dropdown-item"><!----> <a href="/team/android/" class="nav-link">安卓端</a></li><li class="dropdown-item"><!----> <a href="/team/backend/" class="nav-link">服务端</a></li><li class="dropdown-item"><!----> <a href="/team/quality/" class="nav-link">测试端</a></li><li class="dropdown-item"><!----> <a href="/team/design/" class="nav-link">产品设计</a></li></ul></div></div><div class="nav-item"><a href="/project/" class="nav-link">项目管控</a></div><div class="nav-item"><a href="/adm/" class="nav-link">行政管理</a></div><div class="nav-item"><a href="/util/" class="nav-link">协作工具</a></div><div class="nav-item"><a href="/guide/" class="nav-link">文档写作平台入门介绍</a></div> <!----></nav>  <ul class="sidebar-links"><li><a href="/team/frontend/" class="sidebar-link">前端 Frontend</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/#能力输出" class="sidebar-link">能力输出</a></li><li class="sidebar-sub-header"><a href="/team/frontend/#项目构建说明" class="sidebar-link">项目构建说明</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/#构建网站" class="sidebar-link">构建网站</a></li><li class="sidebar-sub-header"><a href="/team/frontend/#构建微信小程序" class="sidebar-link">构建微信小程序</a></li></ul></li><li class="sidebar-sub-header"><a href="/team/frontend/#项目环境要求" class="sidebar-link">项目环境要求</a></li><li class="sidebar-sub-header"><a href="/team/frontend/#项目技术组成" class="sidebar-link">项目技术组成</a></li><li class="sidebar-sub-header"><a href="/team/frontend/#代码版本控制位置" class="sidebar-link">代码版本控制位置</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/#网站、管理平台" class="sidebar-link">网站、管理平台</a></li><li class="sidebar-sub-header"><a href="/team/frontend/#小程序" class="sidebar-link">小程序</a></li></ul></li></ul></li><li><a href="/team/frontend/standard.html" class="active sidebar-link">开发规范</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/standard.html#文件与目录命名规范" class="sidebar-link">文件与目录命名规范</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/standard.html#目录命名" class="sidebar-link">目录命名</a></li><li class="sidebar-sub-header"><a href="/team/frontend/standard.html#文件命名" class="sidebar-link">文件命名</a></li></ul></li><li class="sidebar-sub-header"><a href="/team/frontend/standard.html#预处理样式" class="sidebar-link">预处理样式</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/standard.html#样式抽象" class="sidebar-link">样式抽象</a></li></ul></li></ul></li><li><a href="/team/frontend/plugins.html" class="sidebar-link">功能插件</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/plugins.html#拼图验证码插件" class="sidebar-link">拼图验证码插件</a></li><li class="sidebar-sub-header"><a href="/team/frontend/plugins.html#短信验证" class="sidebar-link">短信验证</a></li><li class="sidebar-sub-header"><a href="/team/frontend/plugins.html#侧边栏抽屉" class="sidebar-link">侧边栏抽屉</a></li><li class="sidebar-sub-header"><a href="/team/frontend/plugins.html#数据表格" class="sidebar-link">数据表格</a></li><li class="sidebar-sub-header"><a href="/team/frontend/plugins.html#数据下载-导出" class="sidebar-link">数据下载/导出</a></li><li class="sidebar-sub-header"><a href="/team/frontend/plugins.html#选择器" class="sidebar-link">选择器</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/plugins.html#单列数据穿梭框" class="sidebar-link">单列数据穿梭框</a></li><li class="sidebar-sub-header"><a href="/team/frontend/plugins.html#树形数据选择器" class="sidebar-link">树形数据选择器</a></li><li class="sidebar-sub-header"><a href="/team/frontend/plugins.html#分组树形数据选择器" class="sidebar-link">分组树形数据选择器</a></li></ul></li></ul></li><li><a href="/team/frontend/components.html" class="sidebar-link">业务组件</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/components.html#数据导入导出" class="sidebar-link">数据导入导出</a></li><li class="sidebar-sub-header"><a href="/team/frontend/components.html#操作权限应用" class="sidebar-link">操作权限应用</a></li><li class="sidebar-sub-header"><a href="/team/frontend/components.html#选择器" class="sidebar-link">选择器</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/components.html#存货选择器" class="sidebar-link">存货选择器</a></li></ul></li></ul></li><li><a href="/team/frontend/http.html" class="sidebar-link">数据交互格式标准</a></li><li><a href="/team/frontend/framework.html" class="sidebar-link">系统框架</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/framework.html#目录结构描述" class="sidebar-link">目录结构描述</a></li><li class="sidebar-sub-header"><a href="/team/frontend/framework.html#api" class="sidebar-link">API</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/framework.html#http-url-data-options" class="sidebar-link">$http(url, [data], [options])</a></li></ul></li><li class="sidebar-sub-header"><a href="/team/frontend/framework.html#自定义指令集-directive" class="sidebar-link">自定义指令集 directive</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/framework.html#v-date" class="sidebar-link">v-date</a></li><li class="sidebar-sub-header"><a href="/team/frontend/framework.html#v-number" class="sidebar-link">v-number</a></li></ul></li><li class="sidebar-sub-header"><a href="/team/frontend/framework.html#表单校验规则" class="sidebar-link">表单校验规则</a></li></ul></li><li><a href="/team/frontend/web-open-platform.html" class="sidebar-link">网页能力开放平台</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/web-open-platform.html#平台介绍及使用规范" class="sidebar-link">平台介绍及使用规范</a></li><li class="sidebar-sub-header"><a href="/team/frontend/web-open-platform.html#现有项目-模块" class="sidebar-link">现有项目/模块</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/web-open-platform.html#app-内嵌网页" class="sidebar-link">App 内嵌网页</a></li><li class="sidebar-sub-header"><a href="/team/frontend/web-open-platform.html#独立功能页" class="sidebar-link">独立功能页</a></li></ul></li></ul></li><li><a href="/team/frontend/quality.html" class="sidebar-link">质量保证体系</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/quality.html#团队应用现状" class="sidebar-link">团队应用现状</a></li><li class="sidebar-sub-header"><a href="/team/frontend/quality.html#语法检查" class="sidebar-link">语法检查</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/quality.html#使用工具" class="sidebar-link">使用工具</a></li><li class="sidebar-sub-header"><a href="/team/frontend/quality.html#运行方式" class="sidebar-link">运行方式</a></li><li class="sidebar-sub-header"><a href="/team/frontend/quality.html#检查结果要求" class="sidebar-link">检查结果要求</a></li></ul></li><li class="sidebar-sub-header"><a href="/team/frontend/quality.html#单元测试" class="sidebar-link">单元测试</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/quality.html#为什么要写单元测试?" class="sidebar-link">为什么要写单元测试?</a></li><li class="sidebar-sub-header"><a href="/team/frontend/quality.html#使用功能库" class="sidebar-link">使用功能库</a></li><li class="sidebar-sub-header"><a href="/team/frontend/quality.html#运行方式-2" class="sidebar-link">运行方式</a></li><li class="sidebar-sub-header"><a href="/team/frontend/quality.html#适用范围" class="sidebar-link">适用范围</a></li></ul></li><li class="sidebar-sub-header"><a href="/team/frontend/quality.html#端对端测试(end-to-end)" class="sidebar-link">端对端测试(End-to-end)</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/team/frontend/quality.html#使用功能库-2" class="sidebar-link">使用功能库</a></li><li class="sidebar-sub-header"><a href="/team/frontend/quality.html#运行方式-3" class="sidebar-link">运行方式</a></li></ul></li></ul></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="开发规范"><a href="#开发规范" aria-hidden="true" class="header-anchor">#</a> 开发规范</h1> <p>编码规范好比协议,有了 <code>Http</code><code>TCP</code> 等各种协议,计算机之间才能有效地通信,同样的,有了一致的编码规范,开发人员之间才能有效地合作</p> <p>为提高软件开发质量,降低开发周期,增强代码的可重用性和易读性,使软件便于维护及移交,开发人员间便于交流和协作,本规范适用于前端团队,以作参考。</p> <div class="custom-block danger"><p class="custom-block-title">注意</p> <p>开发规范执行情况将会不定期进行 <strong>Code Review</strong>,不符合规范的内容必须进行整改。</p></div> <h2 id="文件与目录命名规范"><a href="#文件与目录命名规范" aria-hidden="true" class="header-anchor">#</a> 文件与目录命名规范</h2> <p>前端开发规范应用于 Web 网站、管理平台、移动端内嵌、微信小程序等范围,即使是本文档项目(<code>doc-press</code>)中的文件命名,依然建议应用本规范</p> <p>命名规范优秀的行业范例可参考 <a href="https://github.com/vuejs/vue" target="_blank" rel="noopener noreferrer">Vuejs<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a><a href="https://github.com/facebook/react" target="_blank" rel="noopener noreferrer">Reactjs<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a> 的源码</p> <h3 id="目录命名"><a href="#目录命名" aria-hidden="true" class="header-anchor">#</a> 目录命名</h3> <p>业务功能结构</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>├─用户管理
  └─授权管理
      ├─角色管理
      └─用户角色绑定
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>目录命名示例</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>
├─userManage
   └─userAuthManage
      ├─RoleManage
      └─userRoleBind


├─user
   └─auth
      ├─role
      └─user<span class="token operator">-</span>role
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>目录的命名,应尽可能使用上下、父子结构进行上下文信息描述,目录名自身应尽可能简洁直观。文本上使用全小写字母,有词组的情况使用 “-” 符号隔开</p> <h4 id="为什么要使用小写?"><a href="#为什么要使用小写?" aria-hidden="true" class="header-anchor">#</a> 为什么要使用小写?</h4> <ul><li><p>易用性/可读性<br>
小写文件名通常比大写文件名更易读,比如 <code>accessibility.txt</code> 就比 <code>ACCESSIBILITY.TXT</code> 易读。即使使用驼峰命名法,如 <code>UserRoleBind</code><code>userRoleBind</code> 不如 <code>user-role-bind</code> 的可读性高</p></li> <li><p>兼容性<br>
不同操作系统对于大小兼容程度不一样,为了保证编译、部署后的内容在所有平台上顺利部署,目录名也应当使用小写</p></li> <li><p>行业惯例<br>
诸如 <code>Java</code><code>.net</code><code>C</code> 等著名语言的包路径均为小写,行业巨头的良好规范也逐渐成为行业里约定俗成的规范</p></li></ul> <h3 id="文件命名"><a href="#文件命名" aria-hidden="true" class="header-anchor">#</a> 文件命名</h3> <p>文件名的规则在遵循目录命名的规则作为基础规则,但文件名的命名规则相比目录,略有不同</p> <h4 id="插件-组件-页面"><a href="#插件-组件-页面" aria-hidden="true" class="header-anchor">#</a> 插件/组件/页面</h4> <p>单文件组件、插件/组件主体、页面的文件名应该始终是单词大写开头 (PascalCase)</p> <p>单词大写开头对于代码编辑器的自动补全最为友好,因为这使得我们在 JS(X) 和模板中引用组件的方式尽可能的一致。然而,混用文件命名方式有的时候会导致大小写不敏感的文件系统的问题。</p> <p><strong>Vuejs</strong> 官方文档中,对于文件命名也有相应的 <a href="https://cn.vuejs.org/v2/style-guide/#%E5%8D%95%E6%96%87%E4%BB%B6%E7%BB%84%E4%BB%B6%E6%96%87%E4%BB%B6%E7%9A%84%E5%A4%A7%E5%B0%8F%E5%86%99-%E5%BC%BA%E7%83%88%E6%8E%A8%E8%8D%90" target="_blank" rel="noopener noreferrer">指导规范<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <p>文件命名示例</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>
components
  └─grid
    ├─grid<span class="token punctuation">.</span>sass
    ├─headRow<span class="token punctuation">.</span>vue
    ├─bodyrow<span class="token punctuation">.</span>vue
    ├─grid<span class="token punctuation">.</span>vue
    └─index<span class="token punctuation">.</span>js


components
  └─grid
    ├─grid<span class="token punctuation">.</span>sass
    ├─HeadRow<span class="token punctuation">.</span>vue
    ├─BodyRow<span class="token punctuation">.</span>vue
    ├─Grid<span class="token punctuation">.</span>vue
    └─index<span class="token punctuation">.</span>js
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><h2 id="预处理样式"><a href="#预处理样式" aria-hidden="true" class="header-anchor">#</a> 预处理样式</h2> <p>对于 CSS 样式预处理方案,比较流行的有 <code>SASS/SCSS</code><code>LESS</code><code>Stylus</code>,大体上的使用方式类似,区别在于功能的多少与扩展的能力。</p> <p>综合各方面考虑,开发规范如下(微信小程序不在讨论范围)</p> <ul><li>前端项目统一使用 <code>SASS/SCSS</code> 开发样式预处理内容</li> <li><code>web-open-platform</code> 项目使用 <code>Stylus</code></li></ul> <h3 id="样式抽象"><a href="#样式抽象" aria-hidden="true" class="header-anchor">#</a> 样式抽象</h3> <p>一个工程通常会有大量的页面、组件和插件,功能虽不同,但风格必须统一。对于主题风格部分的内容,必须提取到专用样式文件中进行维护。类似的功能或结构的样式内容在多处独立维护,这是冗余和低效的,多人协同开发时须杜绝该现象发生,在进行样式定义之前应互相询问是否存在重复定义的情况。</p> <p><strong>BTW</strong><br>
CSS 样式预处理,只使用最基本的结构嵌套功能是不够的,了解和使用高级特性才是提高效率和效果的最佳实践</p></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">

      <a href="/team/frontend/" class="prev router-link-active">前端 Frontend</a></span> <span class="next"><a href="/team/frontend/plugins.html">功能插件</a>

    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.0904f644.js" defer></script><script src="/assets/js/2.427d44e8.js" defer></script><script src="/assets/js/19.6c3f7bfe.js" defer></script>
  </body>
</html>