Front-end development documentation

Technical selection

  1. Vue mvvm framework
  2. Es6 ECMAScript 6.0
  3. Ans-ui Analysys-ui
  4. D3 Visual Library Chart Library
  5. Jsplumb connection plugin library
  6. Lodash high performance JavaScript utility library

Development environment

  • Node installation

Node package download (note version v12.20.2) https://nodejs.org/download/release/v12.20.2/

  • 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 set the taobao mirror

  1. npm config set registry http://registry.npm.taobao.org/
  • Modify API_BASE in the file dolphinscheduler-ui/.env to interact with the backend:
  1. # back end interface address
  2. API_BASE = http://127.0.0.1:12345
! ! ! Special attention here. If the project reports a “node-sass error” error while pulling the dependency package, execute the following command again after execution.
  1. npm install node-sass --unsafe-perm #Install node-sass dependency separately
  • 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 addresshttp://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-uiroot directory

command

  • Start pm2 start npm -- run dev

  • Stop pm2 stop npm

  • delete pm2 delete npm

  • Status pm2 list

  1. [root@localhost dolphinscheduler-ui]# pm2 start npm -- run dev
  2. [PM2] Applying action restartProcessId on app [npm](ids: 0)
  3. [PM2] [npm](0)
  4. [PM2] Process successfully started
  5. ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬─────┬──────────┬──────┬──────────┐
  6. App name id version mode pid status restart uptime cpu mem user watching
  7. ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼─────┼──────────┼──────┼──────────┤
  8. npm 0 N/A fork 6168 online 31 0s 0% 5.6 MB root disabled
  9. └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴─────┴──────────┴──────┴──────────┘
  10. Use `pm2 show <id|name>` 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

  1. > Projects are developed using vue single page application (SPA)
  2. - All page entry files are in the `src/js/conf/${ corresponding page filename => home} index.js` entry file
  3. - The corresponding sass file is in `src/sass/conf/${corresponding page filename => home}/index.scss`
  4. - 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

  1. | Project Home
  2. | Workflow
  3. - Workflow definition
  4. - Workflow instance
  5. - Task instance

Resource Management => http://localhost:8888/#/resource/file

  1. | File Management
  2. | udf Management
  3. - Resource Management
  4. - Function management

Data Source Management => http://localhost:8888/#/datasource/list

Security Center => http://localhost:8888/#/security/tenant

  1. | Tenant Management
  2. | User Management
  3. | Alarm Group Management
  4. - master
  5. - 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

  1. The page file corresponding to the routing address

router => route management

  1. vue router, the entry file index.js in each page will be registered. Specific operations: https://router.vuejs.org/zh/

store => status management

  1. The page corresponding to each route has a state management file divided into:
  2. actions => mapActions => Detailshttps://vuex.vuejs.org/zh/guide/actions.html
  3. getters => mapGetters => Detailshttps://vuex.vuejs.org/zh/guide/getters.html
  4. index => entrance
  5. mutations => mapMutations => Detailshttps://vuex.vuejs.org/zh/guide/mutations.html
  6. state => mapState => Detailshttps://vuex.vuejs.org/zh/guide/state.html
  7. Specific actionhttps://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.

  1. // positive example
  2. export default {
  3. name: 'page-article-item'
  4. }
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.

  1. └── components
  2. ├── header
  3. ├── header.vue
  4. └── _source
  5. └── nav.vue
  6. └── util.js
  7. ├── conditions
  8. ├── conditions.vue
  9. └── _source
  10. └── search.vue
  11. └── 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.

  1. // Vue
  2. props: {
  3. articleStatus: Boolean
  4. }
  5. // HTML
  6. <article-item :article-status="true"></article-item>

The definition of Prop should specify its type, defaults, and validation as much as possible.

Example:

  1. props: {
  2. attrM: Number,
  3. attrA: {
  4. type: String,
  5. required: true
  6. },
  7. attrZ: {
  8. type: Object,
  9. // The default value of the array/object should be returned by a factory function
  10. default: function () {
  11. return {
  12. msg: 'achieve you and me'
  13. }
  14. }
  15. },
  16. attrE: {
  17. type: String,
  18. validator: function (v) {
  19. return !(['success', 'fail'].indexOf(v) === -1)
  20. }
  21. }
  22. }
4.v-for

When performing v-for traversal, you should always bring a key value to make rendering more efficient when updating the DOM.

  1. <ul>
  2. <li v-for="item in list" :key="item.id">
  3. {{ item.title }}
  4. </li>
  5. </ul>

v-for should be avoided on the same element as v-if (for example: <li>) 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.

  1. <ul v-if="showList">
  2. <li v-for="item in list" :key="item.id">
  3. {{ item.title }}
  4. </li>
  5. </ul>
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.

  1. <div v-if="hasData" key="mazey-data">
  2. <span>{{ mazeyData }}</span>
  3. </div>
  4. <div v-else key="mazey-none">
  5. <span>no data</span>
  6. </div>
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.

  1. <input :value="mazeyUser" @click="verifyUser">
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 <template><script><style>.

  1. <template>
  2. <div class="test-model">
  3. test
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: "test",
  9. data() {
  10. return {}
  11. },
  12. props: {},
  13. methods: {},
  14. watch: {},
  15. beforeCreate() {
  16. },
  17. created() {
  18. },
  19. beforeMount() {
  20. },
  21. mounted() {
  22. },
  23. beforeUpdate() {
  24. },
  25. updated() {
  26. },
  27. beforeDestroy() {
  28. },
  29. destroyed() {
  30. },
  31. computed: {},
  32. components: {},
  33. }
  34. </script>
  35. <style lang="scss" rel="stylesheet/scss">
  36. .test-model {
  37. }
  38. </style>

JavaScript specification

1.var / let / const

It is recommended to no longer use var, but use let / const, prefer const. The use of any variable must be declared in advance, except that the function defined by function can be placed anywhere.

2.quotes
  1. const foo = 'after division'
  2. const bar = `${foo},ront-end engineer`
3.function

Anonymous functions use the arrow function uniformly. When multiple parameters/return values are used, the object’s structure assignment is used first.

  1. function getPersonInfo ({name, sex}) {
  2. // ...
  3. return {name, gender}
  4. }

The function name is uniformly named with a camel name. The beginning of the capital letter is a constructor. The lowercase letters start with ordinary functions, and the new operator should not be used to operate ordinary functions.

4.object
  1. const foo = {a: 0, b: 1}
  2. const bar = JSON.parse(JSON.stringify(foo))
  3. const foo = {a: 0, b: 1}
  4. const bar = {...foo, c: 2}
  5. const foo = {a: 3}
  6. Object.assign(foo, {b: 4})
  7. const myMap = new Map([])
  8. for (let [key, value] of myMap.entries()) {
  9. // ...
  10. }
5.module

Unified management of project modules using import / export.

  1. // lib.js
  2. export default {}
  3. // app.js
  4. import app from './lib'

Import is placed at the top of the file.

If the module has only one output value, use export default,otherwise no.

HTML / CSS

1.Label

Do not write the type attribute when referencing external CSS or JavaScript. The HTML5 default type is the text/css and text/javascript properties, so there is no need to specify them.

  1. <link rel="stylesheet" href="//www.test.com/css/test.css">
  2. <script src="//www.test.com/js/test.js"></script>
2.Naming

The naming of Class and ID should be semantic, and you can see what you are doing by looking at the name; multiple words are connected by a link.

  1. // positive example
  2. .test-header{
  3. font-size: 20px;
  4. }
3.Attribute abbreviation

CSS attributes use abbreviations as much as possible to improve the efficiency and ease of understanding of the code.

  1. // counter example
  2. border-width: 1px;
  3. border-style: solid;
  4. border-color: #ccc;
  5. // positive example
  6. border: 1px solid #ccc;
4.Document type

The HTML5 standard should always be used.

  1. <!DOCTYPE html>
5.Notes

A block comment should be written to a module file.

  1. /**
  2. * @module mazey/api
  3. * @author Mazey <mazey@mazey.net>
  4. * @description test.
  5. * */

interface

All interfaces are returned as Promise

Note that non-zero is wrong for catching catch

  1. const test = () => {
  2. return new Promise((resolve, reject) => {
  3. resolve({
  4. a:1
  5. })
  6. })
  7. }
  8. // transfer
  9. test.then(res => {
  10. console.log(res)
  11. // {a:1}
  12. })

Normal return

  1. {
  2. code:0,
  3. data:{}
  4. msg:'success'
  5. }

Error return

  1. {
  2. code:10000,
  3. data:{}
  4. msg:'failed'
  5. }

If the interface is a post request, the Content-Type defaults to application/x-www-form-urlencoded; if the Content-Type is changed to application/json, Interface parameter transfer needs to be changed to the following way

  1. io.post('url', payload, null, null, { emulateJSON: false } res => {
  2. resolve(res)
  3. }).catch(e => {
  4. reject(e)
  5. })

dag related interface src/js/conf/home/store/dag/actions.js

Data Source Center Related Interfaces src/js/conf/home/store/datasource/actions.js

Project Management Related Interfaces src/js/conf/home/store/projects/actions.js

Resource Center Related Interfaces src/js/conf/home/store/resource/actions.js

Security Center Related Interfaces src/js/conf/home/store/security/actions.js

User Center Related Interfaces src/js/conf/home/store/user/actions.js

Extended development

1.Add node

(1) First place the icon icon of the node in the src/js/conf/home/pages/dag/imgfolder, and note the English name of the node defined by the toolbar_${in the background. For example: SHELL}.png

(2) Find the tasksType object in src/js/conf/home/pages/dag/_source/config.js and add it to it.

  1. 'DEPENDENT': { // The background definition node type English name is used as the key value
  2. desc: 'DEPENDENT', // tooltip desc
  3. color: '#2FBFD8' // The color represented is mainly used for tree and gantt
  4. }

(3) Add a ${node type (lowercase)}.vue file in src/js/conf/home/pages/dag/_source/formModel/tasks. The contents of the components related to the current node are written here. Must belong to a node component must have a function _verification () After the verification is successful, the relevant data of the current component is thrown to the parent component.

  1. /**
  2. * Verification
  3. */
  4. _verification () {
  5. // datasource subcomponent verification
  6. if (!this.$refs.refDs._verifDatasource()) {
  7. return false
  8. }
  9. // verification function
  10. if (!this.method) {
  11. this.$message.warning(`${i18n.$t('Please enter method')}`)
  12. return false
  13. }
  14. // localParams subcomponent validation
  15. if (!this.$refs.refLocalParams._verifProp()) {
  16. return false
  17. }
  18. // store
  19. this.$emit('on-params', {
  20. type: this.type,
  21. datasource: this.datasource,
  22. method: this.method,
  23. localParams: this.localParams
  24. })
  25. return true
  26. }

(4) Common components used inside the node component are under_source, and commcon.js is used to configure public data.

2.Increase the status type

(1) Find the tasksState object in src/js/conf/home/pages/dag/_source/config.js and add it to it.

  1. 'WAITTING_DEPEND': { // 'WAITTING_DEPEND': { //Backend defines state type, frontend is used as key value
  2. id: 11, // front-end definition id is used as a sort
  3. desc: `${i18n.$t('waiting for dependency')}`, // tooltip desc
  4. color: '#5101be', // The color represented is mainly used for tree and gantt
  5. icoUnicode: '&#xe68c;', // font icon
  6. isSpin: false // whether to rotate (requires code judgment)
  7. }
3.Add the action bar tool

(1) Find the toolOper object in src/js/conf/home/pages/dag/_source/config.js and add it to it.

  1. {
  2. code: 'pointer', // tool identifier
  3. icon: '&#xe781;', // tool icon
  4. disable: disable, // disable
  5. desc: `${i18n.$t('Drag node and selected item')}` // tooltip desc
  6. }

(2) Tool classes are returned as a constructor src/js/conf/home/pages/dag/_source/plugIn

downChart.js => dag image download processing

dragZoom.js => mouse zoom effect processing

jsPlumbHandle.js => drag and drop line processing

util.js => belongs to the plugIn tool class

The operation is handled in the src/js/conf/home/pages/dag/_source/dag.js => toolbarEvent event.

3.Add a routing page

(1) First add a routing addresssrc/js/conf/home/router/index.js in route management

  1. routing address{
  2. path: '/test', // routing address
  3. name: 'test', // alias
  4. component: resolve => require(['../pages/test/index'], resolve), // route corresponding component entry file
  5. meta: {
  6. title: `${i18n.$t('test')} - EasyScheduler` // title display
  7. }
  8. },

(2)Create a test folder in src/js/conf/home/pages and create an index.vueentry file in the folder.

  1. This will give you direct access to`http://localhost:8888/#/test`
4.Increase the preset mailbox

Find the src/lib/localData/email.js startup and timed email address input to automatically pull down the match.

  1. export default ["test@analysys.com.cn","test1@analysys.com.cn","test3@analysys.com.cn"]
5.Authority management and disabled state processing

The permission gives the userType according to the backUser interface getUserInfo interface: "ADMIN_USER/GENERAL_USER"permission to control whether the page operation button is disabled.

specific operation:src/js/module/permissions/index.js

disabled processing:src/js/module/mixin/disabledState.js