demo.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. var demoModel = function (nameLc) {
  2. var teml = {
  3. source: `<template>
  4. <view :class="classes" @click="handleClick">
  5. <view>{{ data }}</view>
  6. </view>
  7. </template>
  8. <script lang="ts">
  9. import { reactive, toRefs, computed } from 'vue';
  10. import { createComponent } from '@/packages/utils/create';
  11. const { componentName, create } = createComponent('${nameLc}');
  12. export default create({
  13. props: {
  14. name: {
  15. type: String,
  16. default: ''
  17. }
  18. },
  19. emits: ['click'],
  20. setup(props, { emit }) {
  21. const state = reactive({
  22. data: 'Welcome to developing components'
  23. });
  24. const classes = computed(() => {
  25. const prefixCls = componentName;
  26. return {
  27. [prefixCls]: true
  28. };
  29. });
  30. const handleClick = (event: Event) => {
  31. emit('click', event);
  32. };
  33. return { ...toRefs(state), classes, handleClick };
  34. }
  35. });
  36. </script>
  37. `,
  38. demo: `<template>
  39. <div class="demo">
  40. <h2>{{ translate('basic') }}</h2>
  41. <nut-cell>
  42. <nut-${nameLc}></nut-${nameLc}>
  43. </nut-cell>
  44. </div>
  45. </template>
  46. <script lang="ts">
  47. import { createComponent } from '@/packages/utils/create';
  48. const { createDemo, translate } = createComponent('${nameLc}');
  49. import { useTranslate } from '@/sites/assets/util/useTranslate';
  50. useTranslate({
  51. 'zh-CN': {
  52. basic: '基本用法'
  53. },
  54. 'en-US': {
  55. basic: 'Basic Usage'
  56. }
  57. })
  58. export default createDemo({
  59. props: {},
  60. setup() {
  61. return { translate };
  62. }
  63. });
  64. </script>
  65. <style lang="scss" scoped>
  66. .demo{
  67. }
  68. </style>
  69. `,
  70. taroDemo: `<template>
  71. <div class="demo">
  72. <h2>基础用法</h2>
  73. <nut-cell>
  74. <nut-${nameLc}></nut-${nameLc}>
  75. </nut-cell>
  76. </div>
  77. </template>
  78. <script lang="ts">
  79. import { defineComponent } from 'vue';
  80. export default defineComponent({
  81. props: {},
  82. setup() {
  83. return {};
  84. }
  85. });
  86. </script>
  87. `,
  88. doc: `# ${nameLc}
  89. ### 介绍
  90. 基于 xxxxxxx
  91. ### 安装
  92. \`\`\`javascript
  93. import { createApp } from 'vue';
  94. // vue
  95. import { } from '@nutui/nutui';
  96. // taro
  97. import { } from '@nutui/nutui-taro';
  98. const app = createApp();
  99. app.use();
  100. \`\`\`
  101. ### 基础用法
  102. :::demo
  103. \`\`\`html
  104. <template>
  105. </template>
  106. <script lang="ts">
  107. export default {
  108. setup() {
  109. return { };
  110. }
  111. };
  112. </script>
  113. \`\`\`
  114. :::
  115. ## API
  116. ### Props
  117. | 参数 | 说明 | 类型 | 默认值 |
  118. |--------------|----------------------------------|--------|------------------|
  119. | name | 图标名称或图片链接 | String | - |
  120. ### Events
  121. | 事件名 | 说明 | 回调参数 |
  122. |--------|----------------|--------------|
  123. | click | 点击图标时触发 | event: Event |
  124. `,
  125. docEN: `# ${nameLc}
  126. ### Intro
  127. ### Install
  128. \`\`\`javascript
  129. import { createApp } from 'vue';
  130. // vue
  131. import { } from '@nutui/nutui';
  132. // taro
  133. import { } from '@nutui/nutui-taro';
  134. const app = createApp();
  135. app.use();
  136. \`\`\`
  137. ### Basic Usage
  138. :::demo
  139. \`\`\`html
  140. <template>
  141. </template>
  142. <script lang="ts">
  143. export default {
  144. setup() {
  145. return { };
  146. }
  147. };
  148. </script>
  149. \`\`\`
  150. :::
  151. ## API
  152. ### Props
  153. | Attribute | Description | Type | Default |
  154. |--------------|----------------------------------|--------|------------------|
  155. | name | description | String | - |
  156. ### Events
  157. | Event | Description | Arguments |
  158. |--------|----------------|--------------|
  159. | click | description | event: Event |
  160. `
  161. };
  162. return teml;
  163. };
  164. module.exports = demoModel;