demo.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. const initTranslate = () => 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. initTranslate();
  62. return { translate };
  63. }
  64. });
  65. </script>
  66. <style lang="scss" scoped>
  67. .demo{
  68. }
  69. </style>
  70. `,
  71. taroDemo: `<template>
  72. <div class="demo">
  73. <h2>基础用法</h2>
  74. <nut-cell>
  75. <nut-${nameLc}></nut-${nameLc}>
  76. </nut-cell>
  77. </div>
  78. </template>
  79. <script lang="ts">
  80. import { defineComponent } from 'vue';
  81. export default defineComponent({
  82. props: {},
  83. setup() {
  84. return {};
  85. }
  86. });
  87. </script>
  88. `,
  89. doc: `# ${nameLc}
  90. ### 介绍
  91. 基于 xxxxxxx
  92. ### 安装
  93. \`\`\`javascript
  94. import { createApp } from 'vue';
  95. // vue
  96. import { } from '@nutui/nutui';
  97. // taro
  98. import { } from '@nutui/nutui-taro';
  99. const app = createApp();
  100. app.use();
  101. \`\`\`
  102. ### 基础用法
  103. :::demo
  104. \`\`\`html
  105. <template>
  106. </template>
  107. <script lang="ts">
  108. export default {
  109. setup() {
  110. return { };
  111. }
  112. };
  113. </script>
  114. \`\`\`
  115. :::
  116. ## API
  117. ### Props
  118. | 参数 | 说明 | 类型 | 默认值 |
  119. |--------------|----------------------------------|--------|------------------|
  120. | name | 图标名称或图片链接 | String | - |
  121. ### Events
  122. | 事件名 | 说明 | 回调参数 |
  123. |--------|----------------|--------------|
  124. | click | 点击图标时触发 | event: Event |
  125. `,
  126. docEN: `# ${nameLc}
  127. ### Intro
  128. ### Install
  129. \`\`\`javascript
  130. import { createApp } from 'vue';
  131. // vue
  132. import { } from '@nutui/nutui';
  133. // taro
  134. import { } from '@nutui/nutui-taro';
  135. const app = createApp();
  136. app.use();
  137. \`\`\`
  138. ### Basic Usage
  139. :::demo
  140. \`\`\`html
  141. <template>
  142. </template>
  143. <script lang="ts">
  144. export default {
  145. setup() {
  146. return { };
  147. }
  148. };
  149. </script>
  150. \`\`\`
  151. :::
  152. ## API
  153. ### Props
  154. | Attribute | Description | Type | Default |
  155. |--------------|----------------------------------|--------|------------------|
  156. | name | description | String | - |
  157. ### Events
  158. | Event | Description | Arguments |
  159. |--------|----------------|--------------|
  160. | click | description | event: Event |
  161. `
  162. };
  163. return teml;
  164. };
  165. module.exports = demoModel;