word.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <!-- 播放文字 -->
  2. <template>
  3. <view id="word">
  4. <view class="title-p">广播内容</view>
  5. <textarea placeholder="请输入广播内容" v-model="text"></textarea>
  6. <view class="radio-box">
  7. <view class="radio-title">播报方式</view>
  8. <radio-group @change="radioChange" class="radio-max-button">
  9. <label class="radio-button" v-for="(item, index) in items" :key="item.value">
  10. <radio :value="item.value" color="#007AFF" :checked="index === current" />{{item.name}}
  11. </label>
  12. </radio-group>
  13. </view>
  14. <view class="button-view" @click="voiceButton">确定</view>
  15. </view>
  16. </template>
  17. <script>
  18. import { voice } from '@/api/apiDemo/index.js'
  19. export default {
  20. data() {
  21. return {
  22. itemData:{},
  23. text:"",
  24. type:"",
  25. items:[
  26. {
  27. name:"文字",
  28. value:"1"
  29. },
  30. {
  31. name:"音频",
  32. value:"2"
  33. },
  34. ]
  35. }
  36. },
  37. onLoad(option) {
  38. this.itemData = JSON.parse(decodeURIComponent(option.item));
  39. },
  40. methods: {
  41. radioChange(e){
  42. this.type = e.detail.value;
  43. },
  44. voiceButton(){
  45. let self = this;
  46. if(!this.text){
  47. uni.showToast({
  48. title: '请输入广播内容',
  49. icon:"none",
  50. mask:true,
  51. duration: 2000
  52. });
  53. return
  54. }
  55. if(!this.type){
  56. uni.showToast({
  57. title: '请选择播报方式',
  58. icon:"none",
  59. mask:true,
  60. duration: 2000
  61. });
  62. return
  63. }
  64. uni.showModal({
  65. // title: '确认要退出吗?',
  66. content: '确认播放吗?',
  67. cancelColor:"#999",
  68. confirmColor:"#0183FA",
  69. success: function (res) {
  70. if (res.confirm) {
  71. self.voice();
  72. } else if (res.cancel) {
  73. }
  74. }
  75. });
  76. },
  77. //播放
  78. async voice(){
  79. let obj = {
  80. txt:this.text,
  81. type:this.type
  82. };
  83. const {data} = await voice(this.itemData.id,obj);
  84. if(data.code == 200){
  85. uni.showToast({
  86. title: '播放成功',
  87. icon:"none",
  88. mask:true,
  89. duration: 2000
  90. });
  91. setTimeout(function(){
  92. uni.navigateBack();
  93. },2000);
  94. }
  95. },
  96. }
  97. }
  98. </script>
  99. <style lang="stylus" scoped>
  100. #word{
  101. height:100%;
  102. background #fff
  103. overflow hidden
  104. .title-p{
  105. font-size:28rpx;
  106. margin:20rpx 0 20rpx 20rpx;
  107. line-height:60rpx;
  108. }
  109. textarea{
  110. width:670rpx;
  111. height:200rpx;
  112. margin:20rpx 20rpx 0;
  113. font-size:26rpx;
  114. border: 1rpx solid #E0E0E0;
  115. border-radius:10rpx;
  116. padding:20rpx;
  117. }
  118. .radio-box{
  119. font-size:26rpx;
  120. .radio-title{
  121. font-size:28rpx;
  122. margin:20rpx 0 20rpx 20rpx;
  123. line-height:60rpx;
  124. }
  125. .radio-max-button{
  126. display flex
  127. margin:0 100rpx;
  128. .radio-button{
  129. flex:1;
  130. margin-left:75rpx;
  131. font-size:26rpx;
  132. }
  133. }
  134. }
  135. .button-view{
  136. width: 600rpx;
  137. height: 80rpx;
  138. background: #0183FA;
  139. border-radius: 20rpx;
  140. font-size:30rpx;
  141. line-height:80rpx;
  142. text-align center;
  143. color: #fff;
  144. margin:90rpx auto;
  145. }
  146. }
  147. </style>