# Front-end development documentation ### Technical selection ``` Vue mvvm framework Es6 ECMAScript 6.0 Ans-ui Analysys-ui D3 Visual Library Chart Library Jsplumb connection plugin library Lodash high performance JavaScript utility library ``` ### Development environment - #### Node installation Node package download (note version 8.9.4) `https://nodejs.org/download/release/v8.9.4/` - #### Front-end project construction Use the command line mode `cd` enter the `dolphinscheduler-ui` project directory and execute `npm install` to pull the project dependency package. > If `npm install` is very slow > You can enter the Taobao image command line to enter `npm install -g cnpm --registry=https://registry.npm.taobao.org` > Run `cnpm install` - Create a new `.env` file or the interface that interacts with the backend Create a new` .env` file in the `dolphinscheduler-ui `directory, add the ip address and port of the backend service to the file, and use it to interact with the backend. The contents of the` .env` file are as follows: ``` # Proxy interface address (modified by yourself) API_BASE = http://192.168.xx.xx:12345 # If you need to access the project with ip, you can remove the "#" (example) #DEV_HOST = 192.168.xx.xx ``` > ##### ! ! ! Special attention here. If the project reports a "node-sass error" error while pulling the dependency package, execute the following command again after execution. ``` npm install node-sass --unsafe-perm //单独安装node-sass依赖 ``` - #### Development environment operation - `npm start` project development environment (after startup address http://localhost:8888/#/) #### Front-end project release - `npm run build` project packaging (after packaging, the root directory will create a folder called dist for publishing Nginx online) Run the `npm run build` command to generate a package file (dist) package Copy it to the corresponding directory of the server (front-end service static page storage directory) Visit address` http://localhost:8888/#/` #### Start with node and daemon under Linux Install pm2 `npm install -g pm2` Execute `pm2 start npm -- run dev` to start the project in the project `dolphinscheduler-ui `root directory #### command - Start `pm2 start npm -- run dev` - Stop `pm2 stop npm` - delete `pm2 delete npm` - Status `pm2 list` ``` [root@localhost dolphinscheduler-ui]# pm2 start npm -- run dev [PM2] Applying action restartProcessId on app [npm](ids: 0) [PM2] [npm](0) ✓ [PM2] Process successfully started ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬─────┬──────────┬──────┬──────────┐ │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │ ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼─────┼──────────┼──────┼──────────┤ │ npm │ 0 │ N/A │ fork │ 6168 │ online │ 31 │ 0s │ 0% │ 5.6 MB │ root │ disabled │ └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴─────┴──────────┴──────┴──────────┘ Use `pm2 show ` to get more details about an app ``` ### Project directory structure `build` some webpack configurations for packaging and development environment projects `node_modules` development environment node dependency package `src` project required documents `src => combo` project third-party resource localization `npm run combo` specific view `build/combo.js` `src => font` Font icon library can be added by visiting https://www.iconfont.cn Note: The font library uses its own secondary development to reintroduce its own library `src/sass/common/_font.scss` `src => images` public image storage `src => js` js/vue `src => lib` internal components of the company (company component library can be deleted after open source) `src => sass` sass file One page corresponds to a sass file `src => view` page file One page corresponds to an html file ``` > Projects are developed using vue single page application (SPA) - All page entry files are in the `src/js/conf/${ corresponding page filename => home} index.js` entry file - The corresponding sass file is in `src/sass/conf/${corresponding page filename => home}/index.scss` - The corresponding html file is in `src/view/${corresponding page filename => home}/index.html` ``` Public module and utill `src/js/module` `components` => internal project common components `download` => download component `echarts` => chart component `filter` => filter and vue pipeline `i18n` => internationalization `io` => io request encapsulation based on axios `mixin` => vue mixin public part for disabled operation `permissions` => permission operation `util` => tool ### System function module Home => `http://localhost:8888/#/home` Project Management => `http://localhost:8888/#/projects/list` ``` | Project Home | Workflow - Workflow definition - Workflow instance - Task instance ``` Resource Management => `http://localhost:8888/#/resource/file` ``` | File Management | udf Management - Resource Management - Function management ``` Data Source Management => `http://localhost:8888/#/datasource/list` Security Center => `http://localhost:8888/#/security/tenant` ``` | Tenant Management | User Management | Alarm Group Management - master - worker ``` User Center => `http://localhost:8888/#/user/account` ## Routing and state management The project `src/js/conf/home` is divided into `pages` => route to page directory ``` The page file corresponding to the routing address ``` `router` => route management ``` vue router, the entry file index.js in each page will be registered. Specific operations: https://router.vuejs.org/zh/ ``` `store` => status management ``` The page corresponding to each route has a state management file divided into: actions => mapActions => Details:https://vuex.vuejs.org/zh/guide/actions.html getters => mapGetters => Details:https://vuex.vuejs.org/zh/guide/getters.html index => entrance mutations => mapMutations => Details:https://vuex.vuejs.org/zh/guide/mutations.html state => mapState => Details:https://vuex.vuejs.org/zh/guide/state.html Specific action:https://vuex.vuejs.org/zh/ ``` ## specification ## Vue specification ##### 1.Component name The component is named multiple words and is connected with a wire (-) to avoid conflicts with HTML tags and a clearer structure. ``` // positive example export default { name: 'page-article-item' } ``` ##### 2.Component files The internal common component of the `src/js/module/components` project writes the folder name with the same name as the file name. The subcomponents and util tools that are split inside the common component are placed in the internal `_source` folder of the component. ``` └── components ├── header ├── header.vue └── _source └── nav.vue └── util.js ├── conditions ├── conditions.vue └── _source └── search.vue └── util.js ``` ##### 3.Prop When you define Prop, you should always name it in camel format (camelCase) and use the connection line (-) when assigning values to the parent component.This follows the characteristics of each language, because it is case-insensitive in HTML tags, and the use of links is more friendly; in JavaScript, the more natural is the hump name. ``` // Vue props: { articleStatus: Boolean } // HTML ``` The definition of Prop should specify its type, defaults, and validation as much as possible. Example: ``` props: { attrM: Number, attrA: { type: String, required: true }, attrZ: { type: Object, // The default value of the array/object should be returned by a factory function default: function () { return { msg: 'achieve you and me' } } }, attrE: { type: String, validator: function (v) { return !(['success', 'fail'].indexOf(v) === -1) } } } ``` ##### 4.v-for When performing v-for traversal, you should always bring a key value to make rendering more efficient when updating the DOM. ``` ``` v-for should be avoided on the same element as v-if (`for example:
  • `) because v-for has a higher priority than v-if. To avoid invalid calculations and rendering, you should try to use v-if Put it on top of the container's parent element. ``` ``` ##### 5.v-if / v-else-if / v-else If the elements in the same set of v-if logic control are logically identical, Vue reuses the same part for more efficient element switching, `such as: value`. In order to avoid the unreasonable effect of multiplexing, you should add key to the same element for identification. ```
    {{ mazeyData }}
    no data
    ``` ##### 6.Instruction abbreviation In order to unify the specification, the instruction abbreviation is always used. Using `v-bind`, `v-on` is not bad. Here is only a unified specification. ``` ``` ##### 7.Top-level element order of single file components Styles are packaged in a file, all the styles defined in a single vue file, the same name in other files will also take effect. All will have a top class name before creating a component. Note: The sass plugin has been added to the project, and the sas syntax can be written directly in a single vue file. For uniformity and ease of reading, they should be placed in the order of `